diff --git a/app.go b/app.go index 48e19e9..f1dbc37 100644 --- a/app.go +++ b/app.go @@ -11,11 +11,6 @@ import ( "k8s.io/utils/clock" ) -type Source interface { - GetUsers() ([]SourceUser, error) - GetGroupsWithMembers() ([]SourceGroupWithMembers, error) -} - type App struct { syncInterval *time.Duration usernameReplaces []ReplacementPair diff --git a/azure_fake.go b/azure_fake.go index 937261c..9986bde 100644 --- a/azure_fake.go +++ b/azure_fake.go @@ -17,6 +17,10 @@ func (a *AzureFake) setGroups(groups []SourceGroupWithMembers) { a.groups = groups } +func (a *AzureFake) GetSourceType() SourceType { + return AzureSourceType +} + func (a *AzureFake) GetUsers() ([]SourceUser, error) { return a.users, nil } diff --git a/azure_real.go b/azure_real.go index 5ecf5a4..d25976d 100644 --- a/azure_real.go +++ b/azure_real.go @@ -98,6 +98,10 @@ func handleNil[T any](s *T) T { return result } +func (a *AzureReal) GetSourceType() SourceType { + return AzureSourceType +} + func (a *AzureReal) GetUsers() ([]SourceUser, error) { ctx, cancel := context.WithTimeout(context.Background(), a.timeout) defer cancel() diff --git a/diff.go b/diff.go index 6d401fc..e39b87f 100644 --- a/diff.go +++ b/diff.go @@ -45,7 +45,7 @@ func (a *App) syncUsers() (map[ObjectID]YtsaurusUser, error) { } } - ytUsers, err := a.ytsaurus.GetUsers() + ytUsers, err := a.ytsaurus.GetUsers(a.source.GetSourceType()) if err != nil { return nil, errors.Wrap(err, "failed to get YTsaurus users") } @@ -118,7 +118,7 @@ func (a *App) syncGroups(usersMap map[ObjectID]YtsaurusUser) error { if err != nil { return errors.Wrap(err, "failed to get Source groups") } - ytGroups, err := a.ytsaurus.GetGroupsWithMembers() + ytGroups, err := a.ytsaurus.GetGroupsWithMembers(a.source.GetSourceType()) if err != nil { return errors.Wrap(err, "failed to get YTsaurus groups") } diff --git a/ldap.go b/ldap.go index f9984c9..a715eeb 100644 --- a/ldap.go +++ b/ldap.go @@ -33,6 +33,10 @@ func NewLdap(cfg *LdapConfig, logger appLoggerType) (*Ldap, error) { }, nil } +func (source *Ldap) GetSourceType() SourceType { + return LdapSourceType +} + func (source *Ldap) GetUsers() ([]SourceUser, error) { res, err := source.Connection.Search(&ldap.SearchRequest{ BaseDN: source.Config.BaseDN, diff --git a/source_models.go b/source.go similarity index 96% rename from source_models.go rename to source.go index e957fd3..c50ffb1 100644 --- a/source_models.go +++ b/source.go @@ -14,6 +14,12 @@ const ( AzureSourceType SourceType = "azure" ) +type Source interface { + GetUsers() ([]SourceUser, error) + GetGroupsWithMembers() ([]SourceGroupWithMembers, error) + GetSourceType() SourceType +} + type SourceUser interface { GetID() ObjectID GetName() string