2022-01-31 10:31:51 +00:00
|
|
|
package stack
|
|
|
|
|
|
|
|
import (
|
Lift context parameter to SerializeDeployment/Resource/Operations/Properties (#15929)
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
SerializePropertyValue needed a `context.Context` object to pass to the
`config.Encrypter`. It was using `context.TODO()`, this change instead
accepts a context on the parameters and lifts that up to
SerializeProperties, SerializeResource, SerializeOperation, and
SerializeDeployment.
There were a few call sites for those methods that already had a context
on hand, and they now pass that context. The other calls sites now use
`context.TODO()`, we should continue to iterate in this area to ensure
everywhere that needs a context has one passed in.
## 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
- [ ] 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-04-15 07:45:46 +00:00
|
|
|
"context"
|
|
|
|
|
2023-09-18 11:01:28 +00:00
|
|
|
"github.com/pulumi/pulumi/pkg/v3/display"
|
2022-01-31 10:31:51 +00:00
|
|
|
"github.com/pulumi/pulumi/pkg/v3/resource/deploy"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
func SerializePlanDiff(
|
|
|
|
diff deploy.PlanDiff,
|
|
|
|
enc config.Encrypter,
|
2023-03-03 16:36:39 +00:00
|
|
|
showSecrets bool,
|
|
|
|
) (apitype.PlanDiffV1, error) {
|
Lift context parameter to SerializeDeployment/Resource/Operations/Properties (#15929)
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
SerializePropertyValue needed a `context.Context` object to pass to the
`config.Encrypter`. It was using `context.TODO()`, this change instead
accepts a context on the parameters and lifts that up to
SerializeProperties, SerializeResource, SerializeOperation, and
SerializeDeployment.
There were a few call sites for those methods that already had a context
on hand, and they now pass that context. The other calls sites now use
`context.TODO()`, we should continue to iterate in this area to ensure
everywhere that needs a context has one passed in.
## 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
- [ ] 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-04-15 07:45:46 +00:00
|
|
|
ctx := context.TODO()
|
|
|
|
adds, err := SerializeProperties(ctx, diff.Adds, enc, showSecrets)
|
2022-01-31 10:31:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return apitype.PlanDiffV1{}, err
|
|
|
|
}
|
|
|
|
|
Lift context parameter to SerializeDeployment/Resource/Operations/Properties (#15929)
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
SerializePropertyValue needed a `context.Context` object to pass to the
`config.Encrypter`. It was using `context.TODO()`, this change instead
accepts a context on the parameters and lifts that up to
SerializeProperties, SerializeResource, SerializeOperation, and
SerializeDeployment.
There were a few call sites for those methods that already had a context
on hand, and they now pass that context. The other calls sites now use
`context.TODO()`, we should continue to iterate in this area to ensure
everywhere that needs a context has one passed in.
## 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
- [ ] 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-04-15 07:45:46 +00:00
|
|
|
updates, err := SerializeProperties(ctx, diff.Updates, enc, showSecrets)
|
2022-01-31 10:31:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return apitype.PlanDiffV1{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
deletes := make([]string, len(diff.Deletes))
|
|
|
|
for i := range deletes {
|
|
|
|
deletes[i] = string(diff.Deletes[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
return apitype.PlanDiffV1{
|
|
|
|
Adds: adds,
|
|
|
|
Updates: updates,
|
|
|
|
Deletes: deletes,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func DeserializePlanDiff(
|
|
|
|
diff apitype.PlanDiffV1,
|
|
|
|
dec config.Decrypter,
|
2023-03-03 16:36:39 +00:00
|
|
|
enc config.Encrypter,
|
|
|
|
) (deploy.PlanDiff, error) {
|
2022-01-31 10:31:51 +00:00
|
|
|
adds, err := DeserializeProperties(diff.Adds, dec, enc)
|
|
|
|
if err != nil {
|
|
|
|
return deploy.PlanDiff{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
updates, err := DeserializeProperties(diff.Updates, dec, enc)
|
|
|
|
if err != nil {
|
|
|
|
return deploy.PlanDiff{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
deletes := make([]resource.PropertyKey, len(diff.Deletes))
|
|
|
|
for i := range deletes {
|
|
|
|
deletes[i] = resource.PropertyKey(diff.Deletes[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
return deploy.PlanDiff{Adds: adds, Updates: updates, Deletes: deletes}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func SerializeResourcePlan(
|
|
|
|
plan *deploy.ResourcePlan,
|
|
|
|
enc config.Encrypter,
|
2023-03-03 16:36:39 +00:00
|
|
|
showSecrets bool,
|
|
|
|
) (apitype.ResourcePlanV1, error) {
|
2022-01-31 10:31:51 +00:00
|
|
|
var outputs map[string]interface{}
|
|
|
|
if plan.Outputs != nil {
|
Lift context parameter to SerializeDeployment/Resource/Operations/Properties (#15929)
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
SerializePropertyValue needed a `context.Context` object to pass to the
`config.Encrypter`. It was using `context.TODO()`, this change instead
accepts a context on the parameters and lifts that up to
SerializeProperties, SerializeResource, SerializeOperation, and
SerializeDeployment.
There were a few call sites for those methods that already had a context
on hand, and they now pass that context. The other calls sites now use
`context.TODO()`, we should continue to iterate in this area to ensure
everywhere that needs a context has one passed in.
## 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
- [ ] 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-04-15 07:45:46 +00:00
|
|
|
ctx := context.TODO()
|
|
|
|
outs, err := SerializeProperties(ctx, plan.Outputs, enc, showSecrets)
|
2022-01-31 10:31:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return apitype.ResourcePlanV1{}, err
|
|
|
|
}
|
|
|
|
outputs = outs
|
|
|
|
}
|
|
|
|
|
|
|
|
steps := make([]apitype.OpType, len(plan.Ops))
|
|
|
|
for i, op := range plan.Ops {
|
|
|
|
steps[i] = apitype.OpType(op)
|
|
|
|
}
|
|
|
|
|
|
|
|
var goal *apitype.GoalV1
|
|
|
|
if plan.Goal != nil {
|
|
|
|
inputDiff, err := SerializePlanDiff(plan.Goal.InputDiff, enc, showSecrets)
|
|
|
|
if err != nil {
|
|
|
|
return apitype.ResourcePlanV1{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
outputDiff, err := SerializePlanDiff(plan.Goal.OutputDiff, enc, showSecrets)
|
|
|
|
if err != nil {
|
|
|
|
return apitype.ResourcePlanV1{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
goal = &apitype.GoalV1{
|
|
|
|
Type: plan.Goal.Type,
|
|
|
|
Name: plan.Goal.Name,
|
|
|
|
Custom: plan.Goal.Custom,
|
|
|
|
InputDiff: inputDiff,
|
|
|
|
OutputDiff: outputDiff,
|
|
|
|
Parent: plan.Goal.Parent,
|
|
|
|
Protect: plan.Goal.Protect,
|
|
|
|
Dependencies: plan.Goal.Dependencies,
|
|
|
|
Provider: plan.Goal.Provider,
|
|
|
|
PropertyDependencies: plan.Goal.PropertyDependencies,
|
|
|
|
DeleteBeforeReplace: plan.Goal.DeleteBeforeReplace,
|
|
|
|
IgnoreChanges: plan.Goal.IgnoreChanges,
|
|
|
|
AdditionalSecretOutputs: plan.Goal.AdditionalSecretOutputs,
|
|
|
|
Aliases: plan.Goal.Aliases,
|
|
|
|
ID: plan.Goal.ID,
|
|
|
|
CustomTimeouts: plan.Goal.CustomTimeouts,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return apitype.ResourcePlanV1{
|
|
|
|
Goal: goal,
|
2022-08-09 16:40:59 +00:00
|
|
|
Seed: plan.Seed,
|
2022-01-31 10:31:51 +00:00
|
|
|
Steps: steps,
|
|
|
|
Outputs: outputs,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func SerializePlan(plan *deploy.Plan, enc config.Encrypter, showSecrets bool) (apitype.DeploymentPlanV1, error) {
|
|
|
|
resourcePlans := map[resource.URN]apitype.ResourcePlanV1{}
|
|
|
|
for urn, plan := range plan.ResourcePlans {
|
|
|
|
serializedPlan, err := SerializeResourcePlan(plan, enc, showSecrets)
|
|
|
|
if err != nil {
|
|
|
|
return apitype.DeploymentPlanV1{}, err
|
|
|
|
}
|
|
|
|
resourcePlans[urn] = serializedPlan
|
|
|
|
}
|
|
|
|
|
|
|
|
return apitype.DeploymentPlanV1{
|
|
|
|
Manifest: plan.Manifest.Serialize(),
|
|
|
|
ResourcePlans: resourcePlans,
|
|
|
|
Config: plan.Config,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func DeserializeResourcePlan(
|
|
|
|
plan apitype.ResourcePlanV1,
|
|
|
|
dec config.Decrypter,
|
2023-03-03 16:36:39 +00:00
|
|
|
enc config.Encrypter,
|
|
|
|
) (*deploy.ResourcePlan, error) {
|
2022-06-01 10:25:01 +00:00
|
|
|
var goal *deploy.GoalPlan
|
|
|
|
if plan.Goal != nil {
|
|
|
|
inputDiff, err := DeserializePlanDiff(plan.Goal.InputDiff, dec, enc)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-01-31 10:31:51 +00:00
|
|
|
|
2022-06-01 10:25:01 +00:00
|
|
|
outputDiff, err := DeserializePlanDiff(plan.Goal.OutputDiff, dec, enc)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
goal = &deploy.GoalPlan{
|
|
|
|
Type: plan.Goal.Type,
|
|
|
|
Name: plan.Goal.Name,
|
|
|
|
Custom: plan.Goal.Custom,
|
|
|
|
InputDiff: inputDiff,
|
|
|
|
OutputDiff: outputDiff,
|
|
|
|
Parent: plan.Goal.Parent,
|
|
|
|
Protect: plan.Goal.Protect,
|
|
|
|
Dependencies: plan.Goal.Dependencies,
|
|
|
|
Provider: plan.Goal.Provider,
|
|
|
|
PropertyDependencies: plan.Goal.PropertyDependencies,
|
|
|
|
DeleteBeforeReplace: plan.Goal.DeleteBeforeReplace,
|
|
|
|
IgnoreChanges: plan.Goal.IgnoreChanges,
|
|
|
|
AdditionalSecretOutputs: plan.Goal.AdditionalSecretOutputs,
|
|
|
|
Aliases: plan.Goal.Aliases,
|
|
|
|
ID: plan.Goal.ID,
|
|
|
|
CustomTimeouts: plan.Goal.CustomTimeouts,
|
|
|
|
}
|
2022-01-31 10:31:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var outputs resource.PropertyMap
|
|
|
|
if plan.Outputs != nil {
|
|
|
|
outs, err := DeserializeProperties(plan.Outputs, dec, enc)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
outputs = outs
|
|
|
|
}
|
|
|
|
|
2022-06-27 14:08:06 +00:00
|
|
|
ops := make([]display.StepOp, len(plan.Steps))
|
2022-01-31 10:31:51 +00:00
|
|
|
for i, op := range plan.Steps {
|
2022-06-27 14:08:06 +00:00
|
|
|
ops[i] = display.StepOp(op)
|
2022-01-31 10:31:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &deploy.ResourcePlan{
|
|
|
|
Goal: goal,
|
2022-08-09 16:40:59 +00:00
|
|
|
Seed: plan.Seed,
|
2022-01-31 10:31:51 +00:00
|
|
|
Ops: ops,
|
|
|
|
Outputs: outputs,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func DeserializePlan(plan apitype.DeploymentPlanV1, dec config.Decrypter, enc config.Encrypter) (*deploy.Plan, error) {
|
|
|
|
manifest, err := deploy.DeserializeManifest(plan.Manifest)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
deserializedPlan := &deploy.Plan{
|
|
|
|
Config: plan.Config,
|
|
|
|
Manifest: *manifest,
|
|
|
|
ResourcePlans: make(map[resource.URN]*deploy.ResourcePlan),
|
|
|
|
}
|
|
|
|
for urn, resourcePlan := range plan.ResourcePlans {
|
|
|
|
deserializedResourcePlan, err := DeserializeResourcePlan(resourcePlan, dec, enc)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
deserializedPlan.ResourcePlans[urn] = deserializedResourcePlan
|
|
|
|
}
|
|
|
|
return deserializedPlan, nil
|
|
|
|
}
|