mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-10 00:27:02 +02:00
Biggest change: we rename `Send` to `SendEvent` in `logical.EventSender`.. Initially we picked `Send` to match the underlying go-eventlogger broker's `Send` method, and to avoid the stuttering of `events.SendEvent`. However, I think it is more useful for the `logical.EventSender` interface to use the method `SendEvent` so that, for example, `framework.Backend` can implement it. This is a relatively change now that should not affect anything except the KV plugin, which is being fixed in another PR. Another change: if the `secret_path` metadata is present, then the plugin-aware `EventBus` will prepend it with the plugin mount. This allows the `secret_path` to be the full path to any referenced secret. This change is also backwards compatible, since this field was not present in the KV plugin. (It did use the slightly different `path` field, which we can keep for now.)
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package plugin
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
|
"github.com/hashicorp/vault/sdk/plugin/pb"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
func newGRPCEventsClient(conn *grpc.ClientConn) *GRPCEventsClient {
|
|
return &GRPCEventsClient{
|
|
client: pb.NewEventsClient(conn),
|
|
}
|
|
}
|
|
|
|
type GRPCEventsClient struct {
|
|
client pb.EventsClient
|
|
}
|
|
|
|
var _ logical.EventSender = (*GRPCEventsClient)(nil)
|
|
|
|
func (s *GRPCEventsClient) SendEvent(ctx context.Context, eventType logical.EventType, event *logical.EventData) error {
|
|
_, err := s.client.SendEvent(ctx, &pb.SendEventRequest{
|
|
EventType: string(eventType),
|
|
Event: event,
|
|
})
|
|
return err
|
|
}
|
|
|
|
type GRPCEventsServer struct {
|
|
pb.UnimplementedEventsServer
|
|
impl logical.EventSender
|
|
}
|
|
|
|
func (s *GRPCEventsServer) SendEvent(ctx context.Context, req *pb.SendEventRequest) (*pb.Empty, error) {
|
|
if s.impl == nil {
|
|
return &pb.Empty{}, nil
|
|
}
|
|
|
|
err := s.impl.SendEvent(ctx, logical.EventType(req.EventType), req.Event)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &pb.Empty{}, nil
|
|
}
|