diff --git a/internal/config/options/defaults.yaml b/cmd/defaults.yaml similarity index 100% rename from internal/config/options/defaults.yaml rename to cmd/defaults.yaml diff --git a/cmd/e2e-setup/main.go b/cmd/e2e-setup/main.go index 8bd368783c..052e325cd2 100644 --- a/cmd/e2e-setup/main.go +++ b/cmd/e2e-setup/main.go @@ -6,16 +6,17 @@ import ( _ "embed" "flag" "fmt" + "strings" "time" + "github.com/zitadel/zitadel/cmd" + cryptoDB "github.com/zitadel/zitadel/internal/crypto/database" "github.com/zitadel/zitadel/internal/id" "github.com/spf13/viper" - "github.com/zitadel/zitadel/internal/config/options" - "github.com/zitadel/zitadel/internal/command" "github.com/zitadel/zitadel/internal/database" "github.com/zitadel/zitadel/internal/eventstore" @@ -41,7 +42,11 @@ func main() { masterkey := flag.String("materkey", "MasterkeyNeedsToHave32Characters", "the ZITADEL installations masterkey") debug := flag.Bool("debug", false, "print information that is helpful for debugging") - err := options.InitViper() + viper.AutomaticEnv() + viper.SetEnvPrefix("ZITADEL") + viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) + viper.SetConfigType("yaml") + err := viper.ReadConfig(bytes.NewBuffer(cmd.DefaultConfig)) logging.OnError(err).Fatalf("unable to initialize zitadel config: %s", err) flag.Parse() diff --git a/cmd/zitadel.go b/cmd/zitadel.go index 285779a6f0..f3fa0a530b 100644 --- a/cmd/zitadel.go +++ b/cmd/zitadel.go @@ -1,11 +1,13 @@ package cmd import ( + "bytes" _ "embed" "errors" "io" + "strings" - "github.com/zitadel/zitadel/internal/config/options" + "github.com/spf13/viper" "github.com/spf13/cobra" "github.com/zitadel/logging" @@ -18,6 +20,9 @@ import ( ) var ( + //go:embed defaults.yaml + DefaultConfig []byte + configFiles []string ) @@ -31,7 +36,11 @@ func New(out io.Writer, in io.Reader, args []string) *cobra.Command { }, } - err := options.InitViper() + viper.AutomaticEnv() + viper.SetEnvPrefix("ZITADEL") + viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) + viper.SetConfigType("yaml") + err := viper.ReadConfig(bytes.NewBuffer(DefaultConfig)) logging.OnError(err).Fatalf("unable initialize config: %s", err) cobra.OnInitialize(initConfig) @@ -50,5 +59,9 @@ func New(out io.Writer, in io.Reader, args []string) *cobra.Command { } func initConfig() { - options.MergeToViper(configFiles...) + for _, file := range configFiles { + viper.SetConfigFile(file) + err := viper.MergeInConfig() + logging.WithFields("file", file).OnError(err).Warn("unable to read config file") + } } diff --git a/internal/config/options/defaults.go b/internal/config/options/defaults.go deleted file mode 100644 index 6867e241ad..0000000000 --- a/internal/config/options/defaults.go +++ /dev/null @@ -1,8 +0,0 @@ -package options - -import ( - _ "embed" -) - -//go:embed defaults.yaml -var defaultConfig []byte diff --git a/internal/config/options/viper.go b/internal/config/options/viper.go deleted file mode 100644 index 1d4c91f5bd..0000000000 --- a/internal/config/options/viper.go +++ /dev/null @@ -1,30 +0,0 @@ -package options - -import ( - "bytes" - "fmt" - "strings" - - "github.com/spf13/viper" - "github.com/zitadel/logging" -) - -func InitViper() error { - viper.AutomaticEnv() - viper.SetEnvPrefix("ZITADEL") - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.SetConfigType("yaml") - err := viper.ReadConfig(bytes.NewBuffer(defaultConfig)) - if err != nil { - return fmt.Errorf("unable to read default config: %w", err) - } - return nil -} - -func MergeToViper(configFiles ...string) { - for _, file := range configFiles { - viper.SetConfigFile(file) - err := viper.MergeInConfig() - logging.WithFields("file", file).OnError(err).Warn("unable to read config file") - } -}