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