core/identity: add enabler (#5084)

* core/identity: add disabler

* enable by default

* add name

* rename to enabler, use mutex instead of goroutine

* rename method, add comments
This commit is contained in:
Caleb Doxsey 2024-04-26 15:05:22 -06:00 committed by GitHub
parent a518435c17
commit 99a5dbd65b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 190 additions and 4 deletions

View file

@ -19,6 +19,7 @@ type config struct {
sessionRefreshCoolOffDuration time.Duration
now func() time.Time
eventMgr *events.Manager
enabled bool
}
func newConfig(options ...Option) *config {
@ -26,6 +27,7 @@ func newConfig(options ...Option) *config {
WithSessionRefreshGracePeriod(defaultSessionRefreshGracePeriod)(cfg)
WithSessionRefreshCoolOffDuration(defaultSessionRefreshCoolOffDuration)(cfg)
WithNow(time.Now)(cfg)
WithEnabled(true)(cfg)
for _, option := range options {
option(cfg)
}
@ -72,7 +74,14 @@ func WithNow(now func() time.Time) Option {
// WithEventManager passes an event manager to record events
func WithEventManager(mgr *events.Manager) Option {
return func(c *config) {
c.eventMgr = mgr
return func(cfg *config) {
cfg.eventMgr = mgr
}
}
// WithEnabled sets the enabled option in the config.
func WithEnabled(enabled bool) Option {
return func(cfg *config) {
cfg.enabled = enabled
}
}