mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:37:32 +00:00
feat: prepare for multiple database types (#4068)
BREAKING CHANGE: the database and admin user config has changed.
This commit is contained in:
@@ -9,15 +9,16 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Database database.Config
|
||||
AdminUser database.User
|
||||
Machine *id.Config
|
||||
Log *logging.Config
|
||||
Database database.Config
|
||||
Machine *id.Config
|
||||
Log *logging.Config
|
||||
}
|
||||
|
||||
func MustNewConfig(v *viper.Viper) *Config {
|
||||
config := new(Config)
|
||||
err := v.Unmarshal(config)
|
||||
err := v.Unmarshal(config,
|
||||
viper.DecodeHook(database.DecodeHook),
|
||||
)
|
||||
logging.OnError(err).Fatal("unable to read config")
|
||||
|
||||
err = config.Log.SetLogger()
|
||||
@@ -25,21 +26,3 @@ func MustNewConfig(v *viper.Viper) *Config {
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
func adminConfig(config *Config) database.Config {
|
||||
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
|
||||
}
|
||||
|
@@ -39,10 +39,10 @@ The user provided by flags needs privileges to
|
||||
|
||||
func InitAll(config *Config) {
|
||||
id.Configure(config.Machine)
|
||||
err := initialise(config,
|
||||
VerifyUser(config.Database.Username, config.Database.Password),
|
||||
VerifyDatabase(config.Database.Database),
|
||||
VerifyGrant(config.Database.Database, config.Database.Username),
|
||||
err := initialise(config.Database,
|
||||
VerifyUser(config.Database.Username(), config.Database.Password()),
|
||||
VerifyDatabase(config.Database.Database()),
|
||||
VerifyGrant(config.Database.Database(), config.Database.Username()),
|
||||
)
|
||||
logging.OnError(err).Fatal("unable to initialize the database")
|
||||
|
||||
@@ -50,10 +50,10 @@ func InitAll(config *Config) {
|
||||
logging.OnError(err).Fatal("unable to initialize ZITADEL")
|
||||
}
|
||||
|
||||
func initialise(config *Config, steps ...func(*sql.DB) error) error {
|
||||
func initialise(config database.Config, steps ...func(*sql.DB) error) error {
|
||||
logging.Info("initialization started")
|
||||
|
||||
db, err := database.Connect(adminConfig(config))
|
||||
db, err := database.Connect(config, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ The user provided by flags needs priviledge to
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
config := MustNewConfig(viper.New())
|
||||
|
||||
err := initialise(config, VerifyDatabase(config.Database.Database))
|
||||
err := initialise(config.Database, VerifyDatabase(config.Database.Database()))
|
||||
logging.OnError(err).Fatal("unable to initialize the database")
|
||||
},
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ Prereqesits:
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
config := MustNewConfig(viper.New())
|
||||
|
||||
err := initialise(config, VerifyGrant(config.Database.Database, config.Database.Username))
|
||||
err := initialise(config.Database, VerifyGrant(config.Database.Database(), config.Database.Username()))
|
||||
logging.OnError(err).Fatal("unable to set grant")
|
||||
},
|
||||
}
|
||||
|
@@ -33,7 +33,7 @@ The user provided by flags needs priviledge to
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
config := MustNewConfig(viper.New())
|
||||
|
||||
err := initialise(config, VerifyUser(config.Database.Username, config.Database.Password))
|
||||
err := initialise(config.Database, VerifyUser(config.Database.Username(), config.Database.Password()))
|
||||
logging.OnError(err).Fatal("unable to init user")
|
||||
},
|
||||
}
|
||||
|
@@ -95,7 +95,7 @@ func VerifyZitadel(db *sql.DB) error {
|
||||
|
||||
func verifyZitadel(config database.Config) error {
|
||||
logging.WithFields("database", config.Database).Info("verify zitadel")
|
||||
db, err := database.Connect(config)
|
||||
db, err := database.Connect(config, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user