mirror of
https://github.com/zitadel/zitadel.git
synced 2025-01-09 20:33:40 +00:00
move defaults.yaml back to cmd pkg
This commit is contained in:
parent
53a3ba8acf
commit
f9176fef04
@ -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()
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
package options
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
)
|
||||
|
||||
//go:embed defaults.yaml
|
||||
var defaultConfig []byte
|
@ -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")
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user