-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmux_server_ValidateProviderConfig.go
More file actions
58 lines (46 loc) · 1.69 KB
/
mux_server_ValidateProviderConfig.go
File metadata and controls
58 lines (46 loc) · 1.69 KB
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
51
52
53
54
55
56
57
58
package tf6muxserver
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-mux/internal/logging"
)
// ValidateProviderConfig calls the ValidateProviderConfig method on each server
// in order, passing `req`. Only one may respond with a non-nil PreparedConfig
// or a non-empty Diagnostics.
func (s muxServer) ValidateProviderConfig(ctx context.Context, req *tfprotov6.ValidateProviderConfigRequest) (*tfprotov6.ValidateProviderConfigResponse, error) {
rpc := "ValidateProviderConfig"
ctx = logging.InitContext(ctx)
ctx = logging.RpcContext(ctx, rpc)
var resp *tfprotov6.ValidateProviderConfigResponse
for _, server := range s.servers {
ctx = logging.Tfprotov6ProviderServerContext(ctx, server)
logging.MuxTrace(ctx, "calling downstream server")
res, err := server.ValidateProviderConfig(ctx, req)
if err != nil {
return resp, fmt.Errorf("error from %T validating provider config: %w", server, err)
}
if res == nil {
continue
}
if resp == nil {
resp = res
continue
}
if len(res.Diagnostics) > 0 {
// This could implement Diagnostic deduplication if/when
// implemented upstream.
resp.Diagnostics = append(resp.Diagnostics, res.Diagnostics...)
}
if res.PreparedConfig != nil {
// This could check equality to bypass the error, however
// DynamicValue does not implement Equals() and previous mux server
// implementations have not requested the enhancement.
if resp.PreparedConfig != nil {
return nil, fmt.Errorf("got a ValidateProviderConfig PreparedConfig response from multiple servers, not sure which to use")
}
resp.PreparedConfig = res.PreparedConfig
}
}
return resp, nil
}