From 87fdb47caa577aaaec7e7baf998e0a7a5bbe0364 Mon Sep 17 00:00:00 2001 From: Otto Bittner Date: Mon, 20 Feb 2023 10:32:33 +0100 Subject: [PATCH] cli: upgrade apply uses correct measurements key (#1223) Apply still used the obsolete upgrade key's measurements. The new, desired behavior is to use the Provider's measurements key --- cli/internal/cmd/upgradeapply.go | 2 +- internal/config/config.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cli/internal/cmd/upgradeapply.go b/cli/internal/cmd/upgradeapply.go index 706f5b3aa..d4491e2ba 100644 --- a/cli/internal/cmd/upgradeapply.go +++ b/cli/internal/cmd/upgradeapply.go @@ -149,7 +149,7 @@ func (u *upgradeApplyCmd) handleImageUpgrade(ctx context.Context, conf *config.C return fmt.Errorf("parsing version from image short path: %w", err) } - err = u.upgrader.UpgradeImage(ctx, imageReference, imageVersion.Version, conf.Upgrade.Measurements) + err = u.upgrader.UpgradeImage(ctx, imageReference, imageVersion.Version, conf.GetMeasurements()) if err != nil { return fmt.Errorf("upgrading image: %w", err) } diff --git a/internal/config/config.go b/internal/config/config.go index e615d3ba8..c24115022 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -436,6 +436,23 @@ func (c *Config) GetProvider() cloudprovider.Provider { return cloudprovider.Unknown } +// GetMeasurements returns the configured measurements or nil if no provder is set. +func (c *Config) GetMeasurements() measurements.M { + if c.Provider.AWS != nil { + return c.Provider.AWS.Measurements + } + if c.Provider.Azure != nil { + return c.Provider.Azure.Measurements + } + if c.Provider.GCP != nil { + return c.Provider.GCP.Measurements + } + if c.Provider.QEMU != nil { + return c.Provider.QEMU.Measurements + } + return nil +} + // EnforcesIDKeyDigest checks whether ID Key Digest should be enforced for respective cloud provider. func (c *Config) EnforcesIDKeyDigest() bool { return c.Provider.Azure != nil && c.Provider.Azure.EnforceIDKeyDigest != nil && *c.Provider.Azure.EnforceIDKeyDigest