Skip to content

Commit bef3574

Browse files
authored
support configurable digger organisation for digger rbac (#420)
* support configurable digger organisation for digger
1 parent 81a192d commit bef3574

File tree

9 files changed

+61
-51
lines changed

9 files changed

+61
-51
lines changed

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ inputs:
7878
description: Digger hostname
7979
required: false
8080
default: 'https://cloud.digger.dev'
81+
digger-organisation:
82+
description: The name of your digger organisation
83+
required: false
8184
setup-tfenv:
8285
description: Setup tfenv
8386
required: false
@@ -188,6 +191,7 @@ runs:
188191
ACTIVATE_VENV: ${{ inputs.setup-checkov == 'true' }}
189192
DISABLE_LOCKING: ${{ inputs.disable-locking == 'true' }}
190193
DIGGER_TOKEN: ${{ inputs.digger-token }}
194+
DIGGER_ORGANISATION: ${{ inputs.digger-organisation }}
191195
DIGGER_HOSTNAME: ${{ inputs.digger-hostname }}
192196
ACCUMULATE_PLANS: ${{ inputs.post-plans-as-one-comment == 'true' }}
193197
REPORTING_STRATEGY: ${{ inputs.reporting-strategy }}

cmd/digger/main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,15 @@ func main() {
333333
}
334334
var policyChecker core_policy.Checker
335335
if os.Getenv("DIGGER_TOKEN") != "" {
336+
if os.Getenv("DIGGER_ORGANISATION") == "" {
337+
log.Fatalf("Token specified but missing organisation: DIGGER_ORGANISATION. Please set this value in action configuration.")
338+
}
336339
policyChecker = policy.DiggerPolicyChecker{
337340
PolicyProvider: &policy.DiggerHttpPolicyProvider{
338-
DiggerHost: os.Getenv("DIGGER_HOSTNAME"),
339-
AuthToken: os.Getenv("DIGGER_TOKEN"),
340-
HttpClient: http.DefaultClient,
341+
DiggerHost: os.Getenv("DIGGER_HOSTNAME"),
342+
DiggerOrganisation: os.Getenv("DIGGER_ORGANISATION"),
343+
AuthToken: os.Getenv("DIGGER_TOKEN"),
344+
HttpClient: http.DefaultClient,
341345
}}
342346
} else {
343347
policyChecker = policy.NoOpPolicyChecker{}

cmd/digger/main_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ func TestGitHubNewPullRequestContext(t *testing.T) {
889889
PrNumber: prNumber,
890890
}
891891
commandsToRunPerProject, _, err := github.ConvertGithubEventToCommands(ghEvent, impactedProjects, requestedProject, map[string]configuration.Workflow{})
892-
_, _, err = digger.RunCommandsPerProject(commandsToRunPerProject, &depGraph, context.RepositoryOwner, context.Repository, eventName, prNumber, prManager, lock, reporter, planStorage, policyChecker, "")
892+
_, _, err = digger.RunCommandsPerProject(commandsToRunPerProject, &depGraph, context.Repository, context.Repository, eventName, prNumber, prManager, lock, reporter, planStorage, policyChecker, "")
893893

894894
assert.NoError(t, err)
895895
if err != nil {
@@ -919,10 +919,7 @@ func TestGitHubNewCommentContext(t *testing.T) {
919919
policyChecker := &utils.MockPolicyChecker{}
920920

921921
commandsToRunPerProject, _, err := github.ConvertGithubEventToCommands(ghEvent, impactedProjects, requestedProject, map[string]configuration.Workflow{})
922-
_, _, err = digger.RunCommandsPerProject(commandsToRunPerProject, &depGraph, context.RepositoryOwner, context.Repository, eventName, prNumber, prManager, lock, reporter, planStorage, policyChecker, "")
923-
924-
_, _, err = digger.RunCommandsPerProject(commandsToRunPerProject, &depGraph, context.RepositoryOwner, context.Repository, eventName, prNumber, prManager, lock, reporter, planStorage, policyChecker, "")
925-
922+
_, _, err = digger.RunCommandsPerProject(commandsToRunPerProject, &depGraph, context.Repository, context.Repository, eventName, prNumber, prManager, lock, reporter, planStorage, policyChecker, "")
926923
assert.NoError(t, err)
927924
if err != nil {
928925
fmt.Println(err)

go.sum

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRB
2929
github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo=
3030
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q=
3131
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE=
32-
github.com/aws/aws-sdk-go v1.44.282 h1:ZPB9QhwxmMIEC8ja0DdFowOl5fODWaZ6s2cZ40fx6r8=
33-
github.com/aws/aws-sdk-go v1.44.282/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
3432
github.com/aws/aws-sdk-go v1.44.291 h1:JVgIyvdYm/A6iCHD0UIS/Hvu/GVHjpW7bN3mwG6sHlU=
3533
github.com/aws/aws-sdk-go v1.44.291/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
3634
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
@@ -44,7 +42,6 @@ github.com/caarlos0/env/v8 v8.0.0/go.mod h1:7K4wMY9bH0esiXSSHlfHLX5xKGQMnkH5Fk4T
4442
github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+MN3u4=
4543
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
4644
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
47-
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
4845
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
4946
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
5047
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
@@ -74,7 +71,6 @@ github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
7471
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
7572
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
7673
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
77-
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
7874
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
7975
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
8076
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
@@ -83,7 +79,6 @@ github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre
8379
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
8480
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
8581
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
86-
github.com/golang-jwt/jwt v3.2.1+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
8782
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
8883
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
8984
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
@@ -118,8 +113,6 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
118113
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
119114
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
120115
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
121-
github.com/google/go-github/v53 v53.1.0 h1:mKJnR9lzZwD1fvbp27aK1i6rxyAbycWsXlN+r9JKPqM=
122-
github.com/google/go-github/v53 v53.1.0/go.mod h1:XhFRObz+m/l+UCm9b7KSIC3lT3NWSXGt7mOsAWEloao=
123116
github.com/google/go-github/v53 v53.2.0 h1:wvz3FyF53v4BK+AsnvCmeNhf8AkTaeh2SoYu/XUvTtI=
124117
github.com/google/go-github/v53 v53.2.0/go.mod h1:XhFRObz+m/l+UCm9b7KSIC3lT3NWSXGt7mOsAWEloao=
125118
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
@@ -146,9 +139,6 @@ github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9Y
146139
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
147140
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
148141
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
149-
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
150-
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
151-
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
152142
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
153143
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
154144
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
@@ -159,9 +149,6 @@ github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfr
159149
github.com/microsoft/azure-devops-go-api/azuredevops v1.0.0-b5 h1:YH424zrwLTlyHSH/GzLMJeu5zhYVZSx5RQxGKm1h96s=
160150
github.com/microsoft/azure-devops-go-api/azuredevops v1.0.0-b5/go.mod h1:PoGiBqKSQK1vIfQ+yVaFcGjDySHvym6FM1cNYnwzbrY=
161151
github.com/miekg/dns v1.1.43 h1:JKfpVSCB84vrAmHzyrsxB5NAr5kLoMXZArPSw7Qlgyg=
162-
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
163-
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
164-
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
165152
github.com/open-policy-agent/opa v0.53.1 h1:APN8iA7Txgel13kSkc6S8dbUulydiPojXt6iyubmB7Q=
166153
github.com/open-policy-agent/opa v0.53.1/go.mod h1:j3wl8FqSz/+u33Scl72Ms2wxkZx4yZPdqSCrOqBqdsA=
167154
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
@@ -196,8 +183,6 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
196183
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
197184
github.com/tchap/go-patricia/v2 v2.3.1 h1:6rQp39lgIYZ+MHmdEq4xzuk1t7OdC35z/xm0BGhTkes=
198185
github.com/tchap/go-patricia/v2 v2.3.1/go.mod h1:VZRHKAb53DLaG+nA9EaYYiaEx6YztwDlLElMsnSHD4k=
199-
github.com/xanzy/go-gitlab v0.85.0 h1:E/wjnsd/mM5kV6O9y5+i6zxjx+wfAwa97sgcT1ETNwk=
200-
github.com/xanzy/go-gitlab v0.85.0/go.mod h1:5ryv+MnpZStBH8I/77HuQBsMbBGANtVpLWC15qOjWAw=
201186
github.com/xanzy/go-gitlab v0.86.0 h1:jR8V9cK9jXRQDb46KOB20NCF3ksY09luaG0IfXE6p7w=
202187
github.com/xanzy/go-gitlab v0.86.0/go.mod h1:5ryv+MnpZStBH8I/77HuQBsMbBGANtVpLWC15qOjWAw=
203188
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo=

pkg/core/policy/policy.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package policy
22

3+
import "digger/pkg/ci"
4+
35
type Provider interface {
46
GetPolicy(namespace string, projectname string) (string, error)
57
}
68

79
type Checker interface {
8-
Check(organisation string, namespace string, projectname string, command string, requestedBy string) (bool, error)
10+
Check(ciService ci.CIService, SCMOrganisation string, SCMrepository string, projectname string, command string, requestedBy string) (bool, error)
911
}

pkg/digger/digger.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,17 @@ func RunCommandsPerProject(
7676
) (bool, bool, error) {
7777
appliesPerProject := make(map[string]bool)
7878

79-
organisation := strings.Split(projectNamespace, "/")[0]
79+
splits := strings.Split(projectNamespace, "/")
80+
SCMOrganisation := splits[0]
81+
SCMrepository := splits[1]
8082

8183
commandsPerProject = SortedCommandsByDependency(commandsPerProject, dependencyGraph)
8284

8385
for _, projectCommands := range commandsPerProject {
8486
for _, command := range projectCommands.Commands {
8587
fmt.Printf("Running '%s' for project '%s'\n", command, projectCommands.ProjectName)
8688

87-
allowedToPerformCommand, err := policyChecker.Check(organisation, projectNamespace, projectCommands.ProjectName, command, requestedBy)
89+
allowedToPerformCommand, err := policyChecker.Check(ciService, SCMOrganisation, SCMrepository, projectCommands.ProjectName, command, requestedBy)
8890

8991
if err != nil {
9092
return false, false, fmt.Errorf("error checking policy: %v", err)

pkg/policy/policy.go

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,29 @@ import (
88
"github.com/open-policy-agent/opa/rego"
99
"io"
1010
"net/http"
11-
"strings"
1211
)
1312

1413
type PolicyProvider interface {
15-
GetPolicy(organisation string, namespace string, projectname string) (string, error)
14+
GetPolicy(organisation string, repository string, projectname string) (string, error)
15+
GetOrganisation() string
1616
}
1717

1818
type DiggerHttpPolicyProvider struct {
19-
DiggerHost string
20-
AuthToken string
21-
HttpClient *http.Client
19+
DiggerHost string
20+
DiggerOrganisation string
21+
AuthToken string
22+
HttpClient *http.Client
2223
}
2324

2425
type NoOpPolicyChecker struct {
2526
}
2627

27-
func (p NoOpPolicyChecker) Check(_ string, _ string, _ string, _ string, _ string) (bool, error) {
28+
func (p NoOpPolicyChecker) Check(_ ci.CIService, _ string, _ string, _ string, _ string, _ string) (bool, error) {
2829
return true, nil
2930
}
3031

31-
func (p *DiggerHttpPolicyProvider) getPolicyForOrganisation(organisation string) (string, *http.Response, error) {
32-
32+
func getPolicyForOrganisation(p *DiggerHttpPolicyProvider) (string, *http.Response, error) {
33+
organisation := p.DiggerOrganisation
3334
req, err := http.NewRequest("GET", p.DiggerHost+"/orgs/"+organisation+"/access-policy", nil)
3435
if err != nil {
3536
return "", nil, err
@@ -49,10 +50,8 @@ func (p *DiggerHttpPolicyProvider) getPolicyForOrganisation(organisation string)
4950
return string(body), resp, nil
5051
}
5152

52-
func (p *DiggerHttpPolicyProvider) getPolicyForNamespace(namespace string, projectName string) (string, *http.Response, error) {
53-
54-
// fetch RBAC policies for projectfrom Digger API
55-
namespace = strings.ReplaceAll(namespace, "/", "-")
53+
func getPolicyForNamespace(p *DiggerHttpPolicyProvider, namespace string, projectName string) (string, *http.Response, error) {
54+
// fetch RBAC policies for project from Digger API
5655
req, err := http.NewRequest("GET", p.DiggerHost+"/repos/"+namespace+"/projects/"+projectName+"/access-policy", nil)
5756

5857
if err != nil {
@@ -75,15 +74,17 @@ func (p *DiggerHttpPolicyProvider) getPolicyForNamespace(namespace string, proje
7574
}
7675

7776
// GetPolicy fetches policy for particular project, if not found then it will fallback to org level policy
78-
func (p *DiggerHttpPolicyProvider) GetPolicy(organisation string, namespace string, projectName string) (string, error) {
79-
content, resp, err := p.getPolicyForNamespace(namespace, projectName)
77+
func (p *DiggerHttpPolicyProvider) GetPolicy(organisation string, repo string, projectName string) (string, error) {
78+
namespace := fmt.Sprintf("%v-%v", organisation, repo)
79+
content, resp, err := getPolicyForNamespace(p, namespace, projectName)
8080
if err != nil {
8181
return "", err
8282
}
83-
if resp.StatusCode == 200 {
83+
84+
if resp.StatusCode == 200 && content != "" {
8485
return content, nil
8586
} else if resp.StatusCode == 404 {
86-
content, resp, err := p.getPolicyForOrganisation(organisation)
87+
content, resp, err := getPolicyForOrganisation(p)
8788
if err != nil {
8889
return "", err
8990
}
@@ -99,15 +100,18 @@ func (p *DiggerHttpPolicyProvider) GetPolicy(organisation string, namespace stri
99100
}
100101
}
101102

103+
func (p *DiggerHttpPolicyProvider) GetOrganisation() string {
104+
return p.DiggerOrganisation
105+
}
106+
102107
type DiggerPolicyChecker struct {
103108
PolicyProvider PolicyProvider
104-
ciService ci.CIService
105109
}
106110

107-
func (p DiggerPolicyChecker) Check(organisation string, namespace string, projectName string, command string, requestedBy string) (bool, error) {
108-
policy, err := p.PolicyProvider.GetPolicy(organisation, namespace, projectName)
109-
110-
teams, err := p.ciService.GetUserTeams(organisation, requestedBy)
111+
func (p DiggerPolicyChecker) Check(ciService ci.CIService, SCMOrganisation string, SCMrepository string, projectName string, command string, requestedBy string) (bool, error) {
112+
organisation := p.PolicyProvider.GetOrganisation()
113+
policy, err := p.PolicyProvider.GetPolicy(organisation, SCMrepository, projectName)
114+
teams, err := ciService.GetUserTeams(SCMOrganisation, requestedBy)
111115
if err != nil {
112116
fmt.Printf("Error while fetching user teams for CI service: %v", err)
113117
return false, err

pkg/policy/policy_test.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
type OpaExamplePolicyProvider struct {
99
}
1010

11-
func (s *OpaExamplePolicyProvider) GetPolicy(_ string, _ string, _ string) (string, error) {
11+
func (s *OpaExamplePolicyProvider) GetPolicy(_ string, _ string) (string, error) {
1212
return "package digger\n" +
1313
"\n" +
1414
"# user-role assignments\n" +
@@ -41,6 +41,10 @@ func (s *OpaExamplePolicyProvider) GetPolicy(_ string, _ string, _ string) (stri
4141
"}", nil
4242
}
4343

44+
func (s *OpaExamplePolicyProvider) GetOrganisation() string {
45+
return "ORGANISATIONDIGGER"
46+
}
47+
4448
type DiggerExamplePolicyProvider struct {
4549
}
4650

@@ -60,6 +64,10 @@ func (s *DiggerExamplePolicyProvider) GetPolicy(_ string, _ string, _ string) (s
6064
"", nil
6165
}
6266

67+
func (s *DiggerExamplePolicyProvider) GetOrganisation() string {
68+
return "ORGANISATIONDIGGER"
69+
}
70+
6371
type DiggerExamplePolicyProvider2 struct {
6472
}
6573

@@ -82,6 +90,10 @@ func (s *DiggerExamplePolicyProvider2) GetPolicy(_ string, _ string, _ string) (
8290
"", nil
8391
}
8492

93+
func (s *DiggerExamplePolicyProvider2) GetOrganisation() string {
94+
return "ORGANISATIONDIGGER"
95+
}
96+
8597
func TestDiggerPolicyChecker_Check(t *testing.T) {
8698
type fields struct {
8799
PolicyProvider PolicyProvider
@@ -145,9 +157,9 @@ func TestDiggerPolicyChecker_Check(t *testing.T) {
145157
t.Run(tt.name, func(t *testing.T) {
146158
var p = &DiggerPolicyChecker{
147159
PolicyProvider: tt.fields.PolicyProvider,
148-
ciService: utils.MockPullRequestManager{Teams: []string{"engineering"}},
149160
}
150-
got, err := p.Check(tt.organisation, tt.name, tt.name, tt.command, tt.requestedBy)
161+
ciService := utils.MockPullRequestManager{Teams: []string{"engineering"}}
162+
got, err := p.Check(ciService, tt.organisation, tt.name, tt.name, tt.command, tt.requestedBy)
151163
if (err != nil) != tt.wantErr {
152164
t.Errorf("DiggerPolicyChecker.Check() error = %v, wantErr %v", err, tt.wantErr)
153165
return

pkg/utils/mocks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (lock *MockLock) GetLock(resource string) (*int, error) {
4444
type MockPolicyChecker struct {
4545
}
4646

47-
func (t MockPolicyChecker) Check(organisation string, namespace string, projectname string, command string, requestedBy string) (bool, error) {
47+
func (t MockPolicyChecker) Check(ciService ci.CIService, SCMOrganisation string, SCMrepository string, projectName string, command string, requestedBy string) (bool, error) {
4848
return false, nil
4949
}
5050

0 commit comments

Comments
 (0)