Skip to content

Commit

Permalink
Introduce sync from ldap
Browse files Browse the repository at this point in the history
  • Loading branch information
savnadya committed Feb 22, 2024
1 parent 96ee8c8 commit b775be6
Show file tree
Hide file tree
Showing 22 changed files with 1,315 additions and 653 deletions.
50 changes: 33 additions & 17 deletions app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"github.com/pkg/errors"
"os"
"os/signal"
"syscall"
Expand All @@ -9,38 +10,53 @@ import (
"k8s.io/utils/clock"
)

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

type App struct {
syncInterval time.Duration
syncInterval *time.Duration
usernameReplaces []ReplacementPair
groupnameReplaces []ReplacementPair
removeLimit int
banDuration time.Duration
removeLimit *int
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("no source (source or ldap) is 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 +72,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 @@ -66,8 +82,8 @@ func NewAppCustomized(cfg *Config, logger appLoggerType, azure Azure, clock cloc

func (a *App) Start() {
a.logger.Info("Starting the application")
if a.syncInterval > 0 {
ticker := time.NewTicker(a.syncInterval)
if a.syncInterval != nil && *a.syncInterval > 0 {
ticker := time.NewTicker(*a.syncInterval)
for {
select {
case <-a.stopCh:
Expand All @@ -83,7 +99,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
2 changes: 1 addition & 1 deletion app_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const (
runLocalYtsaurus = false
)

// TestAppIntegration checks sync with real Azure API and local yt
// TestAppIntegration checks sync with real Source API and local yt
// It requires AZURE_CLIENT_SECRET to be set.
func TestAppIntegration(t *testing.T) {
require.NoError(t, os.Setenv(defaultYtsaurusSecretEnvVar, ytDevToken))
Expand Down
Loading

0 comments on commit b775be6

Please sign in to comment.