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