2022-03-23 08:02:39 +00:00
|
|
|
package setup
|
|
|
|
|
|
|
|
import (
|
2022-03-28 08:05:09 +00:00
|
|
|
"bytes"
|
|
|
|
|
|
|
|
"github.com/caos/logging"
|
|
|
|
"github.com/mitchellh/mapstructure"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
|
|
|
"github.com/caos/zitadel/internal/api/authz"
|
|
|
|
"github.com/caos/zitadel/internal/config/hook"
|
|
|
|
"github.com/caos/zitadel/internal/config/systemdefaults"
|
2022-03-23 08:02:39 +00:00
|
|
|
"github.com/caos/zitadel/internal/database"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2022-03-28 08:05:09 +00:00
|
|
|
Database database.Config
|
|
|
|
SystemDefaults systemdefaults.SystemDefaults
|
|
|
|
InternalAuthZ authz.Config
|
|
|
|
ExternalPort uint16
|
|
|
|
ExternalDomain string
|
|
|
|
ExternalSecure bool
|
|
|
|
Log *logging.Config
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2022-03-23 08:02:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Steps struct {
|
|
|
|
S1ProjectionTable *ProjectionTable
|
2022-03-28 08:05:09 +00:00
|
|
|
S2DefaultInstance *DefaultInstance
|
|
|
|
}
|
|
|
|
|
|
|
|
func MustNewSteps(v *viper.Viper) *Steps {
|
|
|
|
v.SetConfigType("yaml")
|
|
|
|
err := v.ReadConfig(bytes.NewBuffer(defaultSteps))
|
|
|
|
logging.OnError(err).Fatal("unable to read setup steps")
|
|
|
|
|
|
|
|
steps := new(Steps)
|
|
|
|
err = v.Unmarshal(steps,
|
|
|
|
viper.DecodeHook(mapstructure.ComposeDecodeHookFunc(
|
|
|
|
hook.Base64ToBytesHookFunc(),
|
|
|
|
hook.TagToLanguageHookFunc(),
|
|
|
|
mapstructure.StringToTimeDurationHookFunc(),
|
|
|
|
mapstructure.StringToSliceHookFunc(","),
|
|
|
|
)),
|
|
|
|
)
|
|
|
|
logging.OnError(err).Fatal("unable to read steps")
|
|
|
|
return steps
|
2022-03-23 08:02:39 +00:00
|
|
|
}
|