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
|
|
|
|
2024-01-25 16:28:20 +00:00
|
|
|
"github.com/zitadel/zitadel/cmd/encryption"
|
2024-02-16 16:04:42 +00:00
|
|
|
"github.com/zitadel/zitadel/cmd/hooks"
|
2024-01-25 16:28:20 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/actions"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
2024-01-25 16:28:20 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/oidc"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/ui/login"
|
2022-04-26 23:01:45 +00:00
|
|
|
"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/database"
|
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"
|
2024-01-25 16:28:20 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/notification/handlers"
|
2022-11-04 09:21:58 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/query/projection"
|
2024-01-25 16:28:20 +00:00
|
|
|
static_config "github.com/zitadel/zitadel/internal/static/config"
|
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
|
2024-01-25 16:28:20 +00:00
|
|
|
EncryptionKeys *encryption.EncryptionKeyConfig
|
2022-04-21 10:37:39 +00:00
|
|
|
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
|
2024-01-25 16:28:20 +00:00
|
|
|
|
|
|
|
InitProjections InitProjections
|
|
|
|
AssetStorage static_config.AssetStorageConfig
|
|
|
|
OIDC oidc.Config
|
|
|
|
Login login.Config
|
|
|
|
WebAuthNName string
|
|
|
|
Telemetry *handlers.TelemetryPusherConfig
|
2024-02-16 16:04:42 +00:00
|
|
|
SystemAPIUsers map[string]*authz.SystemAPIUser
|
2024-01-25 16:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type InitProjections struct {
|
|
|
|
Enabled bool
|
|
|
|
RetryFailedAfter time.Duration
|
|
|
|
MaxFailureCount uint8
|
|
|
|
BulkLimit uint64
|
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(authz.MemberTypeString),
|
2024-01-25 16:28:20 +00:00
|
|
|
actions.HTTPConfigDecodeHook,
|
2024-02-16 16:04:42 +00:00
|
|
|
hooks.MapTypeStringDecode[string, *authz.SystemAPIUser],
|
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
|
2023-12-31 14:30:25 +00:00
|
|
|
s19AddCurrentStatesIndex *AddCurrentSequencesIndex
|
2024-01-09 18:36:46 +00:00
|
|
|
s20AddByUserSessionIndex *AddByUserIndexToSession
|
2024-01-17 10:16:48 +00:00
|
|
|
s21AddBlockFieldToLimits *AddBlockFieldToLimits
|
2024-01-25 16:28:20 +00:00
|
|
|
s22ActiveInstancesIndex *ActiveInstanceEvents
|
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
|
|
|
}
|