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

Refactoring for adding other sources #4

Merged
merged 21 commits into from
Mar 14, 2024
Merged
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
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
Loading