move defaults.yaml back to cmd pkg

This commit is contained in:
Elio Bischof 2022-07-27 09:42:18 +02:00
parent 53a3ba8acf
commit f9176fef04
No known key found for this signature in database
GPG Key ID: 7B383FDE4DDBF1BD
5 changed files with 24 additions and 44 deletions

View File

@ -6,16 +6,17 @@ import (
_ "embed" _ "embed"
"flag" "flag"
"fmt" "fmt"
"strings"
"time" "time"
"github.com/zitadel/zitadel/cmd"
cryptoDB "github.com/zitadel/zitadel/internal/crypto/database" cryptoDB "github.com/zitadel/zitadel/internal/crypto/database"
"github.com/zitadel/zitadel/internal/id" "github.com/zitadel/zitadel/internal/id"
"github.com/spf13/viper" "github.com/spf13/viper"
"github.com/zitadel/zitadel/internal/config/options"
"github.com/zitadel/zitadel/internal/command" "github.com/zitadel/zitadel/internal/command"
"github.com/zitadel/zitadel/internal/database" "github.com/zitadel/zitadel/internal/database"
"github.com/zitadel/zitadel/internal/eventstore" "github.com/zitadel/zitadel/internal/eventstore"
@ -41,7 +42,11 @@ func main() {
masterkey := flag.String("materkey", "MasterkeyNeedsToHave32Characters", "the ZITADEL installations masterkey") masterkey := flag.String("materkey", "MasterkeyNeedsToHave32Characters", "the ZITADEL installations masterkey")
debug := flag.Bool("debug", false, "print information that is helpful for debugging") 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) logging.OnError(err).Fatalf("unable to initialize zitadel config: %s", err)
flag.Parse() flag.Parse()

View File

@ -1,11 +1,13 @@
package cmd package cmd
import ( import (
"bytes"
_ "embed" _ "embed"
"errors" "errors"
"io" "io"
"strings"
"github.com/zitadel/zitadel/internal/config/options" "github.com/spf13/viper"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/zitadel/logging" "github.com/zitadel/logging"
@ -18,6 +20,9 @@ import (
) )
var ( var (
//go:embed defaults.yaml
DefaultConfig []byte
configFiles []string 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) logging.OnError(err).Fatalf("unable initialize config: %s", err)
cobra.OnInitialize(initConfig) cobra.OnInitialize(initConfig)
@ -50,5 +59,9 @@ func New(out io.Writer, in io.Reader, args []string) *cobra.Command {
} }
func initConfig() { 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")
}
} }

View File

@ -1,8 +0,0 @@
package options
import (
_ "embed"
)
//go:embed defaults.yaml
var defaultConfig []byte

View File

@ -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")
}
}