@@ -41,88 +41,68 @@ enum TestYamlPolicy {
41
41
NESTED_RULE (
42
42
"nested_rule" ,
43
43
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)))" ),
51
48
NESTED_RULE2 (
52
49
"nested_rule2" ,
53
50
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
+ + " {}))" ),
61
56
NESTED_RULE3 (
62
57
"nested_rule3" ,
63
58
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()))" ),
71
64
REQUIRED_LABELS (
72
65
"required_labels" ,
73
66
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()))" ),
83
73
RESTRICTED_DESTINATIONS (
84
74
"restricted_destinations" ,
85
75
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))" ),
97
82
K8S (
98
83
"k8s" ,
99
84
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())" ),
106
90
PB (
107
91
"pb" ,
108
92
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 =="
113
97
+ " 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()))" ),
116
99
LIMITS (
117
100
"limits" ,
118
101
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\" ))" );
126
106
127
107
private final String name ;
128
108
private final boolean producesOptionalResult ;
0 commit comments