2020-12-23 21:25:48 +00:00
|
|
|
// Copyright 2016-2020, Pulumi Corporation.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
2024-01-17 09:35:20 +00:00
|
|
|
"google.golang.org/protobuf/types/known/emptypb"
|
2020-12-23 21:25:48 +00:00
|
|
|
|
2021-03-17 13:20:05 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/config"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
|
|
|
|
pulumirpc "github.com/pulumi/pulumi/sdk/v3/proto/go"
|
2020-12-23 21:25:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type providerServer struct {
|
2022-12-14 19:20:26 +00:00
|
|
|
pulumirpc.UnsafeResourceProviderServer // opt out of forward compat
|
|
|
|
|
2020-12-23 21:25:48 +00:00
|
|
|
provider Provider
|
|
|
|
keepSecrets bool
|
|
|
|
keepResources bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewProviderServer(provider Provider) pulumirpc.ResourceProviderServer {
|
|
|
|
return &providerServer{provider: provider}
|
|
|
|
}
|
|
|
|
|
2024-02-08 16:06:40 +00:00
|
|
|
func (p *providerServer) unmarshalOptions(label string, keepOutputValues bool) MarshalOptions {
|
2020-12-23 21:25:48 +00:00
|
|
|
return MarshalOptions{
|
2024-02-08 16:06:40 +00:00
|
|
|
Label: label,
|
|
|
|
KeepUnknowns: true,
|
|
|
|
KeepSecrets: true,
|
|
|
|
KeepResources: true,
|
|
|
|
KeepOutputValues: keepOutputValues,
|
2020-12-23 21:25:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *providerServer) marshalOptions(label string) MarshalOptions {
|
|
|
|
return MarshalOptions{
|
|
|
|
Label: label,
|
|
|
|
KeepUnknowns: true,
|
|
|
|
KeepSecrets: p.keepSecrets,
|
|
|
|
KeepResources: p.keepResources,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *providerServer) checkNYI(method string, err error) error {
|
|
|
|
if err == ErrNotYetImplemented {
|
|
|
|
return status.Error(codes.Unimplemented, fmt.Sprintf("%v is not yet implemented", method))
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *providerServer) marshalDiff(diff DiffResult) (*pulumirpc.DiffResponse, error) {
|
turn on the golangci-lint exhaustive linter (#15028)
Turn on the golangci-lint exhaustive linter. This is the first step
towards catching more missing cases during development rather than
in tests, or in production.
This might be best reviewed commit-by-commit, as the first commit turns
on the linter with the `default-signifies-exhaustive: true` option set,
which requires a lot less changes in the current codebase.
I think it's probably worth doing the second commit as well, as that
will get us the real benefits, even though we end up with a little bit
more churn. However it means all the `switch` statements are covered,
which isn't the case after the first commit, since we do have a lot of
`default` statements that just call `assert.Fail`.
Fixes #14601
## Checklist
- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
- [x] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2024-01-17 16:50:41 +00:00
|
|
|
var changes pulumirpc.DiffResponse_DiffChanges
|
2020-12-23 21:25:48 +00:00
|
|
|
switch diff.Changes {
|
|
|
|
case DiffNone:
|
|
|
|
changes = pulumirpc.DiffResponse_DIFF_NONE
|
|
|
|
case DiffSome:
|
|
|
|
changes = pulumirpc.DiffResponse_DIFF_SOME
|
turn on the golangci-lint exhaustive linter (#15028)
Turn on the golangci-lint exhaustive linter. This is the first step
towards catching more missing cases during development rather than
in tests, or in production.
This might be best reviewed commit-by-commit, as the first commit turns
on the linter with the `default-signifies-exhaustive: true` option set,
which requires a lot less changes in the current codebase.
I think it's probably worth doing the second commit as well, as that
will get us the real benefits, even though we end up with a little bit
more churn. However it means all the `switch` statements are covered,
which isn't the case after the first commit, since we do have a lot of
`default` statements that just call `assert.Fail`.
Fixes #14601
## Checklist
- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
- [x] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2024-01-17 16:50:41 +00:00
|
|
|
case DiffUnknown:
|
|
|
|
changes = pulumirpc.DiffResponse_DIFF_UNKNOWN
|
2020-12-23 21:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Infer the result from the detailed diff.
|
|
|
|
var diffs, replaces []string
|
|
|
|
var detailedDiff map[string]*pulumirpc.PropertyDiff
|
|
|
|
if len(diff.DetailedDiff) == 0 {
|
|
|
|
diffs = make([]string, len(diff.ChangedKeys))
|
|
|
|
for i, k := range diff.ChangedKeys {
|
|
|
|
diffs[i] = string(k)
|
|
|
|
}
|
|
|
|
replaces = make([]string, len(diff.ReplaceKeys))
|
|
|
|
for i, k := range diff.ReplaceKeys {
|
|
|
|
replaces[i] = string(k)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
changes = pulumirpc.DiffResponse_DIFF_SOME
|
|
|
|
|
|
|
|
detailedDiff = make(map[string]*pulumirpc.PropertyDiff)
|
|
|
|
for path, diff := range diff.DetailedDiff {
|
|
|
|
diffs = append(diffs, path)
|
|
|
|
|
|
|
|
var kind pulumirpc.PropertyDiff_Kind
|
|
|
|
switch diff.Kind {
|
|
|
|
case DiffAdd:
|
|
|
|
kind = pulumirpc.PropertyDiff_ADD
|
|
|
|
case DiffAddReplace:
|
|
|
|
kind, replaces = pulumirpc.PropertyDiff_ADD_REPLACE, append(replaces, path)
|
|
|
|
case DiffDelete:
|
|
|
|
kind = pulumirpc.PropertyDiff_DELETE
|
|
|
|
case DiffDeleteReplace:
|
|
|
|
kind, replaces = pulumirpc.PropertyDiff_DELETE, append(replaces, path)
|
|
|
|
case DiffUpdate:
|
|
|
|
kind = pulumirpc.PropertyDiff_UPDATE
|
|
|
|
case DiffUpdateReplace:
|
|
|
|
kind, replaces = pulumirpc.PropertyDiff_UPDATE_REPLACE, append(replaces, path)
|
|
|
|
}
|
|
|
|
|
|
|
|
detailedDiff[path] = &pulumirpc.PropertyDiff{
|
|
|
|
Kind: kind,
|
|
|
|
InputDiff: diff.InputDiff,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &pulumirpc.DiffResponse{
|
|
|
|
Replaces: replaces,
|
|
|
|
DeleteBeforeReplace: diff.DeleteBeforeReplace,
|
|
|
|
Changes: changes,
|
|
|
|
Diffs: diffs,
|
|
|
|
DetailedDiff: detailedDiff,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *providerServer) GetSchema(ctx context.Context,
|
2023-03-03 16:36:39 +00:00
|
|
|
req *pulumirpc.GetSchemaRequest,
|
|
|
|
) (*pulumirpc.GetSchemaResponse, error) {
|
2020-12-23 21:25:48 +00:00
|
|
|
schema, err := p.provider.GetSchema(int(req.GetVersion()))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &pulumirpc.GetSchemaResponse{Schema: string(schema)}, nil
|
|
|
|
}
|
|
|
|
|
2024-01-17 09:35:20 +00:00
|
|
|
func (p *providerServer) GetPluginInfo(ctx context.Context, req *emptypb.Empty) (*pulumirpc.PluginInfo, error) {
|
2020-12-23 21:25:48 +00:00
|
|
|
info, err := p.provider.GetPluginInfo()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &pulumirpc.PluginInfo{Version: info.Version.String()}, nil
|
|
|
|
}
|
|
|
|
|
2024-01-17 09:35:20 +00:00
|
|
|
func (p *providerServer) Attach(ctx context.Context, req *pulumirpc.PluginAttach) (*emptypb.Empty, error) {
|
2022-04-19 11:41:18 +00:00
|
|
|
// NewProviderServer should take a GrpcProvider instead of Provider, but that's a breaking change
|
|
|
|
// so for now we type test here
|
|
|
|
if grpcProvider, ok := p.provider.(GrpcProvider); ok {
|
|
|
|
err := grpcProvider.Attach(req.GetAddress())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-01-17 09:35:20 +00:00
|
|
|
return &emptypb.Empty{}, nil
|
2022-04-19 11:41:18 +00:00
|
|
|
}
|
|
|
|
// Else report this is unsupported
|
|
|
|
return nil, status.Error(codes.Unimplemented, "Attach is not yet implemented")
|
|
|
|
}
|
|
|
|
|
2024-01-17 09:35:20 +00:00
|
|
|
func (p *providerServer) Cancel(ctx context.Context, req *emptypb.Empty) (*emptypb.Empty, error) {
|
2020-12-23 21:25:48 +00:00
|
|
|
if err := p.provider.SignalCancellation(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-01-17 09:35:20 +00:00
|
|
|
return &emptypb.Empty{}, nil
|
2020-12-23 21:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *providerServer) CheckConfig(ctx context.Context,
|
2023-03-03 16:36:39 +00:00
|
|
|
req *pulumirpc.CheckRequest,
|
|
|
|
) (*pulumirpc.CheckResponse, error) {
|
2020-12-23 21:25:48 +00:00
|
|
|
urn := resource.URN(req.GetUrn())
|
|
|
|
|
2024-02-08 16:06:40 +00:00
|
|
|
state, err := UnmarshalProperties(req.GetOlds(), p.unmarshalOptions("olds", false /* keepOutputValues */))
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-02-08 16:06:40 +00:00
|
|
|
inputs, err := UnmarshalProperties(req.GetNews(), p.unmarshalOptions("news", false /* keepOutputValues */))
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
newInputs, failures, err := p.provider.CheckConfig(urn, state, inputs, true)
|
|
|
|
if err != nil {
|
|
|
|
return nil, p.checkNYI("CheckConfig", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
rpcInputs, err := MarshalProperties(newInputs, p.marshalOptions("inputs"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
rpcFailures := make([]*pulumirpc.CheckFailure, len(failures))
|
|
|
|
for i, f := range failures {
|
|
|
|
rpcFailures[i] = &pulumirpc.CheckFailure{Property: string(f.Property), Reason: f.Reason}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &pulumirpc.CheckResponse{Inputs: rpcInputs, Failures: rpcFailures}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *providerServer) DiffConfig(ctx context.Context, req *pulumirpc.DiffRequest) (*pulumirpc.DiffResponse, error) {
|
|
|
|
urn := resource.URN(req.GetUrn())
|
|
|
|
|
2024-02-08 16:06:40 +00:00
|
|
|
oldInputs, err := UnmarshalProperties(
|
|
|
|
req.GetOldInputs(), p.unmarshalOptions("oldInputs", false /* keepOutputValues */))
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-02-08 16:06:40 +00:00
|
|
|
oldOutputs, err := UnmarshalProperties(
|
|
|
|
req.GetOlds(), p.unmarshalOptions("oldOutputs", false /* keepOutputValues */))
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-02-08 16:06:40 +00:00
|
|
|
newInputs, err := UnmarshalProperties(
|
|
|
|
req.GetNews(), p.unmarshalOptions("newInputs", false /* keepOutputValues */))
|
2023-05-29 15:41:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
diff, err := p.provider.DiffConfig(urn, oldInputs, oldOutputs, newInputs, true, req.GetIgnoreChanges())
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, p.checkNYI("DiffConfig", err)
|
|
|
|
}
|
|
|
|
return p.marshalDiff(diff)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *providerServer) Configure(ctx context.Context,
|
2023-03-03 16:36:39 +00:00
|
|
|
req *pulumirpc.ConfigureRequest,
|
|
|
|
) (*pulumirpc.ConfigureResponse, error) {
|
2020-12-23 21:25:48 +00:00
|
|
|
var inputs resource.PropertyMap
|
|
|
|
if req.GetArgs() != nil {
|
2024-02-08 16:06:40 +00:00
|
|
|
args, err := UnmarshalProperties(req.GetArgs(), p.unmarshalOptions("args", false /* keepOutputValues */))
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
inputs = args
|
|
|
|
} else {
|
2023-01-12 19:29:28 +00:00
|
|
|
inputs = make(resource.PropertyMap)
|
2020-12-23 21:25:48 +00:00
|
|
|
for k, v := range req.GetVariables() {
|
|
|
|
key, err := config.ParseKey(k)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var value interface{}
|
|
|
|
if err = json.Unmarshal([]byte(v), &value); err != nil {
|
|
|
|
// If we couldn't unmarshal a JSON value, just pass the raw string through.
|
|
|
|
value = v
|
|
|
|
}
|
|
|
|
|
|
|
|
inputs[resource.PropertyKey(key.Name())] = resource.NewPropertyValue(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := p.provider.Configure(inputs); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
p.keepSecrets = req.GetAcceptSecrets()
|
|
|
|
p.keepResources = req.GetAcceptResources()
|
2024-02-08 16:06:40 +00:00
|
|
|
return &pulumirpc.ConfigureResponse{
|
|
|
|
AcceptSecrets: true, SupportsPreview: true, AcceptResources: true, AcceptOutputs: true,
|
|
|
|
}, nil
|
2020-12-23 21:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *providerServer) Check(ctx context.Context, req *pulumirpc.CheckRequest) (*pulumirpc.CheckResponse, error) {
|
|
|
|
urn := resource.URN(req.GetUrn())
|
|
|
|
|
2024-02-08 16:06:40 +00:00
|
|
|
state, err := UnmarshalProperties(req.GetOlds(), p.unmarshalOptions("state", false /* keepOutputValues */))
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-02-08 16:06:40 +00:00
|
|
|
inputs, err := UnmarshalProperties(req.GetNews(), p.unmarshalOptions("inputs", false /* keepOutputValues */))
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-08-09 16:40:59 +00:00
|
|
|
newInputs, failures, err := p.provider.Check(urn, state, inputs, true, req.RandomSeed)
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
rpcInputs, err := MarshalProperties(newInputs, p.marshalOptions("newInputs"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
rpcFailures := make([]*pulumirpc.CheckFailure, len(failures))
|
|
|
|
for i, f := range failures {
|
|
|
|
rpcFailures[i] = &pulumirpc.CheckFailure{Property: string(f.Property), Reason: f.Reason}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &pulumirpc.CheckResponse{Inputs: rpcInputs, Failures: rpcFailures}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *providerServer) Diff(ctx context.Context, req *pulumirpc.DiffRequest) (*pulumirpc.DiffResponse, error) {
|
|
|
|
urn, id := resource.URN(req.GetUrn()), resource.ID(req.GetId())
|
|
|
|
|
2024-02-08 16:06:40 +00:00
|
|
|
oldInputs, err := UnmarshalProperties(
|
|
|
|
req.GetOldInputs(), p.unmarshalOptions("oldInputs", false /* keepOutputValues */))
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-02-08 16:06:40 +00:00
|
|
|
oldOutputs, err := UnmarshalProperties(
|
|
|
|
req.GetOlds(), p.unmarshalOptions("oldOutputs", false /* keepOutputValues */))
|
2023-05-29 15:41:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-02-08 16:06:40 +00:00
|
|
|
newInputs, err := UnmarshalProperties(
|
|
|
|
req.GetNews(), p.unmarshalOptions("newInputs", false /* keepOutputValues */))
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-05-29 15:41:36 +00:00
|
|
|
diff, err := p.provider.Diff(urn, id, oldInputs, oldOutputs, newInputs, true, req.GetIgnoreChanges())
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return p.marshalDiff(diff)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *providerServer) Create(ctx context.Context, req *pulumirpc.CreateRequest) (*pulumirpc.CreateResponse, error) {
|
|
|
|
urn := resource.URN(req.GetUrn())
|
|
|
|
|
2024-02-08 16:06:40 +00:00
|
|
|
inputs, err := UnmarshalProperties(req.GetProperties(), p.unmarshalOptions("inputs", false /* keepOutputValues */))
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
id, state, _, err := p.provider.Create(urn, inputs, req.GetTimeout(), req.GetPreview())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
rpcState, err := MarshalProperties(state, p.marshalOptions("newState"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &pulumirpc.CreateResponse{
|
|
|
|
Id: string(id),
|
|
|
|
Properties: rpcState,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *providerServer) Read(ctx context.Context, req *pulumirpc.ReadRequest) (*pulumirpc.ReadResponse, error) {
|
2023-03-10 14:44:00 +00:00
|
|
|
urn, requestID := resource.URN(req.GetUrn()), resource.ID(req.GetId())
|
2020-12-23 21:25:48 +00:00
|
|
|
|
2024-02-08 16:06:40 +00:00
|
|
|
state, err := UnmarshalProperties(req.GetProperties(), p.unmarshalOptions("state", false /* keepOutputValues */))
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-02-08 16:06:40 +00:00
|
|
|
inputs, err := UnmarshalProperties(req.GetInputs(), p.unmarshalOptions("inputs", false /* keepOutputValues */))
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-03-10 14:44:00 +00:00
|
|
|
result, _, err := p.provider.Read(urn, requestID, inputs, state)
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
rpcState, err := MarshalProperties(result.Outputs, p.marshalOptions("newState"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
rpcInputs, err := MarshalProperties(result.Inputs, p.marshalOptions("newInputs"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &pulumirpc.ReadResponse{
|
2023-03-10 14:44:00 +00:00
|
|
|
Id: string(result.ID),
|
2020-12-23 21:25:48 +00:00
|
|
|
Properties: rpcState,
|
|
|
|
Inputs: rpcInputs,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *providerServer) Update(ctx context.Context, req *pulumirpc.UpdateRequest) (*pulumirpc.UpdateResponse, error) {
|
|
|
|
urn, id := resource.URN(req.GetUrn()), resource.ID(req.GetId())
|
|
|
|
|
2024-02-08 16:06:40 +00:00
|
|
|
oldOutputs, err := UnmarshalProperties(
|
|
|
|
req.GetOlds(), p.unmarshalOptions("oldOutputs", false /* keepOutputValues */))
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-02-08 16:06:40 +00:00
|
|
|
oldInputs, err := UnmarshalProperties(
|
|
|
|
req.GetOldInputs(), p.unmarshalOptions("oldInputs", false /* keepOutputValues */))
|
2023-05-29 15:41:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-02-08 16:06:40 +00:00
|
|
|
newInputs, err := UnmarshalProperties(
|
|
|
|
req.GetNews(), p.unmarshalOptions("newInputs", false /* keepOutputValues */))
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-05-29 15:41:36 +00:00
|
|
|
newState, _, err := p.provider.Update(
|
|
|
|
urn, id, oldOutputs, oldInputs, newInputs,
|
|
|
|
req.GetTimeout(), req.GetIgnoreChanges(), req.GetPreview())
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
rpcState, err := MarshalProperties(newState, p.marshalOptions("newState"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &pulumirpc.UpdateResponse{Properties: rpcState}, nil
|
|
|
|
}
|
|
|
|
|
2024-01-17 09:35:20 +00:00
|
|
|
func (p *providerServer) Delete(ctx context.Context, req *pulumirpc.DeleteRequest) (*emptypb.Empty, error) {
|
2020-12-23 21:25:48 +00:00
|
|
|
urn, id := resource.URN(req.GetUrn()), resource.ID(req.GetId())
|
|
|
|
|
2024-02-08 16:06:40 +00:00
|
|
|
inputs, err := UnmarshalProperties(req.GetOldInputs(), p.unmarshalOptions("inputs", false /* keepOutputValues */))
|
2023-10-13 14:12:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-02-08 16:06:40 +00:00
|
|
|
outputs, err := UnmarshalProperties(req.GetProperties(), p.unmarshalOptions("outputs", false /* keepOutputValues */))
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-10-13 14:12:26 +00:00
|
|
|
if _, err = p.provider.Delete(urn, id, inputs, outputs, req.GetTimeout()); err != nil {
|
2020-12-23 21:25:48 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-01-17 09:35:20 +00:00
|
|
|
return &emptypb.Empty{}, nil
|
2020-12-23 21:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *providerServer) Construct(ctx context.Context,
|
2023-03-03 16:36:39 +00:00
|
|
|
req *pulumirpc.ConstructRequest,
|
|
|
|
) (*pulumirpc.ConstructResponse, error) {
|
2023-11-20 08:59:00 +00:00
|
|
|
typ, name, parent := tokens.Type(req.GetType()), req.GetName(), resource.URN(req.GetParent())
|
2020-12-23 21:25:48 +00:00
|
|
|
|
2024-02-08 16:06:40 +00:00
|
|
|
inputs, err := UnmarshalProperties(req.GetInputs(), p.unmarshalOptions("inputs", true /* keepOutputValues */))
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg := map[config.Key]string{}
|
|
|
|
for k, v := range req.GetConfig() {
|
|
|
|
configKey, err := config.ParseKey(k)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
cfg[configKey] = v
|
|
|
|
}
|
2021-06-24 22:38:01 +00:00
|
|
|
|
|
|
|
cfgSecretKeys := []config.Key{}
|
|
|
|
for _, k := range req.GetConfigSecretKeys() {
|
|
|
|
key, err := config.ParseKey(k)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
cfgSecretKeys = append(cfgSecretKeys, key)
|
|
|
|
}
|
|
|
|
|
2020-12-23 21:25:48 +00:00
|
|
|
info := ConstructInfo{
|
2021-06-24 22:38:01 +00:00
|
|
|
Project: req.GetProject(),
|
|
|
|
Stack: req.GetStack(),
|
|
|
|
Config: cfg,
|
|
|
|
ConfigSecretKeys: cfgSecretKeys,
|
|
|
|
DryRun: req.GetDryRun(),
|
|
|
|
Parallel: int(req.GetParallel()),
|
|
|
|
MonitorAddress: req.GetMonitorEndpoint(),
|
2020-12-23 21:25:48 +00:00
|
|
|
}
|
|
|
|
|
2022-09-22 17:13:55 +00:00
|
|
|
aliases := make([]resource.Alias, len(req.GetAliases()))
|
|
|
|
for i, urn := range req.GetAliases() {
|
|
|
|
aliases[i] = resource.Alias{URN: resource.URN(urn)}
|
2020-12-23 21:25:48 +00:00
|
|
|
}
|
|
|
|
dependencies := make([]resource.URN, len(req.GetDependencies()))
|
2021-02-18 00:56:47 +00:00
|
|
|
for i, urn := range req.GetDependencies() {
|
2020-12-23 21:25:48 +00:00
|
|
|
dependencies[i] = resource.URN(urn)
|
|
|
|
}
|
|
|
|
propertyDependencies := map[resource.PropertyKey][]resource.URN{}
|
|
|
|
for name, deps := range req.GetInputDependencies() {
|
|
|
|
urns := make([]resource.URN, len(deps.Urns))
|
|
|
|
for i, urn := range deps.Urns {
|
|
|
|
urns[i] = resource.URN(urn)
|
|
|
|
}
|
|
|
|
propertyDependencies[resource.PropertyKey(name)] = urns
|
|
|
|
}
|
|
|
|
options := ConstructOptions{
|
2022-09-22 17:13:55 +00:00
|
|
|
Aliases: aliases,
|
2020-12-23 21:25:48 +00:00
|
|
|
Dependencies: dependencies,
|
|
|
|
Protect: req.GetProtect(),
|
|
|
|
Providers: req.GetProviders(),
|
|
|
|
PropertyDependencies: propertyDependencies,
|
|
|
|
}
|
|
|
|
|
|
|
|
result, err := p.provider.Construct(info, typ, name, parent, inputs, options)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-02-14 08:15:24 +00:00
|
|
|
opts := p.marshalOptions("outputs")
|
|
|
|
opts.KeepOutputValues = req.AcceptsOutputValues
|
|
|
|
outputs, err := MarshalProperties(result.Outputs, opts)
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
outputDependencies := map[string]*pulumirpc.ConstructResponse_PropertyDependencies{}
|
|
|
|
for name, deps := range result.OutputDependencies {
|
|
|
|
urns := make([]string, len(deps))
|
|
|
|
for i, urn := range deps {
|
|
|
|
urns[i] = string(urn)
|
|
|
|
}
|
|
|
|
outputDependencies[string(name)] = &pulumirpc.ConstructResponse_PropertyDependencies{Urns: urns}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &pulumirpc.ConstructResponse{
|
|
|
|
Urn: string(result.URN),
|
|
|
|
State: outputs,
|
|
|
|
StateDependencies: outputDependencies,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *providerServer) Invoke(ctx context.Context, req *pulumirpc.InvokeRequest) (*pulumirpc.InvokeResponse, error) {
|
2024-02-08 16:06:40 +00:00
|
|
|
args, err := UnmarshalProperties(req.GetArgs(), p.unmarshalOptions("args", false /* keepOutputValues */))
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
result, failures, err := p.provider.Invoke(tokens.ModuleMember(req.GetTok()), args)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
rpcResult, err := MarshalProperties(result, p.marshalOptions("result"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
rpcFailures := make([]*pulumirpc.CheckFailure, len(failures))
|
|
|
|
for i, f := range failures {
|
|
|
|
rpcFailures[i] = &pulumirpc.CheckFailure{Property: string(f.Property), Reason: f.Reason}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &pulumirpc.InvokeResponse{
|
|
|
|
Return: rpcResult,
|
|
|
|
Failures: rpcFailures,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *providerServer) StreamInvoke(req *pulumirpc.InvokeRequest,
|
2023-03-03 16:36:39 +00:00
|
|
|
server pulumirpc.ResourceProvider_StreamInvokeServer,
|
|
|
|
) error {
|
2024-02-08 16:06:40 +00:00
|
|
|
args, err := UnmarshalProperties(req.GetArgs(), p.unmarshalOptions("args", false /* keepOutputValues */))
|
2020-12-23 21:25:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
failures, err := p.provider.StreamInvoke(tokens.ModuleMember(req.GetTok()), args,
|
|
|
|
func(item resource.PropertyMap) error {
|
|
|
|
rpcItem, err := MarshalProperties(item, p.marshalOptions("item"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return server.Send(&pulumirpc.InvokeResponse{Return: rpcItem})
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(failures) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
rpcFailures := make([]*pulumirpc.CheckFailure, len(failures))
|
|
|
|
for i, f := range failures {
|
|
|
|
rpcFailures[i] = &pulumirpc.CheckFailure{Property: string(f.Property), Reason: f.Reason}
|
|
|
|
}
|
|
|
|
|
|
|
|
return server.Send(&pulumirpc.InvokeResponse{Failures: rpcFailures})
|
|
|
|
}
|
2021-06-30 14:48:56 +00:00
|
|
|
|
|
|
|
func (p *providerServer) Call(ctx context.Context, req *pulumirpc.CallRequest) (*pulumirpc.CallResponse, error) {
|
2024-02-08 16:06:40 +00:00
|
|
|
args, err := UnmarshalProperties(req.GetArgs(), p.unmarshalOptions("args", true /* keepOutputValues */))
|
2021-06-30 14:48:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg := map[config.Key]string{}
|
|
|
|
for k, v := range req.GetConfig() {
|
|
|
|
configKey, err := config.ParseKey(k)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
cfg[configKey] = v
|
|
|
|
}
|
|
|
|
info := CallInfo{
|
|
|
|
Project: req.GetProject(),
|
|
|
|
Stack: req.GetStack(),
|
|
|
|
Config: cfg,
|
|
|
|
DryRun: req.GetDryRun(),
|
|
|
|
Parallel: int(req.GetParallel()),
|
|
|
|
MonitorAddress: req.GetMonitorEndpoint(),
|
|
|
|
}
|
|
|
|
argDependencies := map[resource.PropertyKey][]resource.URN{}
|
|
|
|
for name, deps := range req.GetArgDependencies() {
|
|
|
|
urns := make([]resource.URN, len(deps.Urns))
|
|
|
|
for i, urn := range deps.Urns {
|
|
|
|
urns[i] = resource.URN(urn)
|
|
|
|
}
|
|
|
|
argDependencies[resource.PropertyKey(name)] = urns
|
|
|
|
}
|
|
|
|
options := CallOptions{
|
|
|
|
ArgDependencies: argDependencies,
|
|
|
|
}
|
|
|
|
|
|
|
|
result, err := p.provider.Call(tokens.ModuleMember(req.GetTok()), args, info, options)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-02-14 08:15:24 +00:00
|
|
|
opts := p.marshalOptions("return")
|
|
|
|
opts.KeepOutputValues = req.AcceptsOutputValues
|
|
|
|
rpcResult, err := MarshalProperties(result.Return, opts)
|
2021-06-30 14:48:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
returnDependencies := map[string]*pulumirpc.CallResponse_ReturnDependencies{}
|
|
|
|
for name, deps := range result.ReturnDependencies {
|
|
|
|
urns := make([]string, len(deps))
|
|
|
|
for i, urn := range deps {
|
|
|
|
urns[i] = string(urn)
|
|
|
|
}
|
|
|
|
returnDependencies[string(name)] = &pulumirpc.CallResponse_ReturnDependencies{Urns: urns}
|
|
|
|
}
|
|
|
|
|
|
|
|
rpcFailures := make([]*pulumirpc.CheckFailure, len(result.Failures))
|
|
|
|
for i, f := range result.Failures {
|
|
|
|
rpcFailures[i] = &pulumirpc.CheckFailure{Property: string(f.Property), Reason: f.Reason}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &pulumirpc.CallResponse{
|
|
|
|
Return: rpcResult,
|
|
|
|
ReturnDependencies: returnDependencies,
|
|
|
|
Failures: rpcFailures,
|
|
|
|
}, nil
|
|
|
|
}
|
2022-11-16 17:22:47 +00:00
|
|
|
|
|
|
|
func (p *providerServer) GetMapping(ctx context.Context,
|
2023-03-03 16:36:39 +00:00
|
|
|
req *pulumirpc.GetMappingRequest,
|
|
|
|
) (*pulumirpc.GetMappingResponse, error) {
|
2023-09-21 11:45:07 +00:00
|
|
|
data, provider, err := p.provider.GetMapping(req.Key, req.Provider)
|
2022-12-13 11:37:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &pulumirpc.GetMappingResponse{Data: data, Provider: provider}, nil
|
2022-11-16 17:22:47 +00:00
|
|
|
}
|
2023-09-21 11:45:07 +00:00
|
|
|
|
|
|
|
func (p *providerServer) GetMappings(ctx context.Context,
|
|
|
|
req *pulumirpc.GetMappingsRequest,
|
|
|
|
) (*pulumirpc.GetMappingsResponse, error) {
|
|
|
|
providers, err := p.provider.GetMappings(req.Key)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &pulumirpc.GetMappingsResponse{Providers: providers}, nil
|
|
|
|
}
|