2022-02-11 10:02:47 +00:00
|
|
|
package initialise
|
|
|
|
|
2022-03-28 08:05:09 +00:00
|
|
|
import (
|
|
|
|
"github.com/spf13/viper"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/logging"
|
|
|
|
"github.com/zitadel/zitadel/internal/database"
|
2022-03-28 08:05:09 +00:00
|
|
|
)
|
2022-02-11 10:02:47 +00:00
|
|
|
|
|
|
|
type Config struct {
|
2022-02-16 12:30:49 +00:00
|
|
|
Database database.Config
|
|
|
|
AdminUser database.User
|
2022-03-28 08:05:09 +00:00
|
|
|
Log *logging.Config
|
2022-02-16 12:30:49 +00:00
|
|
|
}
|
|
|
|
|
2022-03-28 08:05:09 +00:00
|
|
|
func MustNewConfig(v *viper.Viper) *Config {
|
|
|
|
config := new(Config)
|
|
|
|
err := v.Unmarshal(config)
|
|
|
|
logging.OnError(err).Fatal("unable to read config")
|
|
|
|
|
|
|
|
err = config.Log.SetLogger()
|
|
|
|
logging.OnError(err).Fatal("unable to set logger")
|
|
|
|
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
|
|
|
func adminConfig(config *Config) database.Config {
|
2022-02-16 12:30:49 +00:00
|
|
|
adminConfig := config.Database
|
|
|
|
adminConfig.Username = config.AdminUser.Username
|
|
|
|
adminConfig.Password = config.AdminUser.Password
|
|
|
|
adminConfig.SSL.Cert = config.AdminUser.SSL.Cert
|
|
|
|
adminConfig.SSL.Key = config.AdminUser.SSL.Key
|
|
|
|
if config.AdminUser.SSL.RootCert != "" {
|
|
|
|
adminConfig.SSL.RootCert = config.AdminUser.SSL.RootCert
|
|
|
|
}
|
|
|
|
if config.AdminUser.SSL.Mode != "" {
|
|
|
|
adminConfig.SSL.Mode = config.AdminUser.SSL.Mode
|
|
|
|
}
|
|
|
|
//use default database because the zitadel database might not exist
|
|
|
|
adminConfig.Database = ""
|
|
|
|
|
|
|
|
return adminConfig
|
2022-02-11 10:02:47 +00:00
|
|
|
}
|