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"
|
2023-10-25 15:10:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2023-10-19 10:19:10 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
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
|
2023-10-19 10:19:10 +00:00
|
|
|
Eventstore *eventstore.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,
|
2023-10-25 15:10:45 +00:00
|
|
|
hook.EnumHookFunc(domain.FeatureString),
|
|
|
|
hook.EnumHookFunc(authz.MemberTypeString),
|
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 {
|
2023-12-01 12:25:41 +00:00
|
|
|
s1ProjectionTable *ProjectionTable
|
|
|
|
s2AssetsTable *AssetTable
|
|
|
|
FirstInstance *FirstInstance
|
|
|
|
s5LastFailed *LastFailed
|
|
|
|
s6OwnerRemoveColumns *OwnerRemoveColumns
|
|
|
|
s7LogstoreTables *LogstoreTables
|
|
|
|
s8AuthTokens *AuthTokenIndexes
|
|
|
|
CorrectCreationDate *CorrectCreationDate
|
|
|
|
s12AddOTPColumns *AddOTPColumns
|
|
|
|
s13FixQuotaProjection *FixQuotaConstraints
|
|
|
|
s14NewEventsTable *NewEventsTable
|
|
|
|
s15CurrentStates *CurrentProjectionState
|
|
|
|
s16UniqueConstraintsLower *UniqueConstraintToLower
|
|
|
|
s17AddOffsetToUniqueConstraints *AddOffsetToCurrentStates
|
2023-12-08 12:14:22 +00:00
|
|
|
s18AddLowerFieldsToLoginNames *AddLowerFieldsToLoginNames
|
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
|
2023-06-15 06:16:39 +00:00
|
|
|
OIDC *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(","),
|
2023-10-25 15:10:45 +00:00
|
|
|
hook.EnumHookFunc(domain.FeatureString),
|
2022-03-28 08:05:09 +00:00
|
|
|
)),
|
|
|
|
)
|
|
|
|
logging.OnError(err).Fatal("unable to read steps")
|
|
|
|
return steps
|
2022-03-23 08:02:39 +00:00
|
|
|
}
|