Skip to content

Commit

Permalink
feat: password migration hook
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl committed Jul 1, 2024
1 parent 7df3d56 commit 4182bec
Show file tree
Hide file tree
Showing 8 changed files with 542 additions and 470 deletions.
21 changes: 17 additions & 4 deletions driver/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ const (
ViperKeyClientHTTPPrivateIPExceptionURLs = "clients.http.private_ip_exception_urls"
ViperKeyPreviewDefaultReadConsistencyLevel = "preview.default_read_consistency_level"
ViperKeyVersion = "version"
ViperKeyPasswordMigrationHook = "selfservice.flows.login.password_migration"
)

const (
Expand Down Expand Up @@ -290,6 +291,10 @@ type (
Headers map[string]string `json:"headers" koanf:"headers"`
LocalName string `json:"local_name" koanf:"local_name"`
}
PasswordMigrationHook struct {
Enabled bool `json:"enabled"`
Config json.RawMessage `json:"config"`
}
Config struct {
l *logrusx.Logger
p *configx.Provider
Expand Down Expand Up @@ -518,13 +523,13 @@ func (p *Config) cors(ctx context.Context, prefix string) (cors.Options, bool) {
})
}

// Deprecatd: use context-based WithConfigValue instead
func (p *Config) Set(ctx context.Context, key string, value interface{}) error {
// Deprecated: use context-based confighelpers.WithConfigValue instead
func (p *Config) Set(_ context.Context, key string, value interface{}) error {
return p.p.Set(key, value)
}

// Deprecated: use context-based WithConfigValue instead
func (p *Config) MustSet(ctx context.Context, key string, value interface{}) {
// Deprecated: use context-based confighelpers.WithConfigValue instead
func (p *Config) MustSet(_ context.Context, key string, value interface{}) {
if err := p.p.Set(key, value); err != nil {
p.l.WithError(err).Fatalf("Unable to set \"%s\" to \"%s\".", key, value)
}
Expand Down Expand Up @@ -1599,3 +1604,11 @@ func (p *Config) TokenizeTemplate(ctx context.Context, key string) (_ *SessionTo
func (p *Config) DefaultConsistencyLevel(ctx context.Context) crdbx.ConsistencyLevel {
return crdbx.ConsistencyLevelFromString(p.GetProvider(ctx).String(ViperKeyPreviewDefaultReadConsistencyLevel))
}

func (p *Config) PasswordMigrationHook(ctx context.Context) (hook *PasswordMigrationHook) {
hook = new(PasswordMigrationHook)
// Error is ignored on purpose, as we then default to a hook with `enabled = false`.
_ = p.GetProvider(ctx).Unmarshal(ViperKeyPasswordMigrationHook, hook)

return hook
}
Loading

0 comments on commit 4182bec

Please sign in to comment.