get.porter.sh/porter@v1.3.0/pkg/storage/pluginstore/plugin.go (about)

     1  package pluginstore
     2  
     3  import (
     4  	"context"
     5  
     6  	"get.porter.sh/porter/pkg/portercontext"
     7  	"get.porter.sh/porter/pkg/storage/plugins"
     8  	"get.porter.sh/porter/pkg/storage/plugins/proto"
     9  	"github.com/hashicorp/go-plugin"
    10  	"google.golang.org/grpc"
    11  )
    12  
    13  var _ plugin.GRPCPlugin = Plugin{}
    14  
    15  // Plugin is the shared implementation of a storage plugin wrapper.
    16  type Plugin struct {
    17  	plugin.Plugin
    18  	impl    plugins.StorageProtocol
    19  	context *portercontext.Context
    20  }
    21  
    22  // NewPlugin creates an instance of a storage plugin.
    23  func NewPlugin(c *portercontext.Context, impl plugins.StorageProtocol) Plugin {
    24  	return Plugin{
    25  		context: c,
    26  		impl:    impl,
    27  	}
    28  }
    29  
    30  func (p Plugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
    31  	impl := &GServer{c: p.context, impl: p.impl}
    32  	proto.RegisterStorageProtocolServer(s, impl)
    33  	return nil
    34  }
    35  
    36  func (p Plugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, conn *grpc.ClientConn) (interface{}, error) {
    37  	return &GClient{client: proto.NewStorageProtocolClient(conn)}, nil
    38  }