Skip to content

Commit

Permalink
Lint findings and misc cleanups (#998)
Browse files Browse the repository at this point in the history
* Address g3 lint findings

* Add extension scoped messages to conformance tests
  • Loading branch information
l46kok authored Aug 12, 2024
1 parent 851a4b8 commit 0e3ead6
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 13 deletions.
6 changes: 3 additions & 3 deletions policy/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ func (p *Policy) GetExplanationOutputPolicy() *Policy {
ep := Policy{
name: p.name,
semantic: p.semantic,
info: &*p.info,
info: p.info,
metadata: p.metadata,
source: &*p.source,
source: p.source,
}
if p.rule != nil {
ep.rule = p.rule.getExplanationOutputRule()
Expand Down Expand Up @@ -230,7 +230,7 @@ func (r *Rule) getExplanationOutputRule() *Rule {
description: r.description,
}
for _, variable := range r.variables {
er.variables = append(er.variables, &*variable)
er.variables = append(er.variables, variable)
}
for _, match := range r.matches {
em := Match{
Expand Down
2 changes: 1 addition & 1 deletion policy/testdata/errors_unreachable/policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rule:
- name: want
expression: request.labels
- name: missing
expression: variables.want.filter(l, !(l in resource.labels))
expression: variables.want.filter(l, !(l in resource.labels))
- name: invalid
expression: >
resource.labels.filter(l,
Expand Down
2 changes: 1 addition & 1 deletion policy/testdata/k8s/policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ spec:
resource.containers.all(c, c.startsWith(variables.env + '.'))
messageExpression: >
'only %s containers are allowed in namespace %s'
.format([variables.env, resource.namespace])
.format([variables.env, resource.namespace])
2 changes: 1 addition & 1 deletion policy/testdata/k8s/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ section:
tests:
- name: "restricted_container"
input:
resource.namespace:
resource.namespace:
value: "dev.cel"
resource.labels:
value:
Expand Down
2 changes: 1 addition & 1 deletion policy/testdata/nested_rule2/policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rule:
variables:
- name: "permitted_regions"
expression: "['us', 'uk', 'es']"
match:
match:
- condition: resource.?user.orValue("").startsWith("bad")
rule:
id: "banned regions"
Expand Down
4 changes: 2 additions & 2 deletions policy/testdata/nested_rule2/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ section:
tests:
- name: "restricted_origin"
input:
resource:
resource:
value:
user: "bad-user"
origin: "ir"
Expand All @@ -36,7 +36,7 @@ section:
value:
user: "good-user"
origin: "de"
output: "{'banned': 'unconfigured_region'}"
output: "{'banned': 'unconfigured_region'}"
- name: "permitted"
tests:
- name: "valid_origin"
Expand Down
2 changes: 1 addition & 1 deletion policy/testdata/nested_rule3/policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rule:
variables:
- name: "permitted_regions"
expression: "['us', 'uk', 'es']"
match:
match:
- condition: resource.?user.orValue("").startsWith("bad")
rule:
id: "banned regions"
Expand Down
4 changes: 2 additions & 2 deletions policy/testdata/nested_rule3/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ section:
tests:
- name: "restricted_origin"
input:
resource:
resource:
value:
user: "bad-user"
origin: "ir"
Expand All @@ -36,7 +36,7 @@ section:
value:
user: "good-user"
origin: "de"
output: "{'banned': 'unconfigured_region'}"
output: "{'banned': 'unconfigured_region'}"
- name: "permitted"
tests:
- name: "valid_origin"
Expand Down
3 changes: 2 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (s *ConformanceServer) Check(ctx context.Context, in *confpb.CheckRequest)
checkOptions = append(checkOptions, cel.Container(in.Container))
checkOptions = append(checkOptions, cel.Declarations(in.TypeEnv...))
checkOptions = append(checkOptions, cel.Types(&test2pb.TestAllTypes{}))
checkOptions = append(checkOptions, cel.Types(&test2pb.Proto2ExtensionScopedMessage{}))
checkOptions = append(checkOptions, cel.Types(&test3pb.TestAllTypes{}))
checkOptions = append(checkOptions, cel.OptionalTypes())
env, _ := cel.NewCustomEnv(checkOptions...)
Expand Down Expand Up @@ -268,7 +269,7 @@ func init() {
ext.Strings(),
ext.Math(),
ext.Encoders(),
cel.Types(&test2pb.TestAllTypes{}, &test3pb.TestAllTypes{}),
cel.Types(&test2pb.TestAllTypes{}, &test2pb.Proto2ExtensionScopedMessage{}, &test3pb.TestAllTypes{}),
cel.EagerlyValidateDeclarations(true),
cel.EnableErrorOnBadPresenceTest(true),
cel.OptionalTypes())
Expand Down

0 comments on commit 0e3ead6

Please sign in to comment.