mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-30 15:00:51 +02:00
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:
parent
a518435c17
commit
99a5dbd65b
4 changed files with 190 additions and 4 deletions
|
@ -16,6 +16,7 @@ import (
|
|||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
"github.com/pomerium/pomerium/internal/atomicutil"
|
||||
"github.com/pomerium/pomerium/internal/enabler"
|
||||
"github.com/pomerium/pomerium/internal/events"
|
||||
"github.com/pomerium/pomerium/internal/identity/identity"
|
||||
"github.com/pomerium/pomerium/internal/log"
|
||||
|
@ -43,6 +44,7 @@ type (
|
|||
|
||||
// A Manager refreshes identity information using session and user data.
|
||||
type Manager struct {
|
||||
enabler.Enabler
|
||||
cfg *atomicutil.Value[*config]
|
||||
|
||||
sessionScheduler *scheduler.Scheduler
|
||||
|
@ -62,6 +64,7 @@ func New(
|
|||
sessionScheduler: scheduler.New(),
|
||||
userScheduler: scheduler.New(),
|
||||
}
|
||||
mgr.Enabler = enabler.New("identity_manager", mgr, true)
|
||||
mgr.reset()
|
||||
mgr.UpdateConfig(options...)
|
||||
return mgr
|
||||
|
@ -76,10 +79,15 @@ func withLog(ctx context.Context) context.Context {
|
|||
// UpdateConfig updates the manager with the new options.
|
||||
func (mgr *Manager) UpdateConfig(options ...Option) {
|
||||
mgr.cfg.Store(newConfig(options...))
|
||||
if mgr.cfg.Load().enabled {
|
||||
mgr.Enable()
|
||||
} else {
|
||||
mgr.Disable()
|
||||
}
|
||||
}
|
||||
|
||||
// Run runs the manager. This method blocks until an error occurs or the given context is canceled.
|
||||
func (mgr *Manager) Run(ctx context.Context) error {
|
||||
// RunEnabled runs the manager. This method blocks until an error occurs or the given context is canceled.
|
||||
func (mgr *Manager) RunEnabled(ctx context.Context) error {
|
||||
leaser := databroker.NewLeaser("identity_manager", time.Second*30, mgr)
|
||||
return leaser.Run(ctx)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue