Skip to content

Commit

Permalink
cli: update config migration to migrate v3 -> v4 (#2166)
Browse files Browse the repository at this point in the history
  • Loading branch information
malt3 authored Aug 4, 2023
1 parent d1ace13 commit 15bb958
Show file tree
Hide file tree
Showing 4 changed files with 498 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 @@ -65,6 +65,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/constants"
"github.com/edgelesssys/constellation/v2/internal/file"
"github.com/spf13/afero"
Expand All @@ -33,19 +34,24 @@ func runConfigMigrate(cmd *cobra.Command, _ []string) error {
}

func configMigrate(cmd *cobra.Command, 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(constants.ConfigFilename, &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(constants.ConfigFilename, 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
9 changes: 8 additions & 1 deletion internal/config/migration/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,12 @@ go_library(
srcs = ["migration.go"],
importpath = "github.com/edgelesssys/constellation/v2/internal/config/migration",
visibility = ["//:__subpackages__"],
deps = ["//internal/file"],
deps = [
"//internal/attestation/idkeydigest",
"//internal/attestation/measurements",
"//internal/config",
"//internal/file",
"//internal/role",
"//internal/semver",
],
)
Loading

0 comments on commit 15bb958

Please sign in to comment.