Skip to content

Commit

Permalink
Refactoring for adding other sources (#4)
Browse files Browse the repository at this point in the history
* Introduce sync from ldap

* Update go.mod and go.sum

* Linter fixes

* Add LdapConfigTest

* Ignore users from different source

* Fix build

* Fix test

* Add source_type attribute

* Review fixes

* Refactoring only, without ldap related changes

* Add default value for source_attribute_name

* Rename source.go -> source_models.go

* Remove commented code

* Fix build

* Review fixes

* Fix golangci

* Add buildYtsaurusGroup helper

* Review fixes

* Review fixes

* Fix test

* Remove unused map
  • Loading branch information
savnadya authored Mar 14, 2024
1 parent 96ee8c8 commit bfab770
Show file tree
Hide file tree
Showing 20 changed files with 705 additions and 487 deletions.
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
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ linters-settings:
gofmt:
simplify: false # gofmt with `-s` option, true by default

goimports:
local-prefixes: go.ytsaurus.tech

goconst:
# minimal length of string constant, 3 by default
min-len: 3
Expand Down
30 changes: 20 additions & 10 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ import (
"syscall"
"time"

"github.com/pkg/errors"

"k8s.io/utils/clock"
)

type Azure interface {
GetUsers() ([]AzureUser, error)
GetGroupsWithMembers() ([]AzureGroupWithMembers, error)
type ObjectID = string

type Source interface {
GetUsers() ([]SourceUser, error)
GetGroupsWithMembers() ([]SourceGroupWithMembers, error)
CreateUserFromRaw(raw map[string]any) (SourceUser, error)
CreateGroupFromRaw(raw map[string]any) (SourceGroup, error)
}

type App struct {
Expand All @@ -22,25 +28,29 @@ 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 cfg.Azure == nil {
return nil, errors.New("one and only one source should be specified")
}

source, err := NewAzureReal(cfg.Azure, 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 +66,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 +93,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

0 comments on commit bfab770

Please sign in to comment.