@@ -41,88 +41,68 @@ enum TestYamlPolicy {
4141 NESTED_RULE (
4242 "nested_rule" ,
4343 true ,
44- "cel.bind(variables.permitted_regions, [\" us\" , \" uk\" , \" es\" ],"
45- + " cel.bind(variables.banned_regions, {\" us\" : false, \" ru\" : false, \" ir\" : false},"
46- + " (resource.origin in variables.banned_regions && "
47- + "!(resource.origin in variables.permitted_regions)) "
48- + "? optional.of({\" banned\" : true}) : optional.none()).or("
49- + "optional.of((resource.origin in variables.permitted_regions)"
50- + " ? {\" banned\" : false} : {\" banned\" : true})))" ),
44+ "cel.@block([resource.origin, @index0 in [\" us\" , \" uk\" , \" es\" ], {\" banned\" : true}],"
45+ + " ((@index0 in {\" us\" : false, \" ru\" : false, \" ir\" : false} && !@index1) ?"
46+ + " optional.of(@index2) : optional.none()).or(optional.of(@index1 ? {\" banned\" :"
47+ + " false} : @index2)))" ),
5148 NESTED_RULE2 (
5249 "nested_rule2" ,
5350 false ,
54- "cel.bind(variables.permitted_regions, [\" us\" , \" uk\" , \" es\" ],"
55- + " resource.?user.orValue(\" \" ).startsWith(\" bad\" ) ?"
56- + " cel.bind(variables.banned_regions, {\" us\" : false, \" ru\" : false, \" ir\" : false},"
57- + " (resource.origin in variables.banned_regions && !(resource.origin in"
58- + " variables.permitted_regions)) ? {\" banned\" : \" restricted_region\" } : {\" banned\" :"
59- + " \" bad_actor\" }) : (!(resource.origin in variables.permitted_regions) ? {\" banned\" :"
60- + " \" unconfigured_region\" } : {}))" ),
51+ "cel.@block([resource.origin, !(@index0 in [\" us\" , \" uk\" , \" es\" ])],"
52+ + " resource.?user.orValue(\" \" ).startsWith(\" bad\" ) ? ((@index0 in {\" us\" : false,"
53+ + " \" ru\" : false, \" ir\" : false} && @index1) ? {\" banned\" : \" restricted_region\" } :"
54+ + " {\" banned\" : \" bad_actor\" }) : (@index1 ? {\" banned\" : \" unconfigured_region\" } :"
55+ + " {}))" ),
6156 NESTED_RULE3 (
6257 "nested_rule3" ,
6358 true ,
64- "cel.bind(variables.permitted_regions, [\" us\" , \" uk\" , \" es\" ],"
65- + " resource.?user.orValue(\" \" ).startsWith(\" bad\" ) ?"
66- + " optional.of(cel.bind(variables.banned_regions, {\" us\" : false, \" ru\" : false,"
67- + " \" ir\" : false}, (resource.origin in variables.banned_regions && !(resource.origin"
68- + " in variables.permitted_regions)) ? {\" banned\" : \" restricted_region\" } :"
69- + " {\" banned\" : \" bad_actor\" })) : (!(resource.origin in variables.permitted_regions)"
70- + " ? optional.of({\" banned\" : \" unconfigured_region\" }) : optional.none()))" ),
59+ "cel.@block([resource.origin, !(@index0 in [\" us\" , \" uk\" , \" es\" ])],"
60+ + " resource.?user.orValue(\" \" ).startsWith(\" bad\" ) ? optional.of((@index0 in {\" us\" :"
61+ + " false, \" ru\" : false, \" ir\" : false} && @index1) ? {\" banned\" :"
62+ + " \" restricted_region\" } : {\" banned\" : \" bad_actor\" }) : (@index1 ?"
63+ + " optional.of({\" banned\" : \" unconfigured_region\" }) : optional.none()))" ),
7164 REQUIRED_LABELS (
7265 "required_labels" ,
7366 true ,
74- ""
75- + "cel.bind(variables.want, spec.labels, cel.bind(variables.missing, "
76- + "variables.want.filter(l, !(l in resource.labels)), cel.bind(variables.invalid, "
77- + "resource.labels.filter(l, l in variables.want && variables.want[l] != "
78- + "resource.labels[l]), (variables.missing.size() > 0) ? "
79- + "optional.of(\" missing one or more required labels: [\" \" + "
80- + "variables.missing.join(\" ,\" ) + \" \" ]\" ) : ((variables.invalid.size() > 0) ? "
81- + "optional.of(\" invalid values provided on one or more labels: [\" \" + "
82- + "variables.invalid.join(\" ,\" ) + \" \" ]\" ) : optional.none()))))" ),
67+ "cel.@block([spec.labels.filter(@it:0:0, !(@it:0:0 in resource.labels)), spec.labels,"
68+ + " resource.labels, @index2.filter(@it:0:0, @it:0:0 in @index1 && @index1[@it:0:0] !="
69+ + " @index2[@it:0:0])], (@index0.size() > 0) ? optional.of(\" missing one or more"
70+ + " required labels: [\" \" + @index0.join(\" ,\" ) + \" \" ]\" ) : ((@index3.size() > 0) ?"
71+ + " optional.of(\" invalid values provided on one or more labels: [\" \" +"
72+ + " @index3.join(\" ,\" ) + \" \" ]\" ) : optional.none()))" ),
8373 RESTRICTED_DESTINATIONS (
8474 "restricted_destinations" ,
8575 false ,
86- "cel.bind(variables.matches_origin_ip, locationCode(origin.ip) == spec.origin,"
87- + " cel.bind(variables.has_nationality, has(request.auth.claims.nationality),"
88- + " cel.bind(variables.matches_nationality, variables.has_nationality &&"
89- + " request.auth.claims.nationality == spec.origin, cel.bind(variables.matches_dest_ip,"
90- + " locationCode(destination.ip) in spec.restricted_destinations,"
91- + " cel.bind(variables.matches_dest_label, resource.labels.location in"
92- + " spec.restricted_destinations, cel.bind(variables.matches_dest,"
93- + " variables.matches_dest_ip || variables.matches_dest_label,"
94- + " (variables.matches_nationality && variables.matches_dest) ? true :"
95- + " ((!variables.has_nationality && variables.matches_origin_ip &&"
96- + " variables.matches_dest) ? true : false)))))))" ),
76+ "cel.@block([request.auth.claims, has(@index0.nationality), resource.labels.location in"
77+ + " spec.restricted_destinations], (@index1 && @index0.nationality == spec.origin &&"
78+ + " (locationCode(destination.ip) in spec.restricted_destinations || @index2)) ? true :"
79+ + " ((!@index1 && locationCode(origin.ip) == spec.origin &&"
80+ + " (locationCode(destination.ip) in spec.restricted_destinations || @index2)) ? true :"
81+ + " false))" ),
9782 K8S (
9883 "k8s" ,
9984 true ,
100- "cel.bind(variables.env, resource.labels.?environment.orValue(\" prod\" ),"
101- + " cel.bind(variables.break_glass, resource.labels.?break_glass.orValue(\" false\" ) =="
102- + " \" true\" , !(variables.break_glass || resource.containers.all(c,"
103- + " c.startsWith(variables.env + \" .\" ))) ? optional.of(\" only \" + variables.env + \" "
104- + " containers are allowed in namespace \" + resource.namespace) :"
105- + " optional.none()))" ),
85+ "cel.@block([resource.labels.?environment.orValue(\" prod\" )],"
86+ + " !(resource.labels.?break_glass.orValue(\" false\" ) == \" true\" ||"
87+ + " resource.containers.all(@it:0:0, @it:0:0.startsWith(@index0 + \" .\" ))) ?"
88+ + " optional.of(\" only \" + @index0 + \" containers are allowed in namespace \" +"
89+ + " resource.namespace) : optional.none())" ),
10690 PB (
10791 "pb" ,
10892 true ,
109- "( spec.single_int32 > TestAllTypes{single_int64: 10}.single_int64 ) ? optional.of(\" invalid"
110- + " spec, got single_int32=\" + string(spec.single_int32 ) + \" , wanted <= 10\" ) :"
111- + " ((spec.standalone_enum == cel.expr.conformance.proto3.TestAllTypes.NestedEnum.BAR"
112- + " || dev.cel.testing.testdata.proto3.StandaloneGlobalEnum.SGAR =="
93+ "cel.@block([ spec.single_int32], (@index0 > 10 ) ? optional.of(\" invalid spec, got "
94+ + " single_int32=\" + string(@index0 ) + \" , wanted <= 10\" ) : ((spec.standalone_enum == "
95+ + " cel.expr.conformance.proto3.TestAllTypes.NestedEnum.BAR || "
96+ + " dev.cel.testing.testdata.proto3.StandaloneGlobalEnum.SGAR =="
11397 + " dev.cel.testing.testdata.proto3.StandaloneGlobalEnum.SGOO) ? optional.of(\" invalid"
114- + " spec, neither nested nor imported enums may refer to BAR\" ) :"
115- + " optional.none())" ),
98+ + " spec, neither nested nor imported enums may refer to BAR\" ) : optional.none()))" ),
11699 LIMITS (
117100 "limits" ,
118101 true ,
119- "cel.bind(variables.greeting, \" hello\" , cel.bind(variables.farewell, \" goodbye\" ,"
120- + " cel.bind(variables.person, \" me\" , cel.bind(variables.message_fmt, \" %s, %s\" ,"
121- + " (now.getHours() >= 20) ? cel.bind(variables.message, variables.farewell + \" , \" +"
122- + " variables.person, (now.getHours() < 21) ? optional.of(variables.message + \" !\" ) :"
123- + " ((now.getHours() < 22) ? optional.of(variables.message + \" !!\" ) : ((now.getHours()"
124- + " < 24) ? optional.of(variables.message + \" !!!\" ) : optional.none()))) :"
125- + " optional.of(variables.greeting + \" , \" + variables.person)))))" );
102+ "cel.@block([now.getHours()], (@index0 >= 20) ? ((@index0 < 21) ? optional.of(\" goodbye,"
103+ + " me!\" ) : ((@index0 < 22) ? optional.of(\" goodbye, me!!\" ) : ((@index0 < 24) ?"
104+ + " optional.of(\" goodbye, me!!!\" ) : optional.none()))) : optional.of(\" hello,"
105+ + " me\" ))" );
126106
127107 private final String name ;
128108 private final boolean producesOptionalResult ;
0 commit comments