mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-31 01:47:33 +02:00
* core/identity: add data store for thread-safe storage of sessions and users * wip * add test * wip * clean up context * fix nil session error * add stop message * remove log * use origin context * use base context for manager calls * use manager context for syncers too * add runtime flag * rename legacy lease * add comment * use NotSame * add comment * Update internal/identity/manager/manager.go Co-authored-by: Kenneth Jenkins <51246568+kenjenkins@users.noreply.github.com> * lint --------- Co-authored-by: Kenneth Jenkins <51246568+kenjenkins@users.noreply.github.com>
97 lines
2.7 KiB
Go
97 lines
2.7 KiB
Go
package manager
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/pomerium/pomerium/internal/events"
|
|
"github.com/pomerium/pomerium/pkg/grpc/databroker"
|
|
)
|
|
|
|
var (
|
|
defaultSessionRefreshGracePeriod = 1 * time.Minute
|
|
defaultSessionRefreshCoolOffDuration = 10 * time.Second
|
|
defaultUpdateUserInfoInterval = 10 * time.Minute
|
|
)
|
|
|
|
type config struct {
|
|
authenticator Authenticator
|
|
dataBrokerClient databroker.DataBrokerServiceClient
|
|
sessionRefreshGracePeriod time.Duration
|
|
sessionRefreshCoolOffDuration time.Duration
|
|
updateUserInfoInterval time.Duration
|
|
now func() time.Time
|
|
eventMgr *events.Manager
|
|
enabled bool
|
|
}
|
|
|
|
func newConfig(options ...Option) *config {
|
|
cfg := new(config)
|
|
WithSessionRefreshGracePeriod(defaultSessionRefreshGracePeriod)(cfg)
|
|
WithSessionRefreshCoolOffDuration(defaultSessionRefreshCoolOffDuration)(cfg)
|
|
WithNow(time.Now)(cfg)
|
|
WithUpdateUserInfoInterval(defaultUpdateUserInfoInterval)(cfg)
|
|
WithEnabled(true)(cfg)
|
|
for _, option := range options {
|
|
option(cfg)
|
|
}
|
|
return cfg
|
|
}
|
|
|
|
// An Option customizes the configuration used for the identity manager.
|
|
type Option func(*config)
|
|
|
|
// WithAuthenticator sets the authenticator in the config.
|
|
func WithAuthenticator(authenticator Authenticator) Option {
|
|
return func(cfg *config) {
|
|
cfg.authenticator = authenticator
|
|
}
|
|
}
|
|
|
|
// WithDataBrokerClient sets the databroker client in the config.
|
|
func WithDataBrokerClient(dataBrokerClient databroker.DataBrokerServiceClient) Option {
|
|
return func(cfg *config) {
|
|
cfg.dataBrokerClient = dataBrokerClient
|
|
}
|
|
}
|
|
|
|
// WithSessionRefreshGracePeriod sets the session refresh grace period used by the manager.
|
|
func WithSessionRefreshGracePeriod(dur time.Duration) Option {
|
|
return func(cfg *config) {
|
|
cfg.sessionRefreshGracePeriod = dur
|
|
}
|
|
}
|
|
|
|
// WithSessionRefreshCoolOffDuration sets the session refresh cool-off duration used by the manager.
|
|
func WithSessionRefreshCoolOffDuration(dur time.Duration) Option {
|
|
return func(cfg *config) {
|
|
cfg.sessionRefreshCoolOffDuration = dur
|
|
}
|
|
}
|
|
|
|
// WithNow customizes the time.Now function used by the manager.
|
|
func WithNow(now func() time.Time) Option {
|
|
return func(cfg *config) {
|
|
cfg.now = now
|
|
}
|
|
}
|
|
|
|
// WithEventManager passes an event manager to record events
|
|
func WithEventManager(mgr *events.Manager) Option {
|
|
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
|
|
}
|
|
}
|
|
|
|
// WithUpdateUserInfoInterval sets the update user info interval in the config.
|
|
func WithUpdateUserInfoInterval(dur time.Duration) Option {
|
|
return func(cfg *config) {
|
|
cfg.updateUserInfoInterval = dur
|
|
}
|
|
}
|