mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
d1ace13713
* Remove `--config` and `--master-secret` falgs * Add `--workspace` flag * In CLI, only work on files with paths created from `cli/internal/cmd` * Properly print values for GCP on IAM create when not directly updating the config --------- Signed-off-by: Daniel Weiße <dw@edgeless.systems>
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
/*
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/config"
|
|
"github.com/edgelesssys/constellation/v2/internal/constants"
|
|
"github.com/edgelesssys/constellation/v2/internal/file"
|
|
"github.com/spf13/afero"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func newConfigMigrateCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "migrate",
|
|
Short: "Migrate a configuration file to a new version",
|
|
Long: "Migrate a configuration file to a new version.",
|
|
Args: cobra.NoArgs,
|
|
RunE: runConfigMigrate,
|
|
}
|
|
return cmd
|
|
}
|
|
|
|
func runConfigMigrate(cmd *cobra.Command, _ []string) error {
|
|
handler := file.NewHandler(afero.NewOsFs())
|
|
return configMigrate(cmd, handler)
|
|
}
|
|
|
|
func configMigrate(cmd *cobra.Command, handler file.Handler) error {
|
|
// Make sure we are reading a v2 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
|
|
default:
|
|
return fmt.Errorf("cannot convert config version %s to %s", cfgVersion.Version, config.Version4)
|
|
}
|
|
}
|