@@ -73,23 +73,25 @@ func (p *DiggerHttpPolicyProvider) getPolicyForNamespace(namespace string, proje
7373
7474}
7575
76- // GetPolicy fetches policy for entire organisation, if not found for organisation then it will fetch it for project
76+ // GetPolicy fetches policy for particular project, if not found then it will fallback to org level policy
7777func (p * DiggerHttpPolicyProvider ) GetPolicy (organisation string , namespace string , projectName string ) (string , error ) {
78- content , resp , err := p .getPolicyForOrganisation ( organisation )
78+ content , resp , err := p .getPolicyForNamespace ( namespace , projectName )
7979 if err != nil {
8080 return "" , err
8181 }
8282 if resp .StatusCode == 200 {
8383 return content , nil
8484 } else if resp .StatusCode == 404 {
85- content , resp , err := p .getPolicyForNamespace ( namespace , projectName )
85+ content , resp , err := p .getPolicyForOrganisation ( organisation )
8686 if err != nil {
8787 return "" , err
8888 }
8989 if resp .StatusCode == 200 {
9090 return content , nil
91+ } else if resp .StatusCode == 404 {
92+ return "" , nil
9193 } else {
92- return "" , errors .New (fmt .Sprintf ("unexpected response while fetching namespace policy: %v, code %v" , content , resp .StatusCode ))
94+ return "" , errors .New (fmt .Sprintf ("unexpected response while fetching organisation policy: %v, code %v" , content , resp .StatusCode ))
9395 }
9496 } else {
9597 return "" , errors .New (fmt .Sprintf ("unexpected response while fetching org policy: %v code %v" , content , resp .StatusCode ))
@@ -106,6 +108,11 @@ func (p DiggerPolicyChecker) Check(organisation string, namespace string, projec
106108 if err != nil {
107109 return false , err
108110 }
111+
112+ if policy == "" {
113+ return true , nil
114+ }
115+
109116 ctx := context .Background ()
110117 fmt .Printf ("DEBUG: passing the following input policy: %v ||| text: %v" , input , policy )
111118 query , err := rego .New (
0 commit comments