mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:07:30 +00:00
fix(cli): overwrite setups (#3488)
* fix(cli): possibility to overwrite setup steps * chore: update cockroach version in go-dep * fix(cli): init masterkey flags once Co-authored-by: Livio Amstutz <livio.a@gmail.com>
This commit is contained in:
@@ -21,9 +21,9 @@ RUN apt install openssl tzdata tar
|
|||||||
|
|
||||||
# cockroach binary used to backup database
|
# cockroach binary used to backup database
|
||||||
RUN mkdir /usr/local/lib/cockroach
|
RUN mkdir /usr/local/lib/cockroach
|
||||||
RUN wget -qO- https://binaries.cockroachdb.com/cockroach-v21.2.5.linux-amd64.tgz \
|
RUN wget -qO- https://binaries.cockroachdb.com/cockroach-v21.2.9.linux-amd64.tgz \
|
||||||
| tar xvz && cp -i cockroach-v21.2.5.linux-amd64/cockroach /usr/local/bin/
|
| tar xvz && cp -i cockroach-v21.2.9.linux-amd64/cockroach /usr/local/bin/
|
||||||
RUN rm -r cockroach-v21.2.5.linux-amd64
|
RUN rm -r cockroach-v21.2.9.linux-amd64
|
||||||
|
|
||||||
#######################
|
#######################
|
||||||
## generates static files
|
## generates static files
|
||||||
|
@@ -21,6 +21,9 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func AddMasterKeyFlag(cmd *cobra.Command) {
|
func AddMasterKeyFlag(cmd *cobra.Command) {
|
||||||
|
if cmd.PersistentFlags().Lookup(flagMasterKey) != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
cmd.PersistentFlags().StringP(flagMasterKey, flagMasterKeyShort, "", "path to the masterkey for en/decryption keys")
|
cmd.PersistentFlags().StringP(flagMasterKey, flagMasterKeyShort, "", "path to the masterkey for en/decryption keys")
|
||||||
cmd.PersistentFlags().String(flagMasterKeyArg, "", "masterkey as argument for en/decryption keys")
|
cmd.PersistentFlags().String(flagMasterKeyArg, "", "masterkey as argument for en/decryption keys")
|
||||||
cmd.PersistentFlags().Bool(flagMasterKeyEnv, false, "read masterkey for en/decryption keys from environment variable (ZITADEL_MASTERKEY)")
|
cmd.PersistentFlags().Bool(flagMasterKeyEnv, false, "read masterkey for en/decryption keys from environment variable (ZITADEL_MASTERKEY)")
|
||||||
|
@@ -36,6 +36,7 @@ func MustNewConfig(v *viper.Viper) *Config {
|
|||||||
mapstructure.StringToSliceHookFunc(","),
|
mapstructure.StringToSliceHookFunc(","),
|
||||||
)),
|
)),
|
||||||
)
|
)
|
||||||
|
logging.OnError(err).Fatal("unable to read default config")
|
||||||
|
|
||||||
err = config.Log.SetLogger()
|
err = config.Log.SetLogger()
|
||||||
logging.OnError(err).Fatal("unable to set logger")
|
logging.OnError(err).Fatal("unable to set logger")
|
||||||
@@ -58,6 +59,12 @@ func MustNewSteps(v *viper.Viper) *Steps {
|
|||||||
err := v.ReadConfig(bytes.NewBuffer(defaultSteps))
|
err := v.ReadConfig(bytes.NewBuffer(defaultSteps))
|
||||||
logging.OnError(err).Fatal("unable to read setup steps")
|
logging.OnError(err).Fatal("unable to read setup steps")
|
||||||
|
|
||||||
|
for _, file := range stepFiles {
|
||||||
|
v.SetConfigFile(file)
|
||||||
|
err := v.MergeInConfig()
|
||||||
|
logging.WithFields("file", file).OnError(err).Warn("unable to read setup file")
|
||||||
|
}
|
||||||
|
|
||||||
steps := new(Steps)
|
steps := new(Steps)
|
||||||
err = v.Unmarshal(steps,
|
err = v.Unmarshal(steps,
|
||||||
viper.DecodeHook(mapstructure.ComposeDecodeHookFunc(
|
viper.DecodeHook(mapstructure.ComposeDecodeHookFunc(
|
||||||
|
@@ -18,10 +18,11 @@ import (
|
|||||||
var (
|
var (
|
||||||
//go:embed steps.yaml
|
//go:embed steps.yaml
|
||||||
defaultSteps []byte
|
defaultSteps []byte
|
||||||
|
stepFiles []string
|
||||||
)
|
)
|
||||||
|
|
||||||
func New() *cobra.Command {
|
func New() *cobra.Command {
|
||||||
return &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "setup",
|
Use: "setup",
|
||||||
Short: "setup ZITADEL instance",
|
Short: "setup ZITADEL instance",
|
||||||
Long: `sets up data to start ZITADEL.
|
Long: `sets up data to start ZITADEL.
|
||||||
@@ -37,6 +38,15 @@ Requirements:
|
|||||||
Setup(config, steps, masterKey)
|
Setup(config, steps, masterKey)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Flags(cmd)
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func Flags(cmd *cobra.Command) {
|
||||||
|
cmd.PersistentFlags().StringArrayVar(&stepFiles, "steps", nil, "paths to step files to overwrite default steps")
|
||||||
|
key.AddMasterKeyFlag(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Setup(config *Config, steps *Steps, masterKey string) {
|
func Setup(config *Config, steps *Steps, masterKey string) {
|
||||||
@@ -79,3 +89,13 @@ func Setup(config *Config, steps *Steps, masterKey string) {
|
|||||||
err = migration.Migrate(ctx, eventstoreClient, steps.S3DefaultInstance)
|
err = migration.Migrate(ctx, eventstoreClient, steps.S3DefaultInstance)
|
||||||
logging.OnError(err).Fatal("unable to migrate step 4")
|
logging.OnError(err).Fatal("unable to migrate step 4")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initSteps(v *viper.Viper, files ...string) func() {
|
||||||
|
return func() {
|
||||||
|
for _, file := range files {
|
||||||
|
v.SetConfigFile(file)
|
||||||
|
err := v.MergeInConfig()
|
||||||
|
logging.WithFields("file", file).OnError(err).Warn("unable to read setup file")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -14,7 +14,6 @@ func startFlags(cmd *cobra.Command) {
|
|||||||
bindBoolFlag(cmd, "externalSecure", "if ZITADEL will be served on HTTPS")
|
bindBoolFlag(cmd, "externalSecure", "if ZITADEL will be served on HTTPS")
|
||||||
|
|
||||||
key.AddMasterKeyFlag(cmd)
|
key.AddMasterKeyFlag(cmd)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func bindStringFlag(cmd *cobra.Command, name, description string) {
|
func bindStringFlag(cmd *cobra.Command, name, description string) {
|
||||||
|
@@ -38,6 +38,7 @@ Requirements:
|
|||||||
}
|
}
|
||||||
|
|
||||||
startFlags(cmd)
|
startFlags(cmd)
|
||||||
|
setup.Flags(cmd)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -25,8 +26,8 @@ func New(out io.Writer, in io.Reader, args []string) *cobra.Command {
|
|||||||
Use: "zitadel",
|
Use: "zitadel",
|
||||||
Short: "The ZITADEL CLI let's you interact with ZITADEL",
|
Short: "The ZITADEL CLI let's you interact with ZITADEL",
|
||||||
Long: `The ZITADEL CLI let's you interact with ZITADEL`,
|
Long: `The ZITADEL CLI let's you interact with ZITADEL`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
logging.New().Info("hello world")
|
return errors.New("no additional command provided")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user