diff --git a/internal/sync/entity_comparision.go b/internal/engine/entity_comparision.go similarity index 98% rename from internal/sync/entity_comparision.go rename to internal/engine/entity_comparision.go index 04f017e..4aa2c7f 100644 --- a/internal/sync/entity_comparision.go +++ b/internal/engine/entity_comparision.go @@ -1,4 +1,4 @@ -package sync +package engine type Comparable interface { *GithubTeam | *GithubRepoComparable | *GithubRuleSet diff --git a/internal/sync/githubsaml.go b/internal/engine/githubsaml.go similarity index 99% rename from internal/sync/githubsaml.go rename to internal/engine/githubsaml.go index 01e8423..8985326 100644 --- a/internal/sync/githubsaml.go +++ b/internal/engine/githubsaml.go @@ -1,4 +1,4 @@ -package sync +package engine import ( "encoding/json" diff --git a/internal/sync/goliac_reconciliator.go b/internal/engine/goliac_reconciliator.go similarity index 99% rename from internal/sync/goliac_reconciliator.go rename to internal/engine/goliac_reconciliator.go index f254e01..86275fb 100644 --- a/internal/sync/goliac_reconciliator.go +++ b/internal/engine/goliac_reconciliator.go @@ -1,4 +1,4 @@ -package sync +package engine import ( "context" diff --git a/internal/sync/goliac_reconciliator_test.go b/internal/engine/goliac_reconciliator_test.go similarity index 99% rename from internal/sync/goliac_reconciliator_test.go rename to internal/engine/goliac_reconciliator_test.go index f488b83..823af4f 100644 --- a/internal/sync/goliac_reconciliator_test.go +++ b/internal/engine/goliac_reconciliator_test.go @@ -1,4 +1,4 @@ -package sync +package engine import ( "context" diff --git a/internal/sync/local.go b/internal/engine/local.go similarity index 99% rename from internal/sync/local.go rename to internal/engine/local.go index a71bff2..e23dbd8 100644 --- a/internal/sync/local.go +++ b/internal/engine/local.go @@ -1,4 +1,4 @@ -package sync +package engine import ( "errors" diff --git a/internal/sync/local_test.go b/internal/engine/local_test.go similarity index 99% rename from internal/sync/local_test.go rename to internal/engine/local_test.go index e8bb25c..d325491 100644 --- a/internal/sync/local_test.go +++ b/internal/engine/local_test.go @@ -1,4 +1,4 @@ -package sync +package engine import ( "fmt" diff --git a/internal/sync/mutable_remote.go b/internal/engine/mutable_remote.go similarity index 99% rename from internal/sync/mutable_remote.go rename to internal/engine/mutable_remote.go index 1fe08ee..119376b 100644 --- a/internal/sync/mutable_remote.go +++ b/internal/engine/mutable_remote.go @@ -1,4 +1,4 @@ -package sync +package engine import ( "github.com/Alayacare/goliac/internal/slugify" diff --git a/internal/sync/plugins.go b/internal/engine/plugins.go similarity index 97% rename from internal/sync/plugins.go rename to internal/engine/plugins.go index 5b3021a..2361b88 100644 --- a/internal/sync/plugins.go +++ b/internal/engine/plugins.go @@ -1,4 +1,4 @@ -package sync +package engine import ( "github.com/Alayacare/goliac/internal/config" diff --git a/internal/sync/reconciliator_executor.go b/internal/engine/reconciliator_executor.go similarity index 99% rename from internal/sync/reconciliator_executor.go rename to internal/engine/reconciliator_executor.go index 005c053..7fd9266 100644 --- a/internal/sync/reconciliator_executor.go +++ b/internal/engine/reconciliator_executor.go @@ -1,4 +1,4 @@ -package sync +package engine type ReconciliatorExecutor interface { AddUserToOrg(ghuserid string) diff --git a/internal/sync/remote.go b/internal/engine/remote.go similarity index 99% rename from internal/sync/remote.go rename to internal/engine/remote.go index 1effe32..dab77ca 100644 --- a/internal/sync/remote.go +++ b/internal/engine/remote.go @@ -1,4 +1,4 @@ -package sync +package engine import ( "encoding/json" diff --git a/internal/sync/remote_test.go b/internal/engine/remote_test.go similarity index 99% rename from internal/sync/remote_test.go rename to internal/engine/remote_test.go index 226055c..61d6c82 100644 --- a/internal/sync/remote_test.go +++ b/internal/engine/remote_test.go @@ -1,4 +1,4 @@ -package sync +package engine import ( "encoding/json" diff --git a/internal/github_batch_executor.go b/internal/github_batch_executor.go index cbd82f6..e89821a 100644 --- a/internal/github_batch_executor.go +++ b/internal/github_batch_executor.go @@ -1,7 +1,7 @@ package internal import ( - "github.com/Alayacare/goliac/internal/sync" + "github.com/Alayacare/goliac/internal/engine" "github.com/sirupsen/logrus" ) @@ -25,12 +25,12 @@ type GithubCommand interface { * gal.Commit() */ type GithubBatchExecutor struct { - client sync.ReconciliatorExecutor + client engine.ReconciliatorExecutor maxChangesets int commands []GithubCommand } -func NewGithubBatchExecutor(client sync.ReconciliatorExecutor, maxChangesets int) *GithubBatchExecutor { +func NewGithubBatchExecutor(client engine.ReconciliatorExecutor, maxChangesets int) *GithubBatchExecutor { gal := GithubBatchExecutor{ client: client, maxChangesets: maxChangesets, @@ -147,14 +147,14 @@ func (g *GithubBatchExecutor) DeleteRepository(reponame string) { }) } -func (g *GithubBatchExecutor) AddRuleset(ruleset *sync.GithubRuleSet) { +func (g *GithubBatchExecutor) AddRuleset(ruleset *engine.GithubRuleSet) { g.commands = append(g.commands, &GithubCommandAddRuletset{ client: g.client, ruleset: ruleset, }) } -func (g *GithubBatchExecutor) UpdateRuleset(ruleset *sync.GithubRuleSet) { +func (g *GithubBatchExecutor) UpdateRuleset(ruleset *engine.GithubRuleSet) { g.commands = append(g.commands, &GithubCommandUpdateRuletset{ client: g.client, ruleset: ruleset, @@ -186,7 +186,7 @@ func (g *GithubBatchExecutor) Commit() { } type GithubCommandAddUserToOrg struct { - client sync.ReconciliatorExecutor + client engine.ReconciliatorExecutor ghuserid string } @@ -195,7 +195,7 @@ func (g *GithubCommandAddUserToOrg) Apply() { } type GithubCommandCreateRepository struct { - client sync.ReconciliatorExecutor + client engine.ReconciliatorExecutor reponame string description string writers []string @@ -208,7 +208,7 @@ func (g *GithubCommandCreateRepository) Apply() { } type GithubCommandCreateTeam struct { - client sync.ReconciliatorExecutor + client engine.ReconciliatorExecutor teamname string description string members []string @@ -219,7 +219,7 @@ func (g *GithubCommandCreateTeam) Apply() { } type GithubCommandDeleteRepository struct { - client sync.ReconciliatorExecutor + client engine.ReconciliatorExecutor reponame string } @@ -228,7 +228,7 @@ func (g *GithubCommandDeleteRepository) Apply() { } type GithubCommandDeleteTeam struct { - client sync.ReconciliatorExecutor + client engine.ReconciliatorExecutor teamslug string } @@ -237,7 +237,7 @@ func (g *GithubCommandDeleteTeam) Apply() { } type GithubCommandRemoveUserFromOrg struct { - client sync.ReconciliatorExecutor + client engine.ReconciliatorExecutor ghuserid string } @@ -246,7 +246,7 @@ func (g *GithubCommandRemoveUserFromOrg) Apply() { } type GithubCommandUpdateRepositoryRemoveTeamAccess struct { - client sync.ReconciliatorExecutor + client engine.ReconciliatorExecutor reponame string teamslug string } @@ -256,7 +256,7 @@ func (g *GithubCommandUpdateRepositoryRemoveTeamAccess) Apply() { } type GithubCommandUpdateRepositoryAddTeamAccess struct { - client sync.ReconciliatorExecutor + client engine.ReconciliatorExecutor reponame string teamslug string permission string @@ -267,7 +267,7 @@ func (g *GithubCommandUpdateRepositoryAddTeamAccess) Apply() { } type GithubCommandUpdateRepositoryUpdateTeamAccess struct { - client sync.ReconciliatorExecutor + client engine.ReconciliatorExecutor reponame string teamslug string permission string @@ -278,7 +278,7 @@ func (g *GithubCommandUpdateRepositoryUpdateTeamAccess) Apply() { } type GithubCommandUpdateRepositoryUpdateArchived struct { - client sync.ReconciliatorExecutor + client engine.ReconciliatorExecutor reponame string archived bool } @@ -288,7 +288,7 @@ func (g *GithubCommandUpdateRepositoryUpdateArchived) Apply() { } type GithubCommandUpdateRepositoryUpdatePrivate struct { - client sync.ReconciliatorExecutor + client engine.ReconciliatorExecutor reponame string private bool } @@ -298,7 +298,7 @@ func (g *GithubCommandUpdateRepositoryUpdatePrivate) Apply() { } type GithubCommandUpdateTeamAddMember struct { - client sync.ReconciliatorExecutor + client engine.ReconciliatorExecutor teamslug string member string role string @@ -309,7 +309,7 @@ func (g *GithubCommandUpdateTeamAddMember) Apply() { } type GithubCommandUpdateTeamRemoveMember struct { - client sync.ReconciliatorExecutor + client engine.ReconciliatorExecutor teamslug string member string } @@ -319,8 +319,8 @@ func (g *GithubCommandUpdateTeamRemoveMember) Apply() { } type GithubCommandAddRuletset struct { - client sync.ReconciliatorExecutor - ruleset *sync.GithubRuleSet + client engine.ReconciliatorExecutor + ruleset *engine.GithubRuleSet } func (g *GithubCommandAddRuletset) Apply() { @@ -328,8 +328,8 @@ func (g *GithubCommandAddRuletset) Apply() { } type GithubCommandUpdateRuletset struct { - client sync.ReconciliatorExecutor - ruleset *sync.GithubRuleSet + client engine.ReconciliatorExecutor + ruleset *engine.GithubRuleSet } func (g *GithubCommandUpdateRuletset) Apply() { @@ -337,7 +337,7 @@ func (g *GithubCommandUpdateRuletset) Apply() { } type GithubCommandDeleteRuletset struct { - client sync.ReconciliatorExecutor + client engine.ReconciliatorExecutor rulesetid int } diff --git a/internal/goliac.go b/internal/goliac.go index d34490b..3f13416 100644 --- a/internal/goliac.go +++ b/internal/goliac.go @@ -6,9 +6,9 @@ import ( "strings" "github.com/Alayacare/goliac/internal/config" + "github.com/Alayacare/goliac/internal/engine" "github.com/Alayacare/goliac/internal/entity" "github.com/Alayacare/goliac/internal/github" - "github.com/Alayacare/goliac/internal/sync" "github.com/Alayacare/goliac/internal/usersync" "github.com/sirupsen/logrus" "github.com/spf13/afero" @@ -37,11 +37,13 @@ type Goliac interface { // flush remote cache FlushCache() + + GetLocal() engine.GoliacLocal } type GoliacImpl struct { - local sync.GoliacLocal - remote sync.GoliacRemoteExecutor + local engine.GoliacLocal + remote engine.GoliacRemoteExecutor githubClient github.GitHubClient repoconfig *config.RepositoryConfig } @@ -58,18 +60,22 @@ func NewGoliacImpl() (Goliac, error) { return nil, err } - remote := sync.NewGoliacRemoteImpl(githubClient) + remote := engine.NewGoliacRemoteImpl(githubClient) usersync.InitPlugins(githubClient) return &GoliacImpl{ - local: sync.NewGoliacLocalImpl(), + local: engine.NewGoliacLocalImpl(), githubClient: githubClient, remote: remote, repoconfig: &config.RepositoryConfig{}, }, nil } +func (g *GoliacImpl) GetLocal() engine.GoliacLocal { + return g.local +} + func (g *GoliacImpl) FlushCache() { g.remote.FlushCache() } @@ -122,7 +128,7 @@ func (g *GoliacImpl) ApplyToGithub(dryrun bool, teamreponame string, branch stri commits, err := g.local.ListCommitsFromTag(GOLIAC_GIT_TAG) if err != nil { ga := NewGithubBatchExecutor(g.remote, g.repoconfig.MaxChangesets) - reconciliator := sync.NewGoliacReconciliatorImpl(ga, g.repoconfig) + reconciliator := engine.NewGoliacReconciliatorImpl(ga, g.repoconfig) ctx := context.TODO() err = reconciliator.Reconciliate(ctx, g.local, g.remote, teamreponame, dryrun) @@ -133,9 +139,9 @@ func (g *GoliacImpl) ApplyToGithub(dryrun bool, teamreponame string, branch stri for _, commit := range commits { if err := g.local.CheckoutCommit(commit); err == nil { ga := NewGithubBatchExecutor(g.remote, g.repoconfig.MaxChangesets) - reconciliator := sync.NewGoliacReconciliatorImpl(ga, g.repoconfig) + reconciliator := engine.NewGoliacReconciliatorImpl(ga, g.repoconfig) - ctx := context.WithValue(context.TODO(), sync.KeyAuthor, commit.Author.Email) + ctx := context.WithValue(context.TODO(), engine.KeyAuthor, commit.Author.Email) err = reconciliator.Reconciliate(ctx, g.local, g.remote, teamreponame, dryrun) if err != nil { return fmt.Errorf("Error when reconciliating: %v", err) @@ -179,7 +185,7 @@ func (g *GoliacImpl) UsersUpdate(repositoryUrl, branch string) error { return fmt.Errorf("unable to read goliac.yaml config file: %v", err) } - userplugin, found := sync.GetUserSyncPlugin(g.repoconfig.UserSync.Plugin) + userplugin, found := engine.GetUserSyncPlugin(g.repoconfig.UserSync.Plugin) if !found { return fmt.Errorf("User Sync Plugin %s not found", g.repoconfig.UserSync.Plugin) } diff --git a/internal/goliac_light.go b/internal/goliac_light.go index 15d5a67..3b9b90d 100644 --- a/internal/goliac_light.go +++ b/internal/goliac_light.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/Alayacare/goliac/internal/config" - "github.com/Alayacare/goliac/internal/sync" + "github.com/Alayacare/goliac/internal/engine" "github.com/sirupsen/logrus" "github.com/spf13/afero" ) @@ -15,13 +15,13 @@ type GoliacLight interface { } type GoliacLightImpl struct { - local sync.GoliacLocal + local engine.GoliacLocal repoconfig *config.RepositoryConfig } func NewGoliacLightImpl() (GoliacLight, error) { return &GoliacLightImpl{ - local: sync.NewGoliacLocalImpl(), + local: engine.NewGoliacLocalImpl(), repoconfig: &config.RepositoryConfig{}, }, nil } diff --git a/internal/scaffold.go b/internal/scaffold.go index e7e8faf..0fc565d 100644 --- a/internal/scaffold.go +++ b/internal/scaffold.go @@ -6,9 +6,9 @@ import ( "strings" "github.com/Alayacare/goliac/internal/config" + "github.com/Alayacare/goliac/internal/engine" "github.com/Alayacare/goliac/internal/entity" "github.com/Alayacare/goliac/internal/github" - "github.com/Alayacare/goliac/internal/sync" "github.com/sirupsen/logrus" "github.com/spf13/afero" "gopkg.in/yaml.v3" @@ -17,7 +17,7 @@ import ( type LoadGithubSamlUsers func() (map[string]*entity.User, error) type Scaffold struct { - remote sync.GoliacRemote + remote engine.GoliacRemote loadUsersFromGithubOrgSaml LoadGithubSamlUsers } @@ -33,12 +33,12 @@ func NewScaffold() (*Scaffold, error) { return nil, err } - remote := sync.NewGoliacRemoteImpl(githubClient) + remote := engine.NewGoliacRemoteImpl(githubClient) return &Scaffold{ remote: remote, loadUsersFromGithubOrgSaml: func() (map[string]*entity.User, error) { - return sync.LoadUsersFromGithubOrgSaml(githubClient) + return engine.LoadUsersFromGithubOrgSaml(githubClient) }, }, nil } diff --git a/internal/scaffold_test.go b/internal/scaffold_test.go index a5818b5..280b6d5 100644 --- a/internal/scaffold_test.go +++ b/internal/scaffold_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" + "github.com/Alayacare/goliac/internal/engine" "github.com/Alayacare/goliac/internal/entity" - "github.com/Alayacare/goliac/internal/sync" "github.com/spf13/afero" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" @@ -13,9 +13,9 @@ import ( type ScaffoldGoliacRemoteMock struct { users map[string]string - teams map[string]*sync.GithubTeam - repos map[string]*sync.GithubRepository - teamsRepos map[string]map[string]*sync.GithubTeamRepo + teams map[string]*engine.GithubTeam + repos map[string]*engine.GithubRepository + teamsRepos map[string]map[string]*engine.GithubTeamRepo } func (s *ScaffoldGoliacRemoteMock) Load() error { @@ -29,70 +29,70 @@ func (s *ScaffoldGoliacRemoteMock) Users() map[string]string { func (s *ScaffoldGoliacRemoteMock) TeamSlugByName() map[string]string { return nil } -func (s *ScaffoldGoliacRemoteMock) Teams() map[string]*sync.GithubTeam { +func (s *ScaffoldGoliacRemoteMock) Teams() map[string]*engine.GithubTeam { return s.teams } -func (s *ScaffoldGoliacRemoteMock) Repositories() map[string]*sync.GithubRepository { +func (s *ScaffoldGoliacRemoteMock) Repositories() map[string]*engine.GithubRepository { return s.repos } -func (s *ScaffoldGoliacRemoteMock) TeamRepositories() map[string]map[string]*sync.GithubTeamRepo { +func (s *ScaffoldGoliacRemoteMock) TeamRepositories() map[string]map[string]*engine.GithubTeamRepo { return s.teamsRepos } -func (s *ScaffoldGoliacRemoteMock) RuleSets() map[string]*sync.GithubRuleSet { +func (s *ScaffoldGoliacRemoteMock) RuleSets() map[string]*engine.GithubRuleSet { return nil } func (s *ScaffoldGoliacRemoteMock) AppIds() map[string]int { return nil } -func NewScaffoldGoliacRemoteMock() sync.GoliacRemote { +func NewScaffoldGoliacRemoteMock() engine.GoliacRemote { users := make(map[string]string) - teams := make(map[string]*sync.GithubTeam) - repos := make(map[string]*sync.GithubRepository) - teamsRepos := make(map[string]map[string]*sync.GithubTeamRepo) + teams := make(map[string]*engine.GithubTeam) + repos := make(map[string]*engine.GithubRepository) + teamsRepos := make(map[string]map[string]*engine.GithubTeamRepo) users["githubid1"] = "githubid1" users["githubid2"] = "githubid2" users["githubid3"] = "githubid3" users["githubid4"] = "githubid4" - admin := sync.GithubTeam{ + admin := engine.GithubTeam{ Name: "admin", Slug: "admin", Members: []string{"githubid1", "githubid2"}, } teams["admin"] = &admin - regular := sync.GithubTeam{ + regular := engine.GithubTeam{ Name: "regular", Slug: "regular", Members: []string{"githubid2", "githubid3"}, } teams["regular"] = ®ular - repo1 := sync.GithubRepository{ + repo1 := engine.GithubRepository{ Name: "repo1", } repos["repo1"] = &repo1 - repo2 := sync.GithubRepository{ + repo2 := engine.GithubRepository{ Name: "repo2", } repos["repo2"] = &repo2 - teamRepoRegular := make(map[string]*sync.GithubTeamRepo) - teamRepoRegular["repo1"] = &sync.GithubTeamRepo{ + teamRepoRegular := make(map[string]*engine.GithubTeamRepo) + teamRepoRegular["repo1"] = &engine.GithubTeamRepo{ Name: "repo1", Permission: "WRITE", } - teamRepoRegular["repo2"] = &sync.GithubTeamRepo{ + teamRepoRegular["repo2"] = &engine.GithubTeamRepo{ Name: "repo2", Permission: "READ", } teamsRepos["regular"] = teamRepoRegular - teamRepoAdmin := make(map[string]*sync.GithubTeamRepo) - teamRepoAdmin["repo2"] = &sync.GithubTeamRepo{ + teamRepoAdmin := make(map[string]*engine.GithubTeamRepo) + teamRepoAdmin["repo2"] = &engine.GithubTeamRepo{ Name: "repo2", Permission: "WRITE", } diff --git a/internal/usersync/fromgithubsaml.go b/internal/usersync/fromgithubsaml.go index 1c5588d..eb11deb 100644 --- a/internal/usersync/fromgithubsaml.go +++ b/internal/usersync/fromgithubsaml.go @@ -4,9 +4,9 @@ import ( "fmt" "github.com/Alayacare/goliac/internal/config" + "github.com/Alayacare/goliac/internal/engine" "github.com/Alayacare/goliac/internal/entity" "github.com/Alayacare/goliac/internal/github" - "github.com/Alayacare/goliac/internal/sync" ) /* @@ -19,7 +19,7 @@ type UserSyncPluginFromGithubSaml struct { client github.GitHubClient } -func NewUserSyncPluginFromGithubSaml(client github.GitHubClient) sync.UserSyncPlugin { +func NewUserSyncPluginFromGithubSaml(client github.GitHubClient) engine.UserSyncPlugin { return &UserSyncPluginFromGithubSaml{ client: client, } @@ -27,7 +27,7 @@ func NewUserSyncPluginFromGithubSaml(client github.GitHubClient) sync.UserSyncPl func (p *UserSyncPluginFromGithubSaml) UpdateUsers(repoconfig *config.RepositoryConfig, orguserdirrectorypath string) (map[string]*entity.User, error) { - users, err := sync.LoadUsersFromGithubOrgSaml(p.client) + users, err := engine.LoadUsersFromGithubOrgSaml(p.client) if len(users) == 0 { return nil, fmt.Errorf("Not able to find any SAML identities") diff --git a/internal/usersync/init.go b/internal/usersync/init.go index cdd9bc4..925cbce 100644 --- a/internal/usersync/init.go +++ b/internal/usersync/init.go @@ -1,12 +1,12 @@ package usersync import ( + "github.com/Alayacare/goliac/internal/engine" "github.com/Alayacare/goliac/internal/github" - "github.com/Alayacare/goliac/internal/sync" ) func InitPlugins(client github.GitHubClient) { - sync.RegisterPlugin("noop", NewUserSyncPluginNoop()) - sync.RegisterPlugin("shellscript", NewUserSyncPluginShellScript()) - sync.RegisterPlugin("fromgithubsaml", NewUserSyncPluginFromGithubSaml(client)) + engine.RegisterPlugin("noop", NewUserSyncPluginNoop()) + engine.RegisterPlugin("shellscript", NewUserSyncPluginShellScript()) + engine.RegisterPlugin("fromgithubsaml", NewUserSyncPluginFromGithubSaml(client)) } diff --git a/internal/usersync/noop.go b/internal/usersync/noop.go index 8c50b57..7db32c9 100644 --- a/internal/usersync/noop.go +++ b/internal/usersync/noop.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/Alayacare/goliac/internal/config" + "github.com/Alayacare/goliac/internal/engine" "github.com/Alayacare/goliac/internal/entity" - "github.com/Alayacare/goliac/internal/sync" "github.com/spf13/afero" ) @@ -13,7 +13,7 @@ type UserSyncPluginNoop struct { Fs afero.Fs } -func NewUserSyncPluginNoop() sync.UserSyncPlugin { +func NewUserSyncPluginNoop() engine.UserSyncPlugin { return &UserSyncPluginNoop{ Fs: afero.NewOsFs(), } diff --git a/internal/usersync/shellscript.go b/internal/usersync/shellscript.go index 9ba9bda..c0d2057 100644 --- a/internal/usersync/shellscript.go +++ b/internal/usersync/shellscript.go @@ -5,14 +5,14 @@ import ( "os/exec" "github.com/Alayacare/goliac/internal/config" + "github.com/Alayacare/goliac/internal/engine" "github.com/Alayacare/goliac/internal/entity" - "github.com/Alayacare/goliac/internal/sync" "github.com/spf13/afero" ) type UserSyncPluginShellScript struct{} -func NewUserSyncPluginShellScript() sync.UserSyncPlugin { +func NewUserSyncPluginShellScript() engine.UserSyncPlugin { return &UserSyncPluginShellScript{} }