Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce sync from ldap #2

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.local.yaml
specs
.idea
40 changes: 26 additions & 14 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ import (
"syscall"
"time"

"github.com/pkg/errors"

"k8s.io/utils/clock"
)

type Azure interface {
GetUsers() ([]AzureUser, error)
GetGroupsWithMembers() ([]AzureGroupWithMembers, error)
}

type App struct {
syncInterval time.Duration
usernameReplaces []ReplacementPair
Expand All @@ -22,25 +19,40 @@ type App struct {
banDuration time.Duration

ytsaurus *Ytsaurus
azure Azure
source Source

stopCh chan struct{}
sigCh chan os.Signal
logger appLoggerType
}

func NewApp(cfg *Config, logger appLoggerType) (*App, error) {
azure, err := NewAzureReal(cfg.Azure, logger)
if err != nil {
return nil, err
if (cfg.Azure == nil) == (cfg.Ldap == nil) {
return nil, errors.New("one and only one source should be specified")
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't support two sources at the same time, let's make it
(cfg.Azure == nil) != (cfg.Ldap == nil) with error like "one and only one source should be specified".


var err error
var source Source
if cfg.Azure != nil {
source, err = NewAzureReal(cfg.Azure, logger)
if err != nil {
return nil, err
}
}

if cfg.Ldap != nil {
source, err = NewLdap(cfg.Ldap, logger)
if err != nil {
return nil, err
}
}

return NewAppCustomized(cfg, logger, azure, clock.RealClock{})
return NewAppCustomized(cfg, logger, source, clock.RealClock{})
}

// NewAppCustomized used in tests.
func NewAppCustomized(cfg *Config, logger appLoggerType, azure Azure, clock clock.PassiveClock) (*App, error) {
yt, err := NewYtsaurus(cfg.Ytsaurus, logger, clock)
func NewAppCustomized(cfg *Config, logger appLoggerType, source Source, clock clock.PassiveClock) (*App, error) {
yt, err := NewYtsaurus(&cfg.Ytsaurus, logger, clock)
if err != nil {
return nil, err
}
Expand All @@ -56,7 +68,7 @@ func NewAppCustomized(cfg *Config, logger appLoggerType, azure Azure, clock cloc
banDuration: cfg.App.BanBeforeRemoveDuration,

ytsaurus: yt,
azure: azure,
source: source,

stopCh: make(chan struct{}),
sigCh: sigCh,
Expand All @@ -83,7 +95,7 @@ func (a *App) Start() {
}
} else {
a.logger.Info(
"app.sync_interval config variable is not greater than zero, " +
"app.sync_interval config variable is not specified or is not greater than zero, " +
"auto sync is disabled. Send SIGUSR1 for manual sync.",
)
for {
Expand Down
Loading
Loading