diff --git a/README.md b/README.md index 46a6a20..1654952 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,8 @@ If you want to create a new team (like `foobar`), you need to create a PR with a ``` apiVersion: v1 kind: Team -metadata: - name: foobar -data: +name: foobar +spec: owners: - user1 - user2 @@ -52,8 +51,7 @@ On a given team subdirectory you can create a repository definition via a yaml f ``` apiVersion: v1 kind: Repository -metadata: - name: awesome-repository +name: awesome-repository ``` This will create a `awesome-repository` repository under your organization, that will be @@ -65,9 +63,8 @@ You can of course tweak that: ``` apiVersion: v1 kind: Repository -metadata: - name: awesome-repository -data: +name: awesome-repository +spec: public: true writers: - anotherteamA @@ -89,9 +86,8 @@ You can archive a repository, by a PR that ``` apiVersion: v1 kind: Repository -metadata: - name: awesome-repository -data: +name: awesome-repository +spec: archived: true ``` diff --git a/docs/installation.md b/docs/installation.md index 2a3a330..dae96e0 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -132,20 +132,20 @@ and you can configure different ruleset in the `/rulesets` directory like ``` apiVersion: v1 kind: Ruleset -metadata: - name: default -enforcement: evaluate # can be disable, active or evaluate -bypassapps: - - appname: goliac-project-app - mode: always # always or pull_request -on: - include: - - "~DEFAULT_BRANCH" # it can be ~ALL,~DEFAULT_BRANCH, or branch name - -rules: - - ruletype: pull_request # currently supported: pull_request, required_signatures, required_status_checks - parameters: - requiredApprovingReviewCount: 1 +name: default +spec: + enforcement: evaluate # can be disable, active or evaluate + bypassapps: + - appname: goliac-project-app + mode: always # always or pull_request + on: + include: + - "~DEFAULT_BRANCH" # it can be ~ALL,~DEFAULT_BRANCH, or branch name + + rules: + - ruletype: pull_request # currently supported: pull_request, required_signatures,required_status_checks + parameters: + requiredApprovingReviewCount: 1 ``` ## Testing your IAC github repository @@ -203,7 +203,7 @@ You can run the goliac server as a service or a docker container. It needs sever | GOLIAC_SERVER_GIT_BRANCH | main | teams repo default branch name to use | | GOLIAC_SERVER_HOST |localhost | useful to put it to `0.0.0.0` | | GOLIAC_SERVER_PORT | 18000 | | - +| GOLIAC_SERVER_GIT_BRANCH_PROTECTION_REQUIRED_CHECK | validate | ci check to enforce when evaluating a PR (used for CI mode) | then you just need to start it with ``` @@ -243,8 +243,7 @@ As a reminder a user is defined via a yaml file like `alice.yaml` with the conte ``` apiVersion: v1 kind: User -metadata: - name: alice -data: +name: alice +spec: githubID: alice-myorg ``` diff --git a/internal/engine/githubsaml.go b/internal/engine/githubsaml.go index 8985326..db3a06b 100644 --- a/internal/engine/githubsaml.go +++ b/internal/engine/githubsaml.go @@ -105,8 +105,8 @@ func LoadUsersFromGithubOrgSaml(client github.GitHubClient) (map[string]*entity. user := &entity.User{} user.ApiVersion = "v1" user.Kind = "User" - user.Metadata.Name = c.Node.SamlIdentity.NameId - user.Data.GithubID = c.Node.User.Login + user.Name = c.Node.SamlIdentity.NameId + user.Spec.GithubID = c.Node.User.Login users[c.Node.SamlIdentity.NameId] = user } diff --git a/internal/engine/goliac_reconciliator.go b/internal/engine/goliac_reconciliator.go index 9f91980..7cc21cb 100644 --- a/internal/engine/goliac_reconciliator.go +++ b/internal/engine/goliac_reconciliator.go @@ -83,7 +83,7 @@ func (r *GoliacReconciliatorImpl) reconciliateUsers(ctx context.Context, local G } for _, lUser := range local.Users() { - user, ok := rUsers[lUser.Data.GithubID] + user, ok := rUsers[lUser.Spec.GithubID] if !ok { // deal with non existing remote user @@ -116,8 +116,8 @@ func (r *GoliacReconciliatorImpl) reconciliateTeams(ctx context.Context, local G slugTeams := make(map[string]*GithubTeam) for teamname, teamvalue := range local.Teams() { members := []string{} - members = append(members, teamvalue.Data.Members...) - members = append(members, teamvalue.Data.Owners...) + members = append(members, teamvalue.Spec.Members...) + members = append(members, teamvalue.Spec.Owners...) teamslug := slug.Make(teamname) slugTeams[teamslug] = &GithubTeam{ @@ -130,7 +130,7 @@ func (r *GoliacReconciliatorImpl) reconciliateTeams(ctx context.Context, local G slugTeams[teamslug+"-owners"] = &GithubTeam{ Name: teamname + "-owners", Slug: teamslug + "-owners", - Members: teamvalue.Data.Owners, + Members: teamvalue.Spec.Owners, } } @@ -158,7 +158,7 @@ func (r *GoliacReconciliatorImpl) reconciliateTeams(ctx context.Context, local G members := make([]string, 0) for _, m := range lTeam.Members { if ghuserid, ok := local.Users()[m]; ok { - members = append(members, ghuserid.Data.GithubID) + members = append(members, ghuserid.Spec.GithubID) } } // CREATE team @@ -174,7 +174,7 @@ func (r *GoliacReconciliatorImpl) reconciliateTeams(ctx context.Context, local G localMembers := make(map[string]bool) for _, m := range lTeam.Members { if ghuserid, ok := local.Users()[m]; ok { - localMembers[ghuserid.Data.GithubID] = true + localMembers[ghuserid.Spec.GithubID] = true } } @@ -249,7 +249,7 @@ func (r *GoliacReconciliatorImpl) reconciliateRepositories(ctx context.Context, lRepos := make(map[string]*GithubRepoComparable) for reponame, lRepo := range local.Repositories() { writers := make([]string, 0) - for _, w := range lRepo.Data.Writers { + for _, w := range lRepo.Spec.Writers { writers = append(writers, slug.Make(w)) } // add the team owner's name ;-) @@ -257,7 +257,7 @@ func (r *GoliacReconciliatorImpl) reconciliateRepositories(ctx context.Context, writers = append(writers, slug.Make(*lRepo.Owner)) } readers := make([]string, 0) - for _, r := range lRepo.Data.Readers { + for _, r := range lRepo.Spec.Readers { readers = append(readers, slug.Make(r)) } @@ -275,22 +275,22 @@ func (r *GoliacReconciliatorImpl) reconciliateRepositories(ctx context.Context, // adding exernal reader/writer eReaders := make([]string, 0) - for _, r := range lRepo.Data.ExternalUserReaders { + for _, r := range lRepo.Spec.ExternalUserReaders { if user, ok := local.ExternalUsers()[r]; ok { - eReaders = append(eReaders, user.Data.GithubID) + eReaders = append(eReaders, user.Spec.GithubID) } } eWriters := make([]string, 0) - for _, w := range lRepo.Data.ExternalUserWriters { + for _, w := range lRepo.Spec.ExternalUserWriters { if user, ok := local.ExternalUsers()[w]; ok { - eWriters = append(eWriters, user.Data.GithubID) + eWriters = append(eWriters, user.Spec.GithubID) } } lRepos[slug.Make(reponame)] = &GithubRepoComparable{ - IsPublic: lRepo.Data.IsPublic, - IsArchived: lRepo.Data.IsArchived, + IsPublic: lRepo.Spec.IsPublic, + IsArchived: lRepo.Spec.IsArchived, Readers: readers, Writers: writers, ExternalUserReaders: eReaders, @@ -431,17 +431,17 @@ func (r *GoliacReconciliatorImpl) reconciliateRulesets(ctx context.Context, loca } grs := GithubRuleSet{ - Name: rs.Metadata.Name, - Enforcement: rs.Enforcement, + Name: rs.Name, + Enforcement: rs.Spec.Enforcement, BypassApps: map[string]string{}, - OnInclude: rs.On.Include, - OnExclude: rs.On.Exclude, + OnInclude: rs.Spec.On.Include, + OnExclude: rs.Spec.On.Exclude, Rules: map[string]entity.RuleSetParameters{}, } - for _, b := range rs.BypassApps { + for _, b := range rs.Spec.BypassApps { grs.BypassApps[b.AppName] = b.Mode } - for _, r := range rs.Rules { + for _, r := range rs.Spec.Rules { grs.Rules[r.Ruletype] = r.Parameters } for reponame := range repositories { @@ -449,7 +449,7 @@ func (r *GoliacReconciliatorImpl) reconciliateRulesets(ctx context.Context, loca grs.Repositories = append(grs.Repositories, slug.Make(reponame)) } } - lgrs[rs.Metadata.Name] = &grs + lgrs[rs.Name] = &grs } // prepare remote comparable diff --git a/internal/engine/goliac_reconciliator_test.go b/internal/engine/goliac_reconciliator_test.go index 8946dd7..f93f303 100644 --- a/internal/engine/goliac_reconciliator_test.go +++ b/internal/engine/goliac_reconciliator_test.go @@ -242,18 +242,18 @@ func TestReconciliation(t *testing.T) { repos: make(map[string]*entity.Repository), } newTeam := &entity.Team{} - newTeam.Metadata.Name = "new" - newTeam.Data.Owners = []string{"new.owner"} - newTeam.Data.Members = []string{"new.member"} + newTeam.Name = "new" + newTeam.Spec.Owners = []string{"new.owner"} + newTeam.Spec.Members = []string{"new.member"} local.teams["new"] = newTeam newOwner := entity.User{} - newOwner.Metadata.Name = "new.owner" - newOwner.Data.GithubID = "new_owner" + newOwner.Name = "new.owner" + newOwner.Spec.GithubID = "new_owner" local.users["new.owner"] = &newOwner newMember := entity.User{} - newMember.Metadata.Name = "new.member" - newMember.Data.GithubID = "new_member" + newMember.Name = "new.member" + newMember.Spec.GithubID = "new_member" local.users["new.member"] = &newMember remote := GoliacRemoteMock{ @@ -285,18 +285,18 @@ func TestReconciliation(t *testing.T) { repos: make(map[string]*entity.Repository), } newTeam := &entity.Team{} - newTeam.Metadata.Name = "nouveauté" - newTeam.Data.Owners = []string{"new.owner"} - newTeam.Data.Members = []string{"new.member"} + newTeam.Name = "nouveauté" + newTeam.Spec.Owners = []string{"new.owner"} + newTeam.Spec.Members = []string{"new.member"} local.teams["nouveauté"] = newTeam newOwner := entity.User{} - newOwner.Metadata.Name = "new.owner" - newOwner.Data.GithubID = "new_owner" + newOwner.Name = "new.owner" + newOwner.Spec.GithubID = "new_owner" local.users["new.owner"] = &newOwner newMember := entity.User{} - newMember.Metadata.Name = "new.member" - newMember.Data.GithubID = "new_member" + newMember.Name = "new.member" + newMember.Spec.GithubID = "new_member" local.users["new.member"] = &newMember remote := GoliacRemoteMock{ @@ -328,24 +328,24 @@ func TestReconciliation(t *testing.T) { repos: make(map[string]*entity.Repository), } existingTeam := &entity.Team{} - existingTeam.Metadata.Name = "existing" - existingTeam.Data.Owners = []string{"existing.owner", "existing.owner2"} - existingTeam.Data.Members = []string{"existing.member"} + existingTeam.Name = "existing" + existingTeam.Spec.Owners = []string{"existing.owner", "existing.owner2"} + existingTeam.Spec.Members = []string{"existing.member"} local.teams["existing"] = existingTeam existing_owner := entity.User{} - existing_owner.Metadata.Name = "existing.owner" - existing_owner.Data.GithubID = "existing_owner" + existing_owner.Name = "existing.owner" + existing_owner.Spec.GithubID = "existing_owner" local.users["existing.owner"] = &existing_owner existing_owner2 := entity.User{} - existing_owner2.Metadata.Name = "existing.owner2" - existing_owner2.Data.GithubID = "existing_owner2" + existing_owner2.Name = "existing.owner2" + existing_owner2.Spec.GithubID = "existing_owner2" local.users["existing.owner2"] = &existing_owner2 existing_member := entity.User{} - existing_member.Metadata.Name = "existing.member" - existing_member.Data.GithubID = "existing_member" + existing_member.Name = "existing.member" + existing_member.Spec.GithubID = "existing_member" local.users["existing.member"] = &existing_member remote := GoliacRemoteMock{ @@ -389,24 +389,24 @@ func TestReconciliation(t *testing.T) { repos: make(map[string]*entity.Repository), } existingTeam := &entity.Team{} - existingTeam.Metadata.Name = "exist ing" - existingTeam.Data.Owners = []string{"existing.owner", "existing.owner2"} - existingTeam.Data.Members = []string{"existing.member"} + existingTeam.Name = "exist ing" + existingTeam.Spec.Owners = []string{"existing.owner", "existing.owner2"} + existingTeam.Spec.Members = []string{"existing.member"} local.teams["exist ing"] = existingTeam existing_owner := entity.User{} - existing_owner.Metadata.Name = "existing.owner" - existing_owner.Data.GithubID = "existing_owner" + existing_owner.Name = "existing.owner" + existing_owner.Spec.GithubID = "existing_owner" local.users["existing.owner"] = &existing_owner existing_owner2 := entity.User{} - existing_owner2.Metadata.Name = "existing.owner2" - existing_owner2.Data.GithubID = "existing_owner2" + existing_owner2.Name = "existing.owner2" + existing_owner2.Spec.GithubID = "existing_owner2" local.users["existing.owner2"] = &existing_owner2 existing_member := entity.User{} - existing_member.Metadata.Name = "existing.member" - existing_member.Data.GithubID = "existing_member" + existing_member.Name = "existing.member" + existing_member.Spec.GithubID = "existing_member" local.users["existing.member"] = &existing_member remote := GoliacRemoteMock{ @@ -454,18 +454,18 @@ func TestReconciliation(t *testing.T) { repos: make(map[string]*entity.Repository), } newTeam := &entity.Team{} - newTeam.Metadata.Name = "new" - newTeam.Data.Owners = []string{"new.owner"} - newTeam.Data.Members = []string{"new.member"} + newTeam.Name = "new" + newTeam.Spec.Owners = []string{"new.owner"} + newTeam.Spec.Members = []string{"new.member"} local.teams["new"] = newTeam newOwner := entity.User{} - newOwner.Metadata.Name = "new.owner" - newOwner.Data.GithubID = "new_owner" + newOwner.Name = "new.owner" + newOwner.Spec.GithubID = "new_owner" local.users["new.owner"] = &newOwner newMember := entity.User{} - newMember.Metadata.Name = "new.member" - newMember.Data.GithubID = "new_member" + newMember.Name = "new.member" + newMember.Spec.GithubID = "new_member" local.users["new.member"] = &newMember remote := GoliacRemoteMock{ @@ -564,9 +564,9 @@ func TestReconciliation(t *testing.T) { repos: make(map[string]*entity.Repository), } newRepo := &entity.Repository{} - newRepo.Metadata.Name = "new" - newRepo.Data.Readers = []string{} - newRepo.Data.Writers = []string{} + newRepo.Name = "new" + newRepo.Spec.Readers = []string{} + newRepo.Spec.Writers = []string{} local.repos["new"] = newRepo remote := GoliacRemoteMock{ @@ -597,17 +597,17 @@ func TestReconciliation(t *testing.T) { repos: make(map[string]*entity.Repository), } newRepo := &entity.Repository{} - newRepo.Metadata.Name = "new" - newRepo.Data.Readers = []string{} - newRepo.Data.Writers = []string{} + newRepo.Name = "new" + newRepo.Spec.Readers = []string{} + newRepo.Spec.Writers = []string{} owner := "existing" newRepo.Owner = &owner local.repos["new"] = newRepo existingTeam := &entity.Team{} - existingTeam.Metadata.Name = "existing" - existingTeam.Data.Owners = []string{"existing_owner"} - existingTeam.Data.Members = []string{"existing_member"} + existingTeam.Name = "existing" + existingTeam.Spec.Owners = []string{"existing_owner"} + existingTeam.Spec.Members = []string{"existing_member"} local.teams["existing"] = existingTeam remote := GoliacRemoteMock{ @@ -644,17 +644,17 @@ func TestReconciliation(t *testing.T) { repos: make(map[string]*entity.Repository), } lRepo := &entity.Repository{} - lRepo.Metadata.Name = "myrepo" - lRepo.Data.Readers = []string{} - lRepo.Data.Writers = []string{} + lRepo.Name = "myrepo" + lRepo.Spec.Readers = []string{} + lRepo.Spec.Writers = []string{} lowner := "existing" lRepo.Owner = &lowner local.repos["myrepo"] = lRepo existingTeam := &entity.Team{} - existingTeam.Metadata.Name = "existing" - existingTeam.Data.Owners = []string{"existing_owner"} - existingTeam.Data.Members = []string{"existing_member"} + existingTeam.Name = "existing" + existingTeam.Spec.Owners = []string{"existing_owner"} + existingTeam.Spec.Members = []string{"existing_member"} local.teams["existing"] = existingTeam remote := GoliacRemoteMock{ @@ -707,17 +707,17 @@ func TestReconciliation(t *testing.T) { repos: make(map[string]*entity.Repository), } lRepo := &entity.Repository{} - lRepo.Metadata.Name = "myrepo" - lRepo.Data.Readers = []string{} - lRepo.Data.Writers = []string{} + lRepo.Name = "myrepo" + lRepo.Spec.Readers = []string{} + lRepo.Spec.Writers = []string{} lowner := "existing" lRepo.Owner = &lowner local.repos["myrepo"] = lRepo existingTeam := &entity.Team{} - existingTeam.Metadata.Name = "existing" - existingTeam.Data.Owners = []string{"existing_owner"} - existingTeam.Data.Members = []string{"existing_member"} + existingTeam.Name = "existing" + existingTeam.Spec.Owners = []string{"existing_owner"} + existingTeam.Spec.Members = []string{"existing_member"} local.teams["existing"] = existingTeam remote := GoliacRemoteMock{ @@ -769,23 +769,23 @@ func TestReconciliation(t *testing.T) { repos: make(map[string]*entity.Repository), } lRepo := &entity.Repository{} - lRepo.Metadata.Name = "myrepo" - lRepo.Data.Readers = []string{"reader"} - lRepo.Data.Writers = []string{} + lRepo.Name = "myrepo" + lRepo.Spec.Readers = []string{"reader"} + lRepo.Spec.Writers = []string{} lowner := "existing" lRepo.Owner = &lowner local.repos["myrepo"] = lRepo existingTeam := &entity.Team{} - existingTeam.Metadata.Name = "existing" - existingTeam.Data.Owners = []string{"existing_owner"} - existingTeam.Data.Members = []string{"existing_member"} + existingTeam.Name = "existing" + existingTeam.Spec.Owners = []string{"existing_owner"} + existingTeam.Spec.Members = []string{"existing_member"} local.teams["existing"] = existingTeam readerTeam := &entity.Team{} - readerTeam.Metadata.Name = "reader" - readerTeam.Data.Owners = []string{"existing_owner"} - readerTeam.Data.Members = []string{"existing_member"} + readerTeam.Name = "reader" + readerTeam.Spec.Owners = []string{"existing_owner"} + readerTeam.Spec.Members = []string{"existing_member"} local.teams["reader"] = readerTeam remote := GoliacRemoteMock{ @@ -842,23 +842,23 @@ func TestReconciliation(t *testing.T) { repos: make(map[string]*entity.Repository), } lRepo := &entity.Repository{} - lRepo.Metadata.Name = "myrepo" - lRepo.Data.Readers = []string{} - lRepo.Data.Writers = []string{} + lRepo.Name = "myrepo" + lRepo.Spec.Readers = []string{} + lRepo.Spec.Writers = []string{} lowner := "existing" lRepo.Owner = &lowner local.repos["myrepo"] = lRepo existingTeam := &entity.Team{} - existingTeam.Metadata.Name = "existing" - existingTeam.Data.Owners = []string{"existing_owner"} - existingTeam.Data.Members = []string{"existing_member"} + existingTeam.Name = "existing" + existingTeam.Spec.Owners = []string{"existing_owner"} + existingTeam.Spec.Members = []string{"existing_member"} local.teams["existing"] = existingTeam readerTeam := &entity.Team{} - readerTeam.Metadata.Name = "reader" - readerTeam.Data.Owners = []string{"existing_owner"} - readerTeam.Data.Members = []string{"existing_member"} + readerTeam.Name = "reader" + readerTeam.Spec.Owners = []string{"existing_owner"} + readerTeam.Spec.Members = []string{"existing_member"} local.teams["reader"] = readerTeam remote := GoliacRemoteMock{ @@ -920,17 +920,17 @@ func TestReconciliation(t *testing.T) { repos: make(map[string]*entity.Repository), } lRepo := &entity.Repository{} - lRepo.Metadata.Name = "myrepo" - lRepo.Data.Readers = []string{} - lRepo.Data.Writers = []string{} + lRepo.Name = "myrepo" + lRepo.Spec.Readers = []string{} + lRepo.Spec.Writers = []string{} lowner := "existing" lRepo.Owner = &lowner local.repos["myrepo"] = lRepo existingTeam := &entity.Team{} - existingTeam.Metadata.Name = "existing" - existingTeam.Data.Owners = []string{"existing_owner"} - existingTeam.Data.Members = []string{} + existingTeam.Name = "existing" + existingTeam.Spec.Owners = []string{"existing_owner"} + existingTeam.Spec.Members = []string{} local.teams["existing"] = existingTeam remote := GoliacRemoteMock{ @@ -981,23 +981,23 @@ func TestReconciliation(t *testing.T) { repos: make(map[string]*entity.Repository), } lRepo := &entity.Repository{} - lRepo.Metadata.Name = "myrepo" - lRepo.Data.Readers = []string{"reader"} - lRepo.Data.Writers = []string{} + lRepo.Name = "myrepo" + lRepo.Spec.Readers = []string{"reader"} + lRepo.Spec.Writers = []string{} lowner := "existing" lRepo.Owner = &lowner local.repos["myrepo"] = lRepo existingTeam := &entity.Team{} - existingTeam.Metadata.Name = "existing" - existingTeam.Data.Owners = []string{"existing_owner"} - existingTeam.Data.Members = []string{"existing_member"} + existingTeam.Name = "existing" + existingTeam.Spec.Owners = []string{"existing_owner"} + existingTeam.Spec.Members = []string{"existing_member"} local.teams["existing"] = existingTeam readerTeam := &entity.Team{} - readerTeam.Metadata.Name = "reader" - readerTeam.Data.Owners = []string{"existing_owner"} - readerTeam.Data.Members = []string{"existing_member"} + readerTeam.Name = "reader" + readerTeam.Spec.Owners = []string{"existing_owner"} + readerTeam.Spec.Members = []string{"existing_member"} local.teams["reader"] = readerTeam remote := GoliacRemoteMock{ @@ -1048,23 +1048,23 @@ func TestReconciliation(t *testing.T) { repos: make(map[string]*entity.Repository), } outside1 := entity.User{} - outside1.Metadata.Name = "outside1" - outside1.Data.GithubID = "outside1-githubid" + outside1.Name = "outside1" + outside1.Spec.GithubID = "outside1-githubid" local.externals["outside1"] = &outside1 lRepo := &entity.Repository{} - lRepo.Metadata.Name = "myrepo" - lRepo.Data.Readers = []string{} - lRepo.Data.Writers = []string{} - lRepo.Data.ExternalUserWriters = []string{"outside1"} + lRepo.Name = "myrepo" + lRepo.Spec.Readers = []string{} + lRepo.Spec.Writers = []string{} + lRepo.Spec.ExternalUserWriters = []string{"outside1"} lowner := "existing" lRepo.Owner = &lowner local.repos["myrepo"] = lRepo existingTeam := &entity.Team{} - existingTeam.Metadata.Name = "existing" - existingTeam.Data.Owners = []string{"existing_owner"} - existingTeam.Data.Members = []string{} + existingTeam.Name = "existing" + existingTeam.Spec.Owners = []string{"existing_owner"} + existingTeam.Spec.Members = []string{} local.teams["existing"] = existingTeam remote := GoliacRemoteMock{ @@ -1120,18 +1120,18 @@ func TestReconciliation(t *testing.T) { } lRepo := &entity.Repository{} - lRepo.Metadata.Name = "myrepo" - lRepo.Data.Readers = []string{} - lRepo.Data.Writers = []string{} - lRepo.Data.ExternalUserWriters = []string{} + lRepo.Name = "myrepo" + lRepo.Spec.Readers = []string{} + lRepo.Spec.Writers = []string{} + lRepo.Spec.ExternalUserWriters = []string{} lowner := "existing" lRepo.Owner = &lowner local.repos["myrepo"] = lRepo existingTeam := &entity.Team{} - existingTeam.Metadata.Name = "existing" - existingTeam.Data.Owners = []string{"existing_owner"} - existingTeam.Data.Members = []string{} + existingTeam.Name = "existing" + existingTeam.Spec.Owners = []string{"existing_owner"} + existingTeam.Spec.Members = []string{} local.teams["existing"] = existingTeam remote := GoliacRemoteMock{ @@ -1188,24 +1188,24 @@ func TestReconciliation(t *testing.T) { } outside1 := entity.User{} - outside1.Metadata.Name = "outside1" - outside1.Data.GithubID = "outside1-githubid" + outside1.Name = "outside1" + outside1.Spec.GithubID = "outside1-githubid" local.externals["outside1"] = &outside1 lRepo := &entity.Repository{} - lRepo.Metadata.Name = "myrepo" - lRepo.Data.Readers = []string{} - lRepo.Data.Writers = []string{} - lRepo.Data.ExternalUserWriters = []string{} - lRepo.Data.ExternalUserReaders = []string{"outside1"} + lRepo.Name = "myrepo" + lRepo.Spec.Readers = []string{} + lRepo.Spec.Writers = []string{} + lRepo.Spec.ExternalUserWriters = []string{} + lRepo.Spec.ExternalUserReaders = []string{"outside1"} lowner := "existing" lRepo.Owner = &lowner local.repos["myrepo"] = lRepo existingTeam := &entity.Team{} - existingTeam.Metadata.Name = "existing" - existingTeam.Data.Owners = []string{"existing_owner"} - existingTeam.Data.Members = []string{} + existingTeam.Name = "existing" + existingTeam.Spec.Owners = []string{"existing_owner"} + existingTeam.Spec.Members = []string{} local.teams["existing"] = existingTeam remote := GoliacRemoteMock{ @@ -1327,9 +1327,9 @@ func TestReconciliationRulesets(t *testing.T) { } newRuleset := &entity.RuleSet{} - newRuleset.Metadata.Name = "new" - newRuleset.Enforcement = "evaluate" - newRuleset.Rules = append(newRuleset.Rules, struct { + newRuleset.Name = "new" + newRuleset.Spec.Enforcement = "evaluate" + newRuleset.Spec.Rules = append(newRuleset.Spec.Rules, struct { Ruletype string Parameters entity.RuleSetParameters }{ @@ -1381,9 +1381,9 @@ func TestReconciliationRulesets(t *testing.T) { } newRuleset := &entity.RuleSet{} - newRuleset.Metadata.Name = "new" - newRuleset.Enforcement = "evaluate" - newRuleset.Rules = append(newRuleset.Rules, struct { + newRuleset.Name = "new" + newRuleset.Spec.Enforcement = "evaluate" + newRuleset.Spec.Rules = append(newRuleset.Spec.Rules, struct { Ruletype string Parameters entity.RuleSetParameters }{ @@ -1435,9 +1435,9 @@ func TestReconciliationRulesets(t *testing.T) { } lRuleset := &entity.RuleSet{} - lRuleset.Metadata.Name = "update" - lRuleset.Enforcement = "evaluate" - lRuleset.Rules = append(lRuleset.Rules, struct { + lRuleset.Name = "update" + lRuleset.Spec.Enforcement = "evaluate" + lRuleset.Spec.Rules = append(lRuleset.Spec.Rules, struct { Ruletype string Parameters entity.RuleSetParameters }{ diff --git a/internal/engine/local.go b/internal/engine/local.go index 5319bb1..3dd6c12 100644 --- a/internal/engine/local.go +++ b/internal/engine/local.go @@ -303,7 +303,7 @@ func (g *GoliacLocalImpl) codeowners_regenerate(adminteam string) string { teamsnames := make([]string, 0) for _, t := range g.teams { - teamsnames = append(teamsnames, t.Metadata.Name) + teamsnames = append(teamsnames, t.Name) } sort.Strings(teamsnames) diff --git a/internal/engine/local_test.go b/internal/engine/local_test.go index d325491..b352d59 100644 --- a/internal/engine/local_test.go +++ b/internal/engine/local_test.go @@ -36,9 +36,8 @@ func createBasicStructure(fs afero.Fs, path string) error { err = afero.WriteFile(fs, filepath.Join(path, "users/org/user1.yaml"), []byte(` apiVersion: v1 kind: User -metadata: - name: user1 -data: +name: user1 +spec: githubID: github1 `), 0644) if err != nil { @@ -48,9 +47,8 @@ data: err = afero.WriteFile(fs, filepath.Join(path, "users/org/user2.yaml"), []byte(` apiVersion: v1 kind: User -metadata: - name: user2 -data: +name: user2 +spec: githubID: github2 `), 0644) if err != nil { @@ -66,9 +64,8 @@ data: err = afero.WriteFile(fs, filepath.Join(path, "teams/team1/team.yaml"), []byte(` apiVersion: v1 kind: Team -metadata: - name: team1 -data: +name: team1 +spec: owners: - user1 - user2 @@ -81,8 +78,7 @@ data: err = afero.WriteFile(fs, filepath.Join(path, "projects/repo1.yaml"), []byte(` apiVersion: v1 kind: Repository -metadata: - name: repo1 +name: repo1 `), 0644) if err != nil { return err @@ -157,16 +153,16 @@ func (p *ScrambleUserSync) UpdateUsers(repoconfig *config.RepositoryConfig, orgu foobar := &entity.User{} foobar.ApiVersion = "v1" foobar.Kind = "User" - foobar.Metadata.Name = "foobar" - foobar.Data.GithubID = "foobar" + foobar.Name = "foobar" + foobar.Spec.GithubID = "foobar" users["foobar"] = foobar // updated user1 := &entity.User{} user1.ApiVersion = "v1" user1.Kind = "User" - user1.Metadata.Name = "user1" - user1.Data.GithubID = "user1" + user1.Name = "user1" + user1.Spec.GithubID = "user1" users["user1"] = foobar return users, nil diff --git a/internal/entity/entity.go b/internal/entity/entity.go index 09c1153..01f8a57 100644 --- a/internal/entity/entity.go +++ b/internal/entity/entity.go @@ -10,9 +10,7 @@ type Warning error type Entity struct { ApiVersion string `yaml:"apiVersion"` Kind string `yaml:"kind"` - Metadata struct { - Name string `yaml:"name"` - } `yaml:"metadata"` + Name string `yaml:"name"` } /* diff --git a/internal/entity/entity_ruleset.go b/internal/entity/entity_ruleset.go index 1890c4f..59fb84f 100644 --- a/internal/entity/entity_ruleset.go +++ b/internal/entity/entity_ruleset.go @@ -59,21 +59,23 @@ func CompareRulesetParameters(ruletype string, left RuleSetParameters, right Rul */ type RuleSet struct { Entity `yaml:",inline"` - // Target // branch, tag - Enforcement string // disabled, active, evaluate - BypassApps []struct { - AppName string - Mode string // always, pull_request - } - On struct { - Include []string // ~DEFAULT_BRANCH, ~ALL, branch_name, ... - Exclude []string // branch_name, ... - } + Spec struct { + // Target // branch, tag + Enforcement string // disabled, active, evaluate + BypassApps []struct { + AppName string + Mode string // always, pull_request + } + On struct { + Include []string // ~DEFAULT_BRANCH, ~ALL, branch_name, ... + Exclude []string // branch_name, ... + } - Rules []struct { - Ruletype string // required_signatures, pull_request, required_status_checks... - Parameters RuleSetParameters - } `yaml:"rules"` + Rules []struct { + Ruletype string // required_signatures, pull_request, required_status_checks... + Parameters RuleSetParameters + } `yaml:"rules"` + } `yaml:"spec"` } /* @@ -126,6 +128,10 @@ func ReadRuleSetDirectory(fs afero.Fs, dirname string) (map[string]*RuleSet, []e if e.IsDir() { continue } + // skipping files starting with '.' + if e.Name()[0] == '.' { + continue + } ruleset, err := NewRuleSet(fs, filepath.Join(dirname, e.Name())) if err != nil { errors = append(errors, err) @@ -134,7 +140,7 @@ func ReadRuleSetDirectory(fs afero.Fs, dirname string) (map[string]*RuleSet, []e if err != nil { errors = append(errors, err) } else { - rulesets[ruleset.Metadata.Name] = ruleset + rulesets[ruleset.Name] = ruleset } } @@ -152,31 +158,31 @@ func (r *RuleSet) Validate(filename string) error { return fmt.Errorf("invalid kind: %s for ruleset filename %s", r.Kind, filename) } - if r.Metadata.Name == "" { + if r.Name == "" { return fmt.Errorf("metadata.name is empty for ruleset filename %s", filename) } filename = filepath.Base(filename) - if r.Metadata.Name != filename[:len(filename)-len(filepath.Ext(filename))] { - return fmt.Errorf("invalid metadata.name: %s for ruleset filename %s", r.Metadata.Name, filename) + if r.Name != filename[:len(filename)-len(filepath.Ext(filename))] { + return fmt.Errorf("invalid metadata.name: %s for ruleset filename %s", r.Name, filename) } - for _, rule := range r.Rules { + for _, rule := range r.Spec.Rules { if rule.Ruletype != "required_signatures" && rule.Ruletype != "pull_request" && rule.Ruletype != "required_status_checks" { return fmt.Errorf("invalid rulettype: %s for ruleset filename %s", rule.Ruletype, filename) } } - if r.Enforcement != "disable" && r.Enforcement != "active" && r.Enforcement != "evaluate" { - return fmt.Errorf("invalid enforcement: %s for ruleset filename %s", r.Enforcement, filename) + if r.Spec.Enforcement != "disable" && r.Spec.Enforcement != "active" && r.Spec.Enforcement != "evaluate" { + return fmt.Errorf("invalid enforcement: %s for ruleset filename %s", r.Spec.Enforcement, filename) } - for _, ba := range r.BypassApps { + for _, ba := range r.Spec.BypassApps { if ba.Mode != "always" && ba.Mode != "pull_request" { return fmt.Errorf("invalid mode: %s for bypassapp %s in ruleset filename %s", ba.Mode, ba.AppName, filename) } } - for _, on := range r.On.Include { + for _, on := range r.Spec.On.Include { if on[0] == '~' && (on != "~DEFAULT_BRANCH" && on != "~ALL") { return fmt.Errorf("invalid include: %s in ruleset filename %s", on, filename) } diff --git a/internal/entity/entity_ruletset_test.go b/internal/entity/entity_ruletset_test.go index 08d7b5b..25ac152 100644 --- a/internal/entity/entity_ruletset_test.go +++ b/internal/entity/entity_ruletset_test.go @@ -12,42 +12,42 @@ func fixtureCreateRuleSet(t *testing.T, fs afero.Fs) { err := afero.WriteFile(fs, "rulesets/ruleset1.yaml", []byte(` apiVersion: v1 kind: Ruleset -metadata: - name: ruleset1 -enforcement: evaluate -bypassapps: - - appname: goliac-project-app - mode: always -on: - include: - - "~DEFAULT_BRANCH" - -rules: - - ruletype: pull_request - parameters: - requiredApprovingReviewCount: 1 +name: ruleset1 +spec: + enforcement: evaluate + bypassapps: + - appname: goliac-project-app + mode: always + on: + include: + - "~DEFAULT_BRANCH" + + rules: + - ruletype: pull_request + parameters: + requiredApprovingReviewCount: 1 `), 0644) assert.Nil(t, err) err = afero.WriteFile(fs, "rulesets/ruleset2.yaml", []byte(` apiVersion: v1 kind: Ruleset -metadata: - name: ruleset2 -enforcement: evaluate -bypassapps: - - appname: goliac-project-app - mode: always -on: - include: - - "~DEFAULT_BRANCH" - -rules: - - ruletype: required_status_checks - parameters: - requiredStatusChecks: - - circleCI check - - jenkins check +name: ruleset2 +spec: + enforcement: evaluate + bypassapps: + - appname: goliac-project-app + mode: always + on: + include: + - "~DEFAULT_BRANCH" + + rules: + - ruletype: required_status_checks + parameters: + requiredStatusChecks: + - circleCI check + - jenkins check `), 0644) assert.Nil(t, err) } @@ -82,13 +82,13 @@ func TestRulesetParametersComparison(t *testing.T) { assert.Equal(t, len(warns), 0) assert.NotNil(t, rulesets) - res := CompareRulesetParameters(rulesets["ruleset1"].Rules[0].Ruletype, rulesets["ruleset1"].Rules[0].Parameters, rulesets["ruleset2"].Rules[0].Parameters) + res := CompareRulesetParameters(rulesets["ruleset1"].Spec.Rules[0].Ruletype, rulesets["ruleset1"].Spec.Rules[0].Parameters, rulesets["ruleset2"].Spec.Rules[0].Parameters) assert.False(t, res) - res = CompareRulesetParameters(rulesets["ruleset1"].Rules[0].Ruletype, rulesets["ruleset1"].Rules[0].Parameters, rulesets["ruleset1"].Rules[0].Parameters) + res = CompareRulesetParameters(rulesets["ruleset1"].Spec.Rules[0].Ruletype, rulesets["ruleset1"].Spec.Rules[0].Parameters, rulesets["ruleset1"].Spec.Rules[0].Parameters) assert.True(t, res) - res = CompareRulesetParameters(rulesets["ruleset2"].Rules[0].Ruletype, rulesets["ruleset2"].Rules[0].Parameters, rulesets["ruleset2"].Rules[0].Parameters) + res = CompareRulesetParameters(rulesets["ruleset2"].Spec.Rules[0].Ruletype, rulesets["ruleset2"].Spec.Rules[0].Parameters, rulesets["ruleset2"].Spec.Rules[0].Parameters) assert.True(t, res) }) } diff --git a/internal/entity/entity_test.go b/internal/entity/entity_test.go index 6803ca6..15db10f 100644 --- a/internal/entity/entity_test.go +++ b/internal/entity/entity_test.go @@ -15,14 +15,13 @@ func TestEntity(t *testing.T) { err := afero.WriteFile(fs, "foobar.yaml", []byte(` apiVersion: v1 kind: FooBar -metadata: - name: name +name: name `), 0644) assert.Nil(t, err) e, err := parseEntity(fs, "foobar.yaml") assert.Nil(t, err) assert.NotNil(t, e) - assert.Equal(t, "name", e.Metadata.Name) + assert.Equal(t, "name", e.Name) assert.Equal(t, "FooBar", e.Kind) assert.Equal(t, "v1", e.ApiVersion) @@ -40,8 +39,8 @@ metadata: err := afero.WriteFile(fs, "foobar.yaml", []byte(` apiVersion: v1 kind: FooBar -metadata: -metadata: +name: +name: `), 0644) assert.Nil(t, err) _, err = parseEntity(fs, "foobar.yaml") diff --git a/internal/entity/repository.go b/internal/entity/repository.go index e577ae3..ce648b6 100644 --- a/internal/entity/repository.go +++ b/internal/entity/repository.go @@ -11,14 +11,14 @@ import ( type Repository struct { Entity `yaml:",inline"` - Data struct { + Spec struct { Writers []string `yaml:"writers,omitempty"` Readers []string `yaml:"readers,omitempty"` ExternalUserReaders []string `yaml:"externalUserReaders,omitempty"` ExternalUserWriters []string `yaml:"externalUserWriters,omitempty"` IsPublic bool `yaml:"public,omitempty"` IsArchived bool `yaml:"archived,omitempty"` - } `yaml:"data,omitempty"` + } `yaml:"spec,omitempty"` Owner *string `yaml:"owner,omitempty"` // implicit. team name owning the repo (if any) } @@ -70,6 +70,10 @@ func ReadRepositories(fs afero.Fs, archivedDirname string, teamDirname string, t if entry.IsDir() { continue } + // skipping files starting with '.' + if entry.Name()[0] == '.' { + continue + } if !strings.HasSuffix(entry.Name(), ".yaml") { warning = append(warning, fmt.Errorf("File %s doesn't have a .yaml extension", entry.Name())) continue @@ -81,7 +85,7 @@ func ReadRepositories(fs afero.Fs, archivedDirname string, teamDirname string, t if err := repo.Validate(filepath.Join(archivedDirname, entry.Name()), teams, externalUsers, true); err != nil { errors = append(errors, err) } else { - repos[repo.Metadata.Name] = repo + repos[repo.Name] = repo } } } @@ -120,16 +124,16 @@ func ReadRepositories(fs afero.Fs, archivedDirname string, teamDirname string, t errors = append(errors, err) } else { // check if the repository doesn't already exists - if _, exist := repos[repo.Metadata.Name]; exist { - existing := filepath.Join(archivedDirname, repo.Metadata.Name) - if repos[repo.Metadata.Name].Owner != nil { - existing = filepath.Join(teamDirname, *repos[repo.Metadata.Name].Owner, repo.Metadata.Name) + if _, exist := repos[repo.Name]; exist { + existing := filepath.Join(archivedDirname, repo.Name) + if repos[repo.Name].Owner != nil { + existing = filepath.Join(teamDirname, *repos[repo.Name].Owner, repo.Name) } - errors = append(errors, fmt.Errorf("Repository %s defined in 2 places (check %s and %s)", repo.Metadata.Name, filepath.Join(teamDirname, team.Name(), sube.Name()), existing)) + errors = append(errors, fmt.Errorf("Repository %s defined in 2 places (check %s and %s)", repo.Name, filepath.Join(teamDirname, team.Name(), sube.Name()), existing)) } else { teamname := team.Name() repo.Owner = &teamname - repos[repo.Metadata.Name] = repo + repos[repo.Name] = repo } } } @@ -151,39 +155,39 @@ func (r *Repository) Validate(filename string, teams map[string]*Team, externalU return fmt.Errorf("invalid kind: %s (check repository filename %s)", r.Kind, filename) } - if r.Metadata.Name == "" { - return fmt.Errorf("metadata.name is empty (check repository filename %s)", filename) + if r.Name == "" { + return fmt.Errorf("name is empty (check repository filename %s)", filename) } filename = filepath.Base(filename) - if r.Metadata.Name != filename[:len(filename)-len(filepath.Ext(filename))] { - return fmt.Errorf("invalid metadata.name: %s for repository filename %s", r.Metadata.Name, filename) + if r.Name != filename[:len(filename)-len(filepath.Ext(filename))] { + return fmt.Errorf("invalid name: %s for repository filename %s", r.Name, filename) } - for _, writer := range r.Data.Writers { + for _, writer := range r.Spec.Writers { if _, ok := teams[writer]; !ok { return fmt.Errorf("invalid writer: %s doesn't exist (check repository filename %s)", writer, filename) } } - for _, reader := range r.Data.Readers { + for _, reader := range r.Spec.Readers { if _, ok := teams[reader]; !ok { return fmt.Errorf("invalid reader: %s doesn't exist (check repository filename %s)", reader, filename) } } - for _, externalUserReader := range r.Data.ExternalUserReaders { + for _, externalUserReader := range r.Spec.ExternalUserReaders { if _, ok := externalUsers[externalUserReader]; !ok { return fmt.Errorf("invalid externalUserReader: %s doesn't exist in repository filename %s", externalUserReader, filename) } } - for _, externalUserWriter := range r.Data.ExternalUserWriters { + for _, externalUserWriter := range r.Spec.ExternalUserWriters { if _, ok := externalUsers[externalUserWriter]; !ok { return fmt.Errorf("invalid externalUserWriter: %s doesn't exist in repository filename %s", externalUserWriter, filename) } } - if archived != r.Data.IsArchived { + if archived != r.Spec.IsArchived { if archived { return fmt.Errorf("invalid archived: %s is in the archived directory without the `archived` boolean", filename) } else { diff --git a/internal/entity/repository_test.go b/internal/entity/repository_test.go index db0aae9..628acfc 100644 --- a/internal/entity/repository_test.go +++ b/internal/entity/repository_test.go @@ -12,9 +12,8 @@ func fixtureCreateUserTeam(t *testing.T, fs afero.Fs) { err := afero.WriteFile(fs, "users/user1.yaml", []byte(` apiVersion: v1 kind: User -metadata: - name: user1 -data: +name: user1 +spec: githubID: github1 `), 0644) assert.Nil(t, err) @@ -22,9 +21,8 @@ data: err = afero.WriteFile(fs, "users/user2.yaml", []byte(` apiVersion: v1 kind: User -metadata: - name: user2 -data: +name: user2 +spec: githubID: github2 `), 0644) assert.Nil(t, err) @@ -34,9 +32,8 @@ data: err = afero.WriteFile(fs, "teams/team1/team.yaml", []byte(` apiVersion: v1 kind: Team -metadata: - name: team1 -data: +name: team1 +spec: owners: - user1 - user2 @@ -55,8 +52,7 @@ func TestRepository(t *testing.T) { err := afero.WriteFile(fs, "teams/team1/repo1.yaml", []byte(` apiVersion: v1 kind: Repository -metadata: - name: repo1 +name: repo1 `), 0644) assert.Nil(t, err) users, errs, warns := ReadUserDirectory(fs, "users") @@ -83,8 +79,7 @@ metadata: err := afero.WriteFile(fs, "teams/team1/repo1.yaml", []byte(` apiVersion: v1 kind: Repository -metadata: - name: repo2 +name: repo2 `), 0644) assert.Nil(t, err) users, errs, warns := ReadUserDirectory(fs, "users") @@ -110,9 +105,8 @@ metadata: err := afero.WriteFile(fs, "teams/team1/repo1.yaml", []byte(` apiVersion: v1 kind: Repository -metadata: - name: repo1 -data: +name: repo1 +spec: writers: - wrongteam `), 0644) @@ -140,9 +134,8 @@ data: err := afero.WriteFile(fs, "teams/team1/repo1.yaml", []byte(` apiVersion: v1 kind: Repository -metadata: - name: repo1 -data: +name: repo1 +spec: readers: - wrongteam `), 0644) @@ -170,9 +163,8 @@ data: err := afero.WriteFile(fs, "teams/team1/repo1.yaml", []byte(` apiVersion: v1 kind: Repository -metadata: - name: repo1 -data: +name: repo1 +spec: archived: true `), 0644) assert.Nil(t, err) @@ -201,9 +193,8 @@ data: err := afero.WriteFile(fs, "archived/repo1.yaml", []byte(` apiVersion: v1 kind: Repository -metadata: - name: repo1 -data: +name: repo1 +spec: archived: true `), 0644) assert.Nil(t, err) diff --git a/internal/entity/team.go b/internal/entity/team.go index c56de48..e39bb8a 100644 --- a/internal/entity/team.go +++ b/internal/entity/team.go @@ -11,10 +11,10 @@ import ( type Team struct { Entity `yaml:",inline"` - Data struct { + Spec struct { Owners []string `yaml:"owners,omitempty"` Members []string `yaml:"members,omitempty"` - } `yaml:"data"` + } `yaml:"spec"` } /* @@ -67,6 +67,10 @@ func ReadTeamDirectory(fs afero.Fs, dirname string, users map[string]*User) (map if !e.IsDir() { continue } + // skipping files starting with '.' + if e.Name()[0] == '.' { + continue + } team, err := NewTeam(fs, filepath.Join(dirname, e.Name(), "team.yaml")) if err != nil { errors = append(errors, err) @@ -76,7 +80,7 @@ func ReadTeamDirectory(fs afero.Fs, dirname string, users map[string]*User) (map if err != nil { errors = append(errors, err) } else { - teams[team.Metadata.Name] = team + teams[team.Name] = team } } @@ -95,30 +99,30 @@ func (t *Team) Validate(dirname string, users map[string]*User) (error, []Warnin return fmt.Errorf("invalid kind: %s for team filename %s/team.yaml", t.Kind, dirname), warnings } - if t.Metadata.Name == "" { + if t.Name == "" { return fmt.Errorf("metadata.name is empty for team filename %s", dirname), warnings } - if t.Metadata.Name == "everyone" { + if t.Name == "everyone" { return fmt.Errorf("team name 'everyone' is reserved"), warnings } - if strings.HasSuffix(t.Metadata.Name, "-owners") { + if strings.HasSuffix(t.Name, "-owners") { return fmt.Errorf("metadata.name cannot finish with '-owners' for team filename %s. It is a reserved suffix", dirname), warnings } teamname := filepath.Base(dirname) - if t.Metadata.Name != teamname { - return fmt.Errorf("invalid metadata.name: %s for team filename %s/team.yaml", t.Metadata.Name, dirname), warnings + if t.Name != teamname { + return fmt.Errorf("invalid metadata.name: %s for team filename %s/team.yaml", t.Name, dirname), warnings } - for _, owner := range t.Data.Owners { + for _, owner := range t.Spec.Owners { if _, ok := users[owner]; !ok { return fmt.Errorf("invalid owner: %s doesn't exist in team filename %s/team.yaml", owner, dirname), warnings } } - for _, member := range t.Data.Members { + for _, member := range t.Spec.Members { if _, ok := users[member]; !ok { return fmt.Errorf("invalid member: %s doesn't exist in team filename %s/team.yaml", member, dirname), warnings } @@ -126,7 +130,7 @@ func (t *Team) Validate(dirname string, users map[string]*User) (error, []Warnin // warnings - if len(t.Data.Owners) < 2 { + if len(t.Spec.Owners) < 2 { warnings = append(warnings, fmt.Errorf("no enough owner for team filename %s/team.yaml", dirname)) } @@ -178,24 +182,24 @@ func ReadAndAdjustTeamDirectory(fs afero.Fs, dirname string, users map[string]*U func (t *Team) Update(fs afero.Fs, filename string, users map[string]*User) (bool, error) { changed := false owners := make([]string, 0) - for _, owner := range t.Data.Owners { + for _, owner := range t.Spec.Owners { if _, ok := users[owner]; !ok { changed = true } else { owners = append(owners, owner) } } - t.Data.Owners = owners + t.Spec.Owners = owners members := make([]string, 0) - for _, member := range t.Data.Members { + for _, member := range t.Spec.Members { if _, ok := users[member]; !ok { changed = true } else { members = append(members, member) } } - t.Data.Members = members + t.Spec.Members = members yamlTeam, err := yaml.Marshal(t) if err != nil { diff --git a/internal/entity/team_test.go b/internal/entity/team_test.go index d602e1a..411c3b7 100644 --- a/internal/entity/team_test.go +++ b/internal/entity/team_test.go @@ -12,9 +12,8 @@ func fixtureCreateUser(t *testing.T, fs afero.Fs) { err := afero.WriteFile(fs, "users/user1.yaml", []byte(` apiVersion: v1 kind: User -metadata: - name: user1 -data: +name: user1 +spec: githubID: github1 `), 0644) assert.Nil(t, err) @@ -22,9 +21,8 @@ data: err = afero.WriteFile(fs, "users/user2.yaml", []byte(` apiVersion: v1 kind: User -metadata: - name: user2 -data: +name: user2 +spec: githubID: github2 `), 0644) assert.Nil(t, err) @@ -44,9 +42,8 @@ func TestTeam(t *testing.T) { err := afero.WriteFile(fs, "teams/team1/team.yaml", []byte(` apiVersion: v1 kind: Team -metadata: - name: team1 -data: +name: team1 +spec: owners: - user1 - user2 @@ -72,9 +69,8 @@ data: err := afero.WriteFile(fs, "teams/team1/team.yaml", []byte(` apiVersion: v1 kind: Team -metadata: - name: team1 -data: +name: team1 +spec: owners: - user1 `), 0644) @@ -108,9 +104,8 @@ data: err := afero.WriteFile(fs, "teams/team1/team.yaml", []byte(` apiVersion: v1 kind: Team -metadata: - name: team1 -data: +name: team1 +spec: owners: - wronguser1 - wronguser2 @@ -136,8 +131,7 @@ data: err := afero.WriteFile(fs, "teams/team1/team.yaml", []byte(` apiVersion: v2 kind: Foo -metadata: - name: team2 +name: team2 `), 0644) assert.Nil(t, err) users, errs, warns := ReadUserDirectory(fs, "users") diff --git a/internal/entity/user.go b/internal/entity/user.go index dcf464a..0d6e178 100644 --- a/internal/entity/user.go +++ b/internal/entity/user.go @@ -11,9 +11,9 @@ import ( type User struct { Entity `yaml:",inline"` - Data struct { + Spec struct { GithubID string `yaml:"githubID"` - } `yaml:"data"` + } `yaml:"spec"` } /* @@ -66,6 +66,10 @@ func ReadUserDirectory(fs afero.Fs, dirname string) (map[string]*User, []error, if e.IsDir() { continue } + // skipping files starting with '.' + if e.Name()[0] == '.' { + continue + } if !strings.HasSuffix(e.Name(), ".yaml") { continue } @@ -77,7 +81,7 @@ func ReadUserDirectory(fs afero.Fs, dirname string) (map[string]*User, []error, if err != nil { errors = append(errors, err) } else { - users[user.Metadata.Name] = user + users[user.Name] = user } } @@ -95,16 +99,16 @@ func (u *User) Validate(filename string) error { return fmt.Errorf("invalid kind: %s for user filename %s", u.Kind, filename) } - if u.Metadata.Name == "" { + if u.Name == "" { return fmt.Errorf("metadata.name is empty for user filename %s", filename) } filename = filepath.Base(filename) - if u.Metadata.Name != filename[:len(filename)-len(filepath.Ext(filename))] { - return fmt.Errorf("invalid metadata.name: %s for user filename %s", u.Metadata.Name, filename) + if u.Name != filename[:len(filename)-len(filepath.Ext(filename))] { + return fmt.Errorf("invalid metadata.name: %s for user filename %s", u.Name, filename) } - if u.Data.GithubID == "" { + if u.Spec.GithubID == "" { return fmt.Errorf("data.githubID is empty for user filename %s", filename) } @@ -118,10 +122,10 @@ func (u *User) Equals(a *User) bool { if u.Kind != a.Kind { return false } - if u.Metadata.Name != a.Metadata.Name { + if u.Name != a.Name { return false } - if u.Data.GithubID != a.Data.GithubID { + if u.Spec.GithubID != a.Spec.GithubID { return false } diff --git a/internal/entity/user_test.go b/internal/entity/user_test.go index 726142d..eb740cb 100644 --- a/internal/entity/user_test.go +++ b/internal/entity/user_test.go @@ -17,9 +17,8 @@ func TestUser(t *testing.T) { err := afero.WriteFile(fs, "users/user1.yaml", []byte(` apiVersion: v1 kind: User -metadata: - name: user1 -data: +name: user1 +spec: githubID: github1 `), 0644) assert.Nil(t, err) @@ -30,7 +29,7 @@ data: assert.Equal(t, len(users), 1) user1 := users["user1"] assert.NotNil(t, user1) - assert.Equal(t, "github1", user1.Data.GithubID) + assert.Equal(t, "github1", user1.Spec.GithubID) }) t.Run("happy path: with --- separator", func(t *testing.T) { @@ -40,9 +39,8 @@ data: err := afero.WriteFile(fs, "users/user1.yaml", []byte(`--- apiVersion: v1 kind: User -metadata: - name: user1 -data: +name: user1 +spec: githubID: github1 `), 0644) assert.Nil(t, err) @@ -53,7 +51,7 @@ data: assert.Equal(t, len(users), 1) user1 := users["user1"] assert.NotNil(t, user1) - assert.Equal(t, "github1", user1.Data.GithubID) + assert.Equal(t, "github1", user1.Spec.GithubID) }) t.Run("not happy path: no users directory", func(t *testing.T) { @@ -71,7 +69,7 @@ data: err := afero.WriteFile(fs, "users/user1.yaml", []byte(`--- apiVersion: v1 kind: User -data: +spec: githubID: github1 `), 0644) assert.Nil(t, err) diff --git a/internal/goliac_server.go b/internal/goliac_server.go index 5622220..18c2eb1 100644 --- a/internal/goliac_server.go +++ b/internal/goliac_server.go @@ -71,9 +71,9 @@ func (g *GoliacServerImpl) GetRepositories(app.GetRepositoriesParams) middleware for _, r := range local.Repositories() { repo := models.Repository{ - Name: r.Metadata.Name, - Public: r.Data.IsPublic, - Archived: r.Data.IsArchived, + Name: r.Name, + Public: r.Spec.IsPublic, + Archived: r.Spec.IsArchived, } repositories = append(repositories, &repo) } @@ -93,7 +93,7 @@ func (g *GoliacServerImpl) GetRepository(params app.GetRepositoryParams) middlew teams := make([]*models.RepositoryDetailsTeamsItems0, 0) collaborators := make([]*models.RepositoryDetailsCollaboratorsItems0, 0) - for _, r := range repository.Data.Readers { + for _, r := range repository.Spec.Readers { team := models.RepositoryDetailsTeamsItems0{ Name: r, Access: "read", @@ -109,7 +109,7 @@ func (g *GoliacServerImpl) GetRepository(params app.GetRepositoryParams) middlew teams = append(teams, &team) } - for _, w := range repository.Data.Writers { + for _, w := range repository.Spec.Writers { team := models.RepositoryDetailsTeamsItems0{ Name: w, Access: "write", @@ -117,7 +117,7 @@ func (g *GoliacServerImpl) GetRepository(params app.GetRepositoryParams) middlew teams = append(teams, &team) } - for _, r := range repository.Data.ExternalUserReaders { + for _, r := range repository.Spec.ExternalUserReaders { collaborator := models.RepositoryDetailsCollaboratorsItems0{ Name: r, Access: "read", @@ -125,7 +125,7 @@ func (g *GoliacServerImpl) GetRepository(params app.GetRepositoryParams) middlew collaborators = append(collaborators, &collaborator) } - for _, r := range repository.Data.ExternalUserWriters { + for _, r := range repository.Spec.ExternalUserWriters { collaborator := models.RepositoryDetailsCollaboratorsItems0{ Name: r, Access: "write", @@ -134,9 +134,9 @@ func (g *GoliacServerImpl) GetRepository(params app.GetRepositoryParams) middlew } repositoryDetails := models.RepositoryDetails{ - Name: repository.Metadata.Name, - Public: repository.Data.IsPublic, - Archived: repository.Data.IsArchived, + Name: repository.Name, + Public: repository.Spec.IsPublic, + Archived: repository.Spec.IsArchived, Teams: teams, Collaborators: collaborators, } @@ -151,8 +151,8 @@ func (g *GoliacServerImpl) GetTeams(app.GetTeamsParams) middleware.Responder { for teamname, team := range local.Teams() { t := models.Team{ Name: teamname, - Members: team.Data.Members, - Owners: team.Data.Owners, + Members: team.Spec.Members, + Owners: team.Spec.Owners, } teams = append(teams, &t) @@ -174,13 +174,13 @@ func (g *GoliacServerImpl) GetTeam(params app.GetTeamParams) middleware.Responde if repo.Owner != nil && *repo.Owner == params.TeamID { repos[reponame] = repo } - for _, r := range repo.Data.Readers { + for _, r := range repo.Spec.Readers { if r == params.TeamID { repos[reponame] = repo break } } - for _, r := range repo.Data.Writers { + for _, r := range repo.Spec.Writers { if r == params.TeamID { repos[reponame] = repo break @@ -192,48 +192,48 @@ func (g *GoliacServerImpl) GetTeam(params app.GetTeamParams) middleware.Responde for reponame, repo := range repos { r := models.Repository{ Name: reponame, - Archived: repo.Data.IsArchived, - Public: repo.Data.IsPublic, + Archived: repo.Spec.IsArchived, + Public: repo.Spec.IsPublic, } repositories = append(repositories, &r) } teamDetails := models.TeamDetails{ - Owners: make([]*models.TeamDetailsOwnersItems0, len(team.Data.Owners)), - Members: make([]*models.TeamDetailsMembersItems0, len(team.Data.Members)), - Name: team.Metadata.Name, + Owners: make([]*models.TeamDetailsOwnersItems0, len(team.Spec.Owners)), + Members: make([]*models.TeamDetailsMembersItems0, len(team.Spec.Members)), + Name: team.Name, Repositories: repositories, } - for i, u := range team.Data.Owners { + for i, u := range team.Spec.Owners { if orgUser, ok := local.Users()[u]; ok { teamDetails.Owners[i] = &models.TeamDetailsOwnersItems0{ Name: u, - Githubid: orgUser.Data.GithubID, + Githubid: orgUser.Spec.GithubID, External: false, } } else { extUser := local.ExternalUsers()[u] teamDetails.Owners[i] = &models.TeamDetailsOwnersItems0{ Name: u, - Githubid: extUser.Data.GithubID, + Githubid: extUser.Spec.GithubID, External: false, } } } - for i, u := range team.Data.Members { + for i, u := range team.Spec.Members { if orgUser, ok := local.Users()[u]; ok { teamDetails.Members[i] = &models.TeamDetailsMembersItems0{ Name: u, - Githubid: orgUser.Data.GithubID, + Githubid: orgUser.Spec.GithubID, External: false, } } else { extUser := local.ExternalUsers()[u] teamDetails.Members[i] = &models.TeamDetailsMembersItems0{ Name: u, - Githubid: extUser.Data.GithubID, + Githubid: extUser.Spec.GithubID, External: false, } } @@ -250,7 +250,7 @@ func (g *GoliacServerImpl) GetCollaborators(app.GetCollaboratorsParams) middlewa for username, user := range local.ExternalUsers() { u := models.User{ Name: username, - Githubid: user.Data.GithubID, + Githubid: user.Spec.GithubID, } users = append(users, &u) } @@ -268,32 +268,32 @@ func (g *GoliacServerImpl) GetCollaborator(params app.GetCollaboratorParams) mid } collaboratordetails := models.CollaboratorDetails{ - Githubid: user.Data.GithubID, + Githubid: user.Spec.GithubID, Repositories: make([]*models.Repository, 0), } githubidToExternal := make(map[string]string) for _, e := range local.ExternalUsers() { - githubidToExternal[e.Data.GithubID] = e.Metadata.Name + githubidToExternal[e.Spec.GithubID] = e.Name } // let's sort repo per team for _, repo := range local.Repositories() { - for _, r := range repo.Data.ExternalUserReaders { + for _, r := range repo.Spec.ExternalUserReaders { if r == params.CollaboratorID { collaboratordetails.Repositories = append(collaboratordetails.Repositories, &models.Repository{ - Name: repo.Metadata.Name, - Public: repo.Data.IsPublic, - Archived: repo.Data.IsArchived, + Name: repo.Name, + Public: repo.Spec.IsPublic, + Archived: repo.Spec.IsArchived, }) } } - for _, r := range repo.Data.ExternalUserWriters { + for _, r := range repo.Spec.ExternalUserWriters { if r == params.CollaboratorID { collaboratordetails.Repositories = append(collaboratordetails.Repositories, &models.Repository{ - Name: repo.Metadata.Name, - Public: repo.Data.IsPublic, - Archived: repo.Data.IsArchived, + Name: repo.Name, + Public: repo.Spec.IsPublic, + Archived: repo.Spec.IsArchived, }) } } @@ -309,7 +309,7 @@ func (g *GoliacServerImpl) GetUsers(app.GetUsersParams) middleware.Responder { for username, user := range local.Users() { u := models.User{ Name: username, - Githubid: user.Data.GithubID, + Githubid: user.Spec.GithubID, } users = append(users, &u) } @@ -326,7 +326,7 @@ func (g *GoliacServerImpl) GetUser(params app.GetUserParams) middleware.Responde } userdetails := models.UserDetails{ - Githubid: user.Data.GithubID, + Githubid: user.Spec.GithubID, Teams: make([]*models.Team, 0), Repositories: make([]*models.Repository, 0), } @@ -334,23 +334,23 @@ func (g *GoliacServerImpl) GetUser(params app.GetUserParams) middleware.Responde // [teamname]team userTeams := make(map[string]*models.Team) for teamname, team := range local.Teams() { - for _, owner := range team.Data.Owners { + for _, owner := range team.Spec.Owners { if owner == params.UserID { team := models.Team{ Name: teamname, - Members: team.Data.Members, - Owners: team.Data.Owners, + Members: team.Spec.Members, + Owners: team.Spec.Owners, } userTeams[teamname] = &team break } } - for _, member := range team.Data.Members { + for _, member := range team.Spec.Members { if member == params.UserID { team := models.Team{ Name: teamname, - Members: team.Data.Members, - Owners: team.Data.Owners, + Members: team.Spec.Members, + Owners: team.Spec.Owners, } userTeams[teamname] = &team break @@ -369,19 +369,19 @@ func (g *GoliacServerImpl) GetUser(params app.GetUserParams) middleware.Responde if _, ok := teamRepo[*repo.Owner]; !ok { teamRepo[*repo.Owner] = make(map[string]*entity.Repository) } - teamRepo[*repo.Owner][repo.Metadata.Name] = repo + teamRepo[*repo.Owner][repo.Name] = repo } - for _, r := range repo.Data.Readers { + for _, r := range repo.Spec.Readers { if _, ok := teamRepo[r]; !ok { teamRepo[r] = make(map[string]*entity.Repository) } - teamRepo[r][repo.Metadata.Name] = repo + teamRepo[r][repo.Name] = repo } - for _, w := range repo.Data.Writers { + for _, w := range repo.Spec.Writers { if _, ok := teamRepo[w]; !ok { teamRepo[w] = make(map[string]*entity.Repository) } - teamRepo[w][repo.Metadata.Name] = repo + teamRepo[w][repo.Name] = repo } } @@ -397,9 +397,9 @@ func (g *GoliacServerImpl) GetUser(params app.GetUserParams) middleware.Responde for _, r := range userRepos { repo := models.Repository{ - Name: r.Metadata.Name, - Public: r.Data.IsPublic, - Archived: r.Data.IsArchived, + Name: r.Name, + Public: r.Spec.IsPublic, + Archived: r.Spec.IsArchived, } userdetails.Repositories = append(userdetails.Repositories, &repo) } diff --git a/internal/goliac_server_test.go b/internal/goliac_server_test.go index 4b9cca7..8d68b90 100644 --- a/internal/goliac_server_test.go +++ b/internal/goliac_server_test.go @@ -46,16 +46,16 @@ func fixtureGoliacLocal() *GoliacLocalMock { // users user1 := entity.User{} - user1.Metadata.Name = "user1" - user1.Data.GithubID = "github1" + user1.Name = "user1" + user1.Spec.GithubID = "github1" user2 := entity.User{} - user2.Metadata.Name = "user2" - user2.Data.GithubID = "github2" + user2.Name = "user2" + user2.Spec.GithubID = "github2" user3 := entity.User{} - user3.Metadata.Name = "user3" - user3.Data.GithubID = "github3" + user3.Name = "user3" + user3.Spec.GithubID = "github3" l.users["user1"] = &user1 l.users["user2"] = &user2 @@ -63,39 +63,39 @@ func fixtureGoliacLocal() *GoliacLocalMock { // external users userE1 := entity.User{} - userE1.Metadata.Name = "userE1" - userE1.Data.GithubID = "githubE1" + userE1.Name = "userE1" + userE1.Spec.GithubID = "githubE1" l.externalUsers["userE1"] = &userE1 // teams ateam := entity.Team{} - ateam.Metadata.Name = "ateam" - ateam.Data.Owners = []string{"user1"} - ateam.Data.Members = []string{"user3"} + ateam.Name = "ateam" + ateam.Spec.Owners = []string{"user1"} + ateam.Spec.Members = []string{"user3"} mixteam := entity.Team{} - mixteam.Metadata.Name = "mixteam" - mixteam.Data.Owners = []string{"user1"} - mixteam.Data.Members = []string{"userE1"} + mixteam.Name = "mixteam" + mixteam.Spec.Owners = []string{"user1"} + mixteam.Spec.Members = []string{"userE1"} l.teams["ateam"] = &ateam l.teams["mixteam"] = &mixteam // repositories repoA := entity.Repository{} - repoA.Metadata.Name = "repoA" + repoA.Name = "repoA" ownerA := "ateam" repoA.Owner = &ownerA - repoA.Data.Readers = []string{} - repoA.Data.Writers = []string{} + repoA.Spec.Readers = []string{} + repoA.Spec.Writers = []string{} repoB := entity.Repository{} - repoB.Metadata.Name = "repoB" + repoB.Name = "repoB" ownerB := "mixteam" repoB.Owner = &ownerB - repoB.Data.Readers = []string{"ateam"} - repoB.Data.Writers = []string{} + repoB.Spec.Readers = []string{"ateam"} + repoB.Spec.Writers = []string{} l.repositories["repoA"] = &repoA l.repositories["repoB"] = &repoB diff --git a/internal/scaffold.go b/internal/scaffold.go index 86efbd9..a0f7f59 100644 --- a/internal/scaffold.go +++ b/internal/scaffold.go @@ -142,8 +142,8 @@ func (s *Scaffold) generateTeams(fs afero.Fs, teamspath string, usermap map[stri lTeam := entity.Team{} lTeam.ApiVersion = "v1" lTeam.Kind = "Team" - lTeam.Metadata.Name = team - lTeam.Data.Owners = t.Members + lTeam.Name = team + lTeam.Spec.Owners = t.Members out, err := yaml.Marshal(&lTeam) if err == nil { @@ -160,21 +160,21 @@ func (s *Scaffold) generateTeams(fs afero.Fs, teamspath string, usermap map[stri lRepo := entity.Repository{} lRepo.ApiVersion = "v1" lRepo.Kind = "Repository" - lRepo.Metadata.Name = r - lRepo.Data.Writers = repoWrite[r] - lRepo.Data.Readers = repoRead[r] + lRepo.Name = r + lRepo.Spec.Writers = repoWrite[r] + lRepo.Spec.Readers = repoRead[r] // removing team name from writer - for i, t := range lRepo.Data.Writers { + for i, t := range lRepo.Spec.Writers { if t == team { - lRepo.Data.Writers = append(lRepo.Data.Writers[:i], lRepo.Data.Writers[i+1:]...) + lRepo.Spec.Writers = append(lRepo.Spec.Writers[:i], lRepo.Spec.Writers[i+1:]...) break } } // removing team owner (especially for the special case teams repo) - for i, t := range lRepo.Data.Writers { + for i, t := range lRepo.Spec.Writers { if strings.HasSuffix(t, "-owners") { - lRepo.Data.Writers = append(lRepo.Data.Writers[:i], lRepo.Data.Writers[i+1:]...) + lRepo.Spec.Writers = append(lRepo.Spec.Writers[:i], lRepo.Spec.Writers[i+1:]...) break } } @@ -204,8 +204,8 @@ func (s *Scaffold) generateTeams(fs afero.Fs, teamspath string, usermap map[stri lTeam := entity.Team{} lTeam.ApiVersion = "v1" lTeam.Kind = "Team" - lTeam.Metadata.Name = team - lTeam.Data.Owners = t.Members + lTeam.Name = team + lTeam.Spec.Owners = t.Members out, err := yaml.Marshal(&lTeam) if err == nil { @@ -237,7 +237,7 @@ func (s *Scaffold) generateUsers(fs afero.Fs, userspath string) (map[string]stri if len(users) > 0 && err == nil { for username, user := range users { - usermap[user.Data.GithubID] = username + usermap[user.Spec.GithubID] = username out, err := yaml.Marshal(&user) if err == nil { if err := writeFile(path.Join(userspath, "org", username+".yaml"), out, fs); err != nil { @@ -254,8 +254,8 @@ func (s *Scaffold) generateUsers(fs afero.Fs, userspath string) (map[string]stri user := entity.User{} user.ApiVersion = "v1" user.Kind = "User" - user.Metadata.Name = githubid - user.Data.GithubID = githubid + user.Name = githubid + user.Spec.GithubID = githubid out, err := yaml.Marshal(&user) if err == nil { @@ -274,20 +274,20 @@ func (s *Scaffold) generateUsers(fs afero.Fs, userspath string) (map[string]stri func (s *Scaffold) generateRuleset(fs afero.Fs, rulesetspath string) error { ruleset := `apiVersion: v1 kind: Ruleset -metadata: - name: default -enforcement: active -bypassapps: - - appname: goliac-project-app - mode: always -on: - include: - - "~DEFAULT_BRANCH" - -rules: - - ruletype: pull_request - parameters: - requiredApprovingReviewCount: 1 +name: default +spec: + enforcement: active + bypassapps: + - appname: goliac-project-app + mode: always + on: + include: + - "~DEFAULT_BRANCH" + + rules: + - ruletype: pull_request + parameters: + requiredApprovingReviewCount: 1 ` if err := writeFile(path.Join(rulesetspath, "default.yaml"), []byte(ruleset), fs); err != nil { return err @@ -362,8 +362,7 @@ On a given team subdirectory you can create a repository definition via a yaml f ` + "```" + ` apiVersion: v1 kind: Repository -metadata: - name: awesome-repository +name: awesome-repository ` + "```" + ` This will create a ` + "`" + `awesome-repository` + "`" + ` repository under your organization, that will be @@ -375,9 +374,8 @@ You can of course tweak that: ` + "```" + ` apiVersion: v1 kind: Repository -metadata: - name: awesome-repository -data: +name: awesome-repository +spec: public: true writers: - anotherteamA @@ -398,9 +396,8 @@ If you want to create a new team (like ` + "`" + `foobar` + "`" + `), you need t ` + "```" + ` apiVersion: v1 kind: Team -metadata: - name: foobar -data: +name: foobar +spec: owners: - user1 - user2 @@ -423,9 +420,8 @@ You can archive a repository, by a PR that ` + "```" + ` apiVersion: v1 kind: Repository -metadata: - name: awesome-repository -data: +name: awesome-repository +spec: archived: true ` + "```" + ` diff --git a/internal/scaffold_test.go b/internal/scaffold_test.go index 7e9704a..c9cfc66 100644 --- a/internal/scaffold_test.go +++ b/internal/scaffold_test.go @@ -116,22 +116,22 @@ func LoadGithubSamlUsersMock() (map[string]*entity.User, error) { user1 := &entity.User{} user1.ApiVersion = "v1" user1.Kind = "User" - user1.Metadata.Name = "user1@company.com" - user1.Data.GithubID = "githubid1" + user1.Name = "user1@company.com" + user1.Spec.GithubID = "githubid1" users["user1@company.com"] = user1 user2 := &entity.User{} user2.ApiVersion = "v1" user2.Kind = "User" - user2.Metadata.Name = "user2@company.com" - user2.Data.GithubID = "githubid2" + user2.Name = "user2@company.com" + user2.Spec.GithubID = "githubid2" users["user2@company.com"] = user2 user3 := &entity.User{} user3.ApiVersion = "v1" user3.Kind = "User" - user3.Metadata.Name = "user3@company.com" - user3.Data.GithubID = "githubid3" + user3.Name = "user3@company.com" + user3.Spec.GithubID = "githubid3" users["user3@company.com"] = user3 return users, nil @@ -290,8 +290,8 @@ func TestScaffoldFull(t *testing.T) { var at entity.Team err = yaml.Unmarshal(regularTeam, &at) assert.Nil(t, err) - assert.Equal(t, "regular", at.Metadata.Name) - assert.Equal(t, 2, len(at.Data.Owners)) // githubid2,githubid3 + assert.Equal(t, "regular", at.Name) + assert.Equal(t, 2, len(at.Spec.Owners)) // githubid2,githubid3 repo1, err := afero.ReadFile(fs, "/teams/regular/repo1.yaml") assert.Nil(t, err) @@ -299,8 +299,8 @@ func TestScaffoldFull(t *testing.T) { var r1 entity.Repository err = yaml.Unmarshal(repo1, &r1) assert.Nil(t, err) - assert.Equal(t, "repo1", r1.Metadata.Name) - assert.Equal(t, 0, len(r1.Data.Writers)) // regular -> not counted + assert.Equal(t, "repo1", r1.Name) + assert.Equal(t, 0, len(r1.Spec.Writers)) // regular -> not counted repo2, err := afero.ReadFile(fs, "/teams/admin/repo2.yaml") assert.Nil(t, err) @@ -308,7 +308,7 @@ func TestScaffoldFull(t *testing.T) { var r2 entity.Repository err = yaml.Unmarshal(repo2, &r2) assert.Nil(t, err) - assert.Equal(t, "repo2", r2.Metadata.Name) - assert.Equal(t, 1, len(r2.Data.Readers)) // regular + assert.Equal(t, "repo2", r2.Name) + assert.Equal(t, 1, len(r2.Spec.Readers)) // regular }) }