5864075c30
This isn't perfect for sure, but it's solidifying and becoming a useful base to work off. This routes events sent from auth and secrets plugins to the main `EventBus` in the Vault Core. Events sent from plugins are automatically tagged with the namespace and plugin information associated with them.
43 lines
975 B
Go
43 lines
975 B
Go
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) Send(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) {
|
|
err := s.impl.Send(ctx, logical.EventType(req.EventType), req.Event)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &pb.Empty{}, nil
|
|
}
|