2022-03-23 08:02:39 +00:00
|
|
|
package setup
|
|
|
|
|
|
|
|
import (
|
2022-03-28 08:05:09 +00:00
|
|
|
"bytes"
|
2022-06-10 13:34:52 +00:00
|
|
|
"strings"
|
2022-03-28 08:05:09 +00:00
|
|
|
|
|
|
|
"github.com/mitchellh/mapstructure"
|
|
|
|
"github.com/spf13/viper"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/logging"
|
2022-03-28 08:05:09 +00:00
|
|
|
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
|
|
"github.com/zitadel/zitadel/internal/command"
|
|
|
|
"github.com/zitadel/zitadel/internal/config/hook"
|
|
|
|
"github.com/zitadel/zitadel/internal/config/systemdefaults"
|
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
|
|
"github.com/zitadel/zitadel/internal/database"
|
2022-09-01 07:24:26 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/id"
|
2022-03-23 08:02:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2022-04-21 10:37:39 +00:00
|
|
|
Database database.Config
|
|
|
|
SystemDefaults systemdefaults.SystemDefaults
|
|
|
|
InternalAuthZ authz.Config
|
2022-04-28 08:30:41 +00:00
|
|
|
ExternalDomain string
|
2022-04-21 10:37:39 +00:00
|
|
|
ExternalPort uint16
|
|
|
|
ExternalSecure bool
|
|
|
|
Log *logging.Config
|
|
|
|
EncryptionKeys *encryptionKeyConfig
|
|
|
|
DefaultInstance command.InstanceSetup
|
2022-09-01 07:24:26 +00:00
|
|
|
Machine *id.Config
|
2022-03-28 08:05:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func MustNewConfig(v *viper.Viper) *Config {
|
|
|
|
config := new(Config)
|
2022-04-21 10:37:39 +00:00
|
|
|
err := v.Unmarshal(config,
|
|
|
|
viper.DecodeHook(mapstructure.ComposeDecodeHookFunc(
|
|
|
|
hook.Base64ToBytesHookFunc(),
|
|
|
|
hook.TagToLanguageHookFunc(),
|
|
|
|
mapstructure.StringToTimeDurationHookFunc(),
|
|
|
|
mapstructure.StringToSliceHookFunc(","),
|
2022-07-28 14:25:42 +00:00
|
|
|
database.DecodeHook,
|
2022-04-21 10:37:39 +00:00
|
|
|
)),
|
|
|
|
)
|
2022-04-25 15:05:20 +00:00
|
|
|
logging.OnError(err).Fatal("unable to read default config")
|
2022-03-28 08:05:09 +00:00
|
|
|
|
|
|
|
err = config.Log.SetLogger()
|
|
|
|
logging.OnError(err).Fatal("unable to set logger")
|
|
|
|
|
2022-09-01 07:24:26 +00:00
|
|
|
id.Configure(config.Machine)
|
|
|
|
|
2022-03-28 08:05:09 +00:00
|
|
|
return config
|
2022-03-23 08:02:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Steps struct {
|
2022-09-02 14:05:13 +00:00
|
|
|
s1ProjectionTable *ProjectionTable
|
|
|
|
s2AssetsTable *AssetTable
|
|
|
|
FirstInstance *FirstInstance
|
|
|
|
s4EventstoreIndexes *EventstoreIndexes
|
2022-03-28 08:05:09 +00:00
|
|
|
}
|
|
|
|
|
2022-04-12 14:20:17 +00:00
|
|
|
type encryptionKeyConfig struct {
|
|
|
|
User *crypto.KeyConfig
|
2022-05-13 12:13:07 +00:00
|
|
|
SMTP *crypto.KeyConfig
|
2022-04-12 14:20:17 +00:00
|
|
|
}
|
|
|
|
|
2022-03-28 08:05:09 +00:00
|
|
|
func MustNewSteps(v *viper.Viper) *Steps {
|
2022-06-27 10:32:34 +00:00
|
|
|
v.AutomaticEnv()
|
|
|
|
v.SetEnvPrefix("ZITADEL")
|
|
|
|
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
2022-03-28 08:05:09 +00:00
|
|
|
v.SetConfigType("yaml")
|
|
|
|
err := v.ReadConfig(bytes.NewBuffer(defaultSteps))
|
|
|
|
logging.OnError(err).Fatal("unable to read setup steps")
|
|
|
|
|
2022-04-25 15:05:20 +00:00
|
|
|
for _, file := range stepFiles {
|
|
|
|
v.SetConfigFile(file)
|
|
|
|
err := v.MergeInConfig()
|
|
|
|
logging.WithFields("file", file).OnError(err).Warn("unable to read setup file")
|
|
|
|
}
|
|
|
|
|
2022-03-28 08:05:09 +00:00
|
|
|
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
|
|
|
}
|