Skip to content

Commit

Permalink
cli: update config migration to migrate v3 -> v4
Browse files Browse the repository at this point in the history
  • Loading branch information
malt3 committed Aug 4, 2023
1 parent 7bfcb0b commit 8aff487
Show file tree
Hide file tree
Showing 4 changed files with 829 additions and 8 deletions.
1 change: 1 addition & 0 deletions cli/internal/cmd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ go_library(
"//internal/compatibility",
"//internal/config",
"//internal/config/instancetypes",
"//internal/config/migration",
"//internal/constants",
"//internal/crypto",
"//internal/file",
Expand Down
10 changes: 8 additions & 2 deletions cli/internal/cmd/configmigrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"

"github.com/edgelesssys/constellation/v2/internal/config"
"github.com/edgelesssys/constellation/v2/internal/config/migration"
"github.com/edgelesssys/constellation/v2/internal/file"
"github.com/spf13/afero"
"github.com/spf13/cobra"
Expand All @@ -36,19 +37,24 @@ func runConfigMigrate(cmd *cobra.Command, _ []string) error {
}

func configMigrate(cmd *cobra.Command, configPath string, handler file.Handler) error {
// Make sure we are reading a v2 config
// Make sure we are reading a v3 config
var cfgVersion struct {
Version string `yaml:"version"`
}
if err := handler.ReadYAML(configPath, &cfgVersion); err != nil {
return err
}

// TODO(malt3): add migration from v3 to v4
switch cfgVersion.Version {
case config.Version4:
cmd.Printf("Config already at version %s, nothing to do\n", config.Version4)
return nil
case migration.Version3:
if err := migration.V3ToV4(configPath, handler); err != nil {
return fmt.Errorf("migrating config: %w", err)
}
cmd.Printf("Successfully migrated config to %s\n", config.Version4)
return nil
default:
return fmt.Errorf("cannot convert config version %s to %s", cfgVersion.Version, config.Version4)
}
Expand Down
12 changes: 11 additions & 1 deletion internal/config/migration/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,15 @@ go_library(
srcs = ["migration.go"],
importpath = "github.com/edgelesssys/constellation/v2/internal/config/migration",
visibility = ["//:__subpackages__"],
deps = ["//internal/file"],
deps = [
"//internal/api/attestationconfigapi",
"//internal/attestation/idkeydigest",
"//internal/attestation/measurements",
"//internal/attestation/variant",
"//internal/cloud/cloudprovider",
"//internal/config",
"//internal/file",
"//internal/role",
"//internal/semver",
],
)
Loading

0 comments on commit 8aff487

Please sign in to comment.