github.com/crowdsecurity/crowdsec@v1.6.1/pkg/protobufs/plugin_interface.go (about) 1 package protobufs 2 3 import ( 4 "context" 5 6 plugin "github.com/hashicorp/go-plugin" 7 "google.golang.org/grpc" 8 ) 9 10 type Notifier interface { 11 Notify(ctx context.Context, notification *Notification) (*Empty, error) 12 Configure(ctx context.Context, config *Config) (*Empty, error) 13 } 14 15 // This is the implementation of plugin.NotifierPlugin so we can serve/consume this. 16 type NotifierPlugin struct { 17 // GRPCPlugin must still implement the Plugin interface 18 plugin.Plugin 19 // Concrete implementation, written in Go. This is only used for plugins 20 // that are written in Go. 21 Impl Notifier 22 } 23 24 type GRPCClient struct{ client NotifierClient } 25 26 func (m *GRPCClient) Notify(ctx context.Context, notification *Notification) (*Empty, error) { 27 _, err := m.client.Notify(context.Background(), notification) 28 return &Empty{}, err 29 } 30 31 func (m *GRPCClient) Configure(ctx context.Context, config *Config) (*Empty, error) { 32 _, err := m.client.Configure(context.Background(), config) 33 return &Empty{}, err 34 } 35 36 type GRPCServer struct { 37 Impl Notifier 38 } 39 40 func (p *NotifierPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error { 41 RegisterNotifierServer(s, p.Impl) 42 return nil 43 } 44 45 func (p *NotifierPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) { 46 return &GRPCClient{client: NewNotifierClient(c)}, nil 47 }