Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint findings and misc cleanups #998

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions policy/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,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 @@ -192,7 +192,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
5 changes: 2 additions & 3 deletions policy/testdata/pb/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@ section:
tests:
- name: "good spec"
input:
spec:
spec:
expr: >
TestAllTypes{single_int32: 10}
output: "optional.none()"
- name: "invalid"
tests:
- name: "bad spec"
input:
spec:
spec:
expr: >
TestAllTypes{single_int32: 11}
output: >
"invalid spec, got single_int32=11, wanted <= 10"

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