-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
exceptions.go
33 lines (29 loc) · 1.06 KB
/
exceptions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package rego
import (
"context"
"fmt"
)
func (s *Scanner) isIgnored(ctx context.Context, namespace, ruleName string, input interface{}) (bool, error) {
if ignored, err := s.isNamespaceIgnored(ctx, namespace, input); err != nil {
return false, err
} else if ignored {
return true, nil
}
return s.isRuleIgnored(ctx, namespace, ruleName, input)
}
func (s *Scanner) isNamespaceIgnored(ctx context.Context, namespace string, input interface{}) (bool, error) {
exceptionQuery := fmt.Sprintf("data.namespace.exceptions.exception[_] == %q", namespace)
result, _, err := s.runQuery(ctx, exceptionQuery, input, true)
if err != nil {
return false, fmt.Errorf("query namespace exceptions: %w", err)
}
return result.Allowed(), nil
}
func (s *Scanner) isRuleIgnored(ctx context.Context, namespace, ruleName string, input interface{}) (bool, error) {
exceptionQuery := fmt.Sprintf("endswith(%q, data.%s.exception[_][_])", ruleName, namespace)
result, _, err := s.runQuery(ctx, exceptionQuery, input, true)
if err != nil {
return false, err
}
return result.Allowed(), nil
}