From 37b22b8d3c6f0d9c7c5f2eeb81adae08f69d7c4c Mon Sep 17 00:00:00 2001 From: Fraser Waters Date: Tue, 23 Nov 2021 15:35:34 +0000 Subject: [PATCH] Add manifest to plan --- pkg/resource/deploy/snapshot.go | 22 ++++++++++++++++++++++ pkg/resource/stack/deployment.go | 18 +----------------- pkg/resource/stack/plan.go | 17 ++++++++++++++++- 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/pkg/resource/deploy/snapshot.go b/pkg/resource/deploy/snapshot.go index 536bf1af1..2348461fd 100644 --- a/pkg/resource/deploy/snapshot.go +++ b/pkg/resource/deploy/snapshot.go @@ -21,6 +21,7 @@ import ( "github.com/pulumi/pulumi/pkg/v3/resource/deploy/providers" "github.com/pulumi/pulumi/pkg/v3/secrets" + "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/util/contract" "github.com/pulumi/pulumi/sdk/v3/go/common/workspace" @@ -44,6 +45,27 @@ type Manifest struct { Plugins []workspace.PluginInfo // the plugin versions also loaded. } +func (m Manifest) Serialize() apitype.ManifestV1 { + manifest := apitype.ManifestV1{ + Time: m.Time, + Magic: m.Magic, + Version: m.Version, + } + for _, plug := range m.Plugins { + var version string + if plug.Version != nil { + version = plug.Version.String() + } + manifest.Plugins = append(manifest.Plugins, apitype.PluginInfoV1{ + Name: plug.Name, + Path: plug.Path, + Type: plug.Kind, + Version: version, + }) + } + return manifest +} + // NewMagic creates a magic cookie out of a manifest; this can be used to check for tampering. This ignores // any existing magic value already stored on the manifest. func (m Manifest) NewMagic() string { diff --git a/pkg/resource/stack/deployment.go b/pkg/resource/stack/deployment.go index 73187de49..35a8de59c 100644 --- a/pkg/resource/stack/deployment.go +++ b/pkg/resource/stack/deployment.go @@ -105,23 +105,7 @@ func SerializeDeployment(snap *deploy.Snapshot, sm secrets.Manager, showSecrets contract.Require(snap != nil, "snap") // Capture the version information into a manifest. - manifest := apitype.ManifestV1{ - Time: snap.Manifest.Time, - Magic: snap.Manifest.Magic, - Version: snap.Manifest.Version, - } - for _, plug := range snap.Manifest.Plugins { - var version string - if plug.Version != nil { - version = plug.Version.String() - } - manifest.Plugins = append(manifest.Plugins, apitype.PluginInfoV1{ - Name: plug.Name, - Path: plug.Path, - Type: plug.Kind, - Version: version, - }) - } + manifest := snap.Manifest.Serialize() // If a specific secrets manager was not provided, use the one in the snapshot, if present. if sm == nil { diff --git a/pkg/resource/stack/plan.go b/pkg/resource/stack/plan.go index 62b9821bb..36bd15a6e 100644 --- a/pkg/resource/stack/plan.go +++ b/pkg/resource/stack/plan.go @@ -1,7 +1,10 @@ package stack import ( + "time" + "github.com/pulumi/pulumi/pkg/v3/resource/deploy" + "github.com/pulumi/pulumi/pkg/v3/version" "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" @@ -77,7 +80,19 @@ func SerializePlan(plan deploy.Plan, enc config.Encrypter, showSecrets bool) (ap } resourcePlans[urn] = serializedPlan } - return apitype.DeploymentPlanV1{ResourcePlans: resourcePlans}, nil + + // Bit odd this isn't part of deploy.Plan but that's just a map right now. We need to change that to track config and things so we'll move this then. + manifest := deploy.Manifest{ + Time: time.Now(), + Version: version.Version, + // Plugins: sm.plugins, - Explicitly dropped, since we don't use the plugin list in the manifest anymore. + } + manifest.Magic = manifest.NewMagic() + + return apitype.DeploymentPlanV1{ + Manifest: manifest.Serialize(), + ResourcePlans: resourcePlans, + }, nil } func DeserializeResourcePlan(