config: allow setting directory sync interval and timeout (#1098)

Updates #567
This commit is contained in:
Cuong Manh Le 2020-07-17 23:11:27 +07:00 committed by GitHub
parent 25867501d4
commit 821f2e9000
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 4 deletions

View file

@ -4,12 +4,14 @@ import "time"
var (
defaultGroupRefreshInterval = 10 * time.Minute
defaultGroupRefreshTimeout = 1 * time.Minute
defaultSessionRefreshGracePeriod = 1 * time.Minute
defaultSessionRefreshCoolOffDuration = 10 * time.Second
)
type config struct {
groupRefreshInterval time.Duration
groupRefreshTimeout time.Duration
sessionRefreshGracePeriod time.Duration
sessionRefreshCoolOffDuration time.Duration
}
@ -17,6 +19,7 @@ type config struct {
func newConfig(options ...Option) *config {
cfg := new(config)
WithGroupRefreshInterval(defaultGroupRefreshInterval)(cfg)
WithGroupRefreshTimeout(defaultGroupRefreshTimeout)(cfg)
WithSessionRefreshGracePeriod(defaultSessionRefreshGracePeriod)(cfg)
WithSessionRefreshCoolOffDuration(defaultSessionRefreshCoolOffDuration)(cfg)
for _, option := range options {
@ -35,6 +38,13 @@ func WithGroupRefreshInterval(interval time.Duration) Option {
}
}
// WithGroupRefreshTimeout sets the group refresh timeout used by the manager.
func WithGroupRefreshTimeout(timeout time.Duration) Option {
return func(cfg *config) {
cfg.groupRefreshTimeout = timeout
}
}
// WithSessionRefreshGracePeriod sets the session refresh grace period used by the manager.
func WithSessionRefreshGracePeriod(dur time.Duration) Option {
return func(cfg *config) {

View file

@ -188,7 +188,7 @@ func (mgr *Manager) refreshLoop(
func (mgr *Manager) refreshDirectoryUsers(ctx context.Context) {
mgr.log.Info().Msg("refreshing directory users")
ctx, clearTimeout := context.WithTimeout(ctx, time.Minute)
ctx, clearTimeout := context.WithTimeout(ctx, mgr.cfg.groupRefreshTimeout)
defer clearTimeout()
directoryUsers, err := mgr.directory.UserGroups(ctx)