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-12-09 13:04:33 +00:00
|
|
|
"time"
|
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-11-04 09:21:58 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/query/projection"
|
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-11-04 09:21:58 +00:00
|
|
|
Projections projection.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(),
|
2022-12-09 13:04:33 +00:00
|
|
|
mapstructure.StringToTimeHookFunc(time.RFC3339),
|
2022-04-21 10:37:39 +00:00
|
|
|
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-11-30 16:01:17 +00:00
|
|
|
s1ProjectionTable *ProjectionTable
|
|
|
|
s2AssetsTable *AssetTable
|
|
|
|
FirstInstance *FirstInstance
|
|
|
|
s4EventstoreIndexes *EventstoreIndexes
|
|
|
|
s5LastFailed *LastFailed
|
|
|
|
s6OwnerRemoveColumns *OwnerRemoveColumns
|
2023-02-15 01:52:11 +00:00
|
|
|
s7LogstoreTables *LogstoreTables
|
2023-02-21 14:46:47 +00:00
|
|
|
s8AuthTokens *AuthTokenIndexes
|
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(),
|
2022-12-09 13:04:33 +00:00
|
|
|
mapstructure.StringToTimeHookFunc(time.RFC3339),
|
2022-03-28 08:05:09 +00:00
|
|
|
mapstructure.StringToSliceHookFunc(","),
|
|
|
|
)),
|
|
|
|
)
|
|
|
|
logging.OnError(err).Fatal("unable to read steps")
|
|
|
|
return steps
|
2022-03-23 08:02:39 +00:00
|
|
|
}
|