github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/pluginmanager_service/grpc/shared/interface.go (about)

     1  // Package shared contains shared data between the host and plugins.
     2  package shared
     3  
     4  import (
     5  	"context"
     6  	"github.com/turbot/steampipe/pkg/pluginmanager_service/grpc/proto"
     7  
     8  	"github.com/hashicorp/go-plugin"
     9  	"google.golang.org/grpc"
    10  )
    11  
    12  const PluginName = "steampipe_plugin_manager"
    13  
    14  // PluginMap is a ma of the plugins supported, _without the implementation_
    15  // this used to create a GRPC client
    16  var PluginMap = map[string]plugin.Plugin{
    17  	PluginName: &PluginManagerPlugin{},
    18  }
    19  
    20  // Handshake is a common handshake that is shared by plugin and host.
    21  var Handshake = plugin.HandshakeConfig{
    22  	MagicCookieKey:   "PLUGIN_MANAGER_MAGIC_COOKIE",
    23  	MagicCookieValue: "really-complex-permanent-string-value",
    24  }
    25  
    26  // PluginManager is the interface for the plugin manager service
    27  type PluginManager interface {
    28  	Get(req *proto.GetRequest) (*proto.GetResponse, error)
    29  	RefreshConnections(req *proto.RefreshConnectionsRequest) (*proto.RefreshConnectionsResponse, error)
    30  	Shutdown(req *proto.ShutdownRequest) (*proto.ShutdownResponse, error)
    31  }
    32  
    33  // PluginManagerPlugin is the implementation of plugin.GRPCServer so we can serve/consume this.
    34  type PluginManagerPlugin struct {
    35  	// GRPCPlugin must still implement the Stub interface
    36  	plugin.Plugin
    37  	// Concrete implementation
    38  	Impl PluginManager
    39  }
    40  
    41  func (p *PluginManagerPlugin) GRPCServer(_ *plugin.GRPCBroker, s *grpc.Server) error {
    42  	//fmt.Println("GRPCServer")
    43  	proto.RegisterPluginManagerServer(s, &GRPCServer{Impl: p.Impl})
    44  	return nil
    45  }
    46  
    47  // GRPCClient returns a GRPCClient, called by Dispense
    48  func (p *PluginManagerPlugin) GRPCClient(ctx context.Context, _ *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
    49  	return &GRPCClient{client: proto.NewPluginManagerClient(c), ctx: ctx}, nil
    50  }