9
9
"net/rpc"
10
10
11
11
"github.com/hashicorp/go-plugin"
12
+ "github.com/hashicorp/terraform-svchost/disco"
12
13
"github.com/hashicorp/terraform/internal/stacksplugin"
13
14
"github.com/hashicorp/terraform/internal/stacksplugin/stacksproto1"
14
15
"google.golang.org/grpc"
@@ -21,6 +22,7 @@ type GRPCStacksPlugin struct {
21
22
plugin.GRPCPlugin
22
23
Metadata metadata.MD
23
24
Impl stacksplugin.Stacks1
25
+ Services * disco.Disco
24
26
}
25
27
26
28
type GRPCStacksServer struct {
@@ -46,9 +48,10 @@ func (p *GRPCStacksPlugin) Client(*plugin.MuxBroker, *rpc.Client) (interface{},
46
48
func (p * GRPCStacksPlugin ) GRPCClient (ctx context.Context , broker * plugin.GRPCBroker , c * grpc.ClientConn ) (interface {}, error ) {
47
49
ctx = metadata .NewOutgoingContext (ctx , p .Metadata )
48
50
return & GRPCStacksClient {
49
- client : stacksproto1 .NewCommandServiceClient (c ),
50
- broker : broker ,
51
- context : ctx ,
51
+ client : stacksproto1 .NewCommandServiceClient (c ),
52
+ broker : broker ,
53
+ services : p .Services ,
54
+ context : ctx ,
52
55
}, nil
53
56
}
54
57
@@ -62,99 +65,5 @@ func (p *GRPCStacksPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server)
62
65
})
63
66
return nil
64
67
*/
65
- return nil
66
- }
67
-
68
- /**
69
- func registerGRPCServices(s *grpc.Server) {
70
- // We initially only register the setup server, because the registration
71
- // of other services can vary depending on the capabilities negotiated
72
- // during handshake.
73
- server := newSetupServer(serverHandshake(s))
74
- setup.RegisterSetupServer(s, server)
75
- }
76
-
77
- func serverHandshake(s *grpc.Server) func(context.Context, *setup.Handshake_Request, *stopper) (*setup.ServerCapabilities, error) {
78
- dependenciesStub := dynrpcserver.NewDependenciesStub()
79
- dependencies.RegisterDependenciesServer(s, dependenciesStub)
80
- stacksStub := dynrpcserver.NewStacksStub()
81
- stacks.RegisterStacksServer(s, stacksStub)
82
- packagesStub := dynrpcserver.NewPackagesStub()
83
- packages.RegisterPackagesServer(s, packagesStub)
84
-
85
- return func(ctx context.Context, request *setup.Handshake_Request, stopper *stopper) (*setup.ServerCapabilities, error) {
86
- // All of our servers will share a common handles table so that objects
87
- // can be passed from one service to another.
88
- handles := newHandleTable()
89
-
90
- // NOTE: This is intentionally not the same disco that "package main"
91
- // instantiates for Terraform CLI, because the RPC API is
92
- // architecturally independent from CLI despite being launched through
93
- // it, and so it is not subject to any ambient CLI configuration files
94
- // that might be in scope. If we later discover requirements for
95
- // callers to customize the service discovery settings, consider
96
- // adding new fields to terraform1.ClientCapabilities (even though
97
- // this isn't strictly a "capability") so that the RPC caller has
98
- // full control without needing to also tinker with the current user's
99
- // CLI configuration.
100
- services, err := newServiceDisco(request.GetConfig())
101
- if err != nil {
102
- return &setup.ServerCapabilities{}, err
103
- }
104
-
105
- // If handshaking is successful (which it currently always is, because
106
- // we don't have any special capabilities to negotiate yet) then we
107
- // will initialize all of the other services so the client can begin
108
- // doing real work. In future the details of what we register here
109
- // might vary based on the negotiated capabilities.
110
- dependenciesStub.ActivateRPCServer(newDependenciesServer(handles, services))
111
- stacksStub.ActivateRPCServer(newStacksServer(stopper, handles))
112
- packagesStub.ActivateRPCServer(newPackagesServer(services))
113
-
114
- // If the client requested any extra capabililties that we're going
115
- // to honor then we should announce them in this result.
116
- return &setup.ServerCapabilities{}, nil
117
- }
118
- }
119
-
120
- // serviceOpts are options that could potentially apply to all of our
121
- // individual RPC services.
122
- //
123
- // This could potentially be embedded inside a service-specific options
124
- // structure, if needed.
125
- type serviceOpts struct {
126
- experimentsAllowed bool
127
- }
128
-
129
- func newServiceDisco(config *setup.Config) (*disco.Disco, error) {
130
- // First, we'll try and load any credentials that might have been available
131
- // to the UI. It's perfectly fine if there are none so any errors we find
132
- // are from malformed credentials rather than missing ones.
133
-
134
- file, diags := cliconfig.LoadConfig()
135
- if diags.HasErrors() {
136
- return nil, fmt.Errorf("problem loading CLI configuration: %w", diags.ErrWithWarnings())
137
- }
138
-
139
- helperPlugins := pluginDiscovery.FindPlugins("credentials", cliconfig.GlobalPluginDirs())
140
- src, err := file.CredentialsSource(helperPlugins)
141
- if err != nil {
142
- return nil, fmt.Errorf("problem creating credentials source: %w", err)
143
- }
144
- services := disco.NewWithCredentialsSource(src)
145
-
146
- // Second, we'll side-load any credentials that might have been passed in.
147
-
148
- credSrc := services.CredentialsSource()
149
- if config != nil {
150
- for host, cred := range config.GetCredentials() {
151
- if err := credSrc.StoreForHost(svchost.Hostname(host), auth.HostCredentialsToken(cred.Token)); err != nil {
152
- return nil, fmt.Errorf("problem storing credential for host %s with: %w", host, err)
153
- }
154
- }
155
- services.SetCredentialsSource(credSrc)
156
- }
157
-
158
- return services, nil
68
+ return errors .ErrUnsupported
159
69
}
160
- **/
0 commit comments