2022-03-23 09:02:39 +01:00
|
|
|
package setup
|
|
|
|
|
|
|
|
import (
|
2022-03-28 10:05:09 +02:00
|
|
|
"bytes"
|
2022-06-10 15:34:52 +02:00
|
|
|
"strings"
|
2022-12-09 13:04:33 +00:00
|
|
|
"time"
|
2022-03-28 10:05:09 +02:00
|
|
|
|
|
|
|
"github.com/mitchellh/mapstructure"
|
|
|
|
"github.com/spf13/viper"
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/logging"
|
2022-03-28 10:05:09 +02:00
|
|
|
|
2022-04-27 01:01:45 +02: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 09:24:26 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/id"
|
2022-11-04 10:21:58 +01:00
|
|
|
"github.com/zitadel/zitadel/internal/query/projection"
|
2022-03-23 09:02:39 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2022-04-21 12:37:39 +02:00
|
|
|
Database database.Config
|
|
|
|
SystemDefaults systemdefaults.SystemDefaults
|
|
|
|
InternalAuthZ authz.Config
|
2022-04-28 10:30:41 +02:00
|
|
|
ExternalDomain string
|
2022-04-21 12:37:39 +02:00
|
|
|
ExternalPort uint16
|
|
|
|
ExternalSecure bool
|
|
|
|
Log *logging.Config
|
|
|
|
EncryptionKeys *encryptionKeyConfig
|
|
|
|
DefaultInstance command.InstanceSetup
|
2022-09-01 09:24:26 +02:00
|
|
|
Machine *id.Config
|
2022-11-04 10:21:58 +01:00
|
|
|
Projections projection.Config
|
2022-03-28 10:05:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func MustNewConfig(v *viper.Viper) *Config {
|
|
|
|
config := new(Config)
|
2022-04-21 12:37:39 +02: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 12:37:39 +02:00
|
|
|
mapstructure.StringToSliceHookFunc(","),
|
2022-07-28 16:25:42 +02:00
|
|
|
database.DecodeHook,
|
2022-04-21 12:37:39 +02:00
|
|
|
)),
|
|
|
|
)
|
2022-04-25 17:05:20 +02:00
|
|
|
logging.OnError(err).Fatal("unable to read default config")
|
2022-03-28 10:05:09 +02:00
|
|
|
|
|
|
|
err = config.Log.SetLogger()
|
|
|
|
logging.OnError(err).Fatal("unable to set logger")
|
|
|
|
|
2022-09-01 09:24:26 +02:00
|
|
|
id.Configure(config.Machine)
|
|
|
|
|
2022-03-28 10:05:09 +02:00
|
|
|
return config
|
2022-03-23 09:02:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type Steps struct {
|
2023-04-18 19:29:04 +02:00
|
|
|
s1ProjectionTable *ProjectionTable
|
|
|
|
s2AssetsTable *AssetTable
|
|
|
|
FirstInstance *FirstInstance
|
|
|
|
s4EventstoreIndexes *EventstoreIndexesNew
|
|
|
|
s5LastFailed *LastFailed
|
|
|
|
s6OwnerRemoveColumns *OwnerRemoveColumns
|
|
|
|
s7LogstoreTables *LogstoreTables
|
|
|
|
s8AuthTokens *AuthTokenIndexes
|
|
|
|
s9EventstoreIndexes2 *EventstoreIndexesNew
|
|
|
|
s10EventstoreCreationDate *CorrectCreationDate
|
2022-03-28 10:05:09 +02:00
|
|
|
}
|
|
|
|
|
2022-04-12 16:20:17 +02:00
|
|
|
type encryptionKeyConfig struct {
|
|
|
|
User *crypto.KeyConfig
|
2022-05-13 14:13:07 +02:00
|
|
|
SMTP *crypto.KeyConfig
|
2022-04-12 16:20:17 +02:00
|
|
|
}
|
|
|
|
|
2022-03-28 10:05:09 +02:00
|
|
|
func MustNewSteps(v *viper.Viper) *Steps {
|
2022-06-27 12:32:34 +02:00
|
|
|
v.AutomaticEnv()
|
|
|
|
v.SetEnvPrefix("ZITADEL")
|
|
|
|
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
2022-03-28 10:05:09 +02:00
|
|
|
v.SetConfigType("yaml")
|
|
|
|
err := v.ReadConfig(bytes.NewBuffer(defaultSteps))
|
|
|
|
logging.OnError(err).Fatal("unable to read setup steps")
|
|
|
|
|
2022-04-25 17:05:20 +02: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 10:05:09 +02: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 10:05:09 +02:00
|
|
|
mapstructure.StringToSliceHookFunc(","),
|
|
|
|
)),
|
|
|
|
)
|
|
|
|
logging.OnError(err).Fatal("unable to read steps")
|
|
|
|
return steps
|
2022-03-23 09:02:39 +01:00
|
|
|
}
|