github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/cloudplugin/cloudplugin1/grpc_plugin.go (about) 1 package cloudplugin1 2 3 import ( 4 "context" 5 "errors" 6 "net/rpc" 7 8 "github.com/hashicorp/go-plugin" 9 "github.com/terramate-io/tf/cloudplugin" 10 "github.com/terramate-io/tf/cloudplugin/cloudproto1" 11 "google.golang.org/grpc" 12 ) 13 14 // GRPCCloudPlugin is the go-plugin implementation, but only the client 15 // implementation exists in this package. 16 type GRPCCloudPlugin struct { 17 plugin.GRPCPlugin 18 Impl cloudplugin.Cloud1 19 } 20 21 // Server always returns an error; we're only implementing the GRPCPlugin 22 // interface, not the Plugin interface. 23 func (p *GRPCCloudPlugin) Server(*plugin.MuxBroker) (interface{}, error) { 24 return nil, errors.New("cloudplugin only implements gRPC clients") 25 } 26 27 // Client always returns an error; we're only implementing the GRPCPlugin 28 // interface, not the Plugin interface. 29 func (p *GRPCCloudPlugin) Client(*plugin.MuxBroker, *rpc.Client) (interface{}, error) { 30 return nil, errors.New("cloudplugin only implements gRPC clients") 31 } 32 33 // GRPCServer always returns an error; we're only implementing the client 34 // interface, not the server. 35 func (p *GRPCCloudPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error { 36 return errors.New("cloudplugin only implements gRPC clients") 37 } 38 39 // GRPCClient returns a new GRPC client for interacting with the cloud plugin server. 40 func (p *GRPCCloudPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) { 41 return &GRPCCloudClient{ 42 client: cloudproto1.NewCommandServiceClient(c), 43 context: ctx, 44 }, nil 45 }