Skip to content

Commit

Permalink
Merge pull request #56 from nzin/refactorEntities
Browse files Browse the repository at this point in the history
refactor entities
  • Loading branch information
nzin-alayacare authored Sep 9, 2023
2 parents 02ebd3b + c5512e3 commit 214c5b9
Show file tree
Hide file tree
Showing 21 changed files with 461 additions and 476 deletions.
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
```

Expand Down
35 changes: 17 additions & 18 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

```
Expand Down Expand Up @@ -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
```
4 changes: 2 additions & 2 deletions internal/engine/githubsaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
42 changes: 21 additions & 21 deletions internal/engine/goliac_reconciliator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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
}
}

Expand Down Expand Up @@ -249,15 +249,15 @@ 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 ;-)
if lRepo.Owner != nil {
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))
}

Expand All @@ -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,
Expand Down Expand Up @@ -431,25 +431,25 @@ 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 {
if match.Match([]byte(slug.Make(reponame))) {
grs.Repositories = append(grs.Repositories, slug.Make(reponame))
}
}
lgrs[rs.Metadata.Name] = &grs
lgrs[rs.Name] = &grs
}

// prepare remote comparable
Expand Down
Loading

0 comments on commit 214c5b9

Please sign in to comment.