@@ -222,40 +222,48 @@ func (c compiler) CompileCELExpression(expressionAccessor ExpressionAccessor, op
222
222
func mustBuildEnvs (baseEnv * environment.EnvSet ) variableDeclEnvs {
223
223
requestType := BuildRequestType ()
224
224
namespaceType := BuildNamespaceType ()
225
- envs := make (variableDeclEnvs , 4 ) // since the number of variable combinations is small, pre-build a environment for each
225
+ envs := make (variableDeclEnvs , 8 ) // since the number of variable combinations is small, pre-build a environment for each
226
226
for _ , hasParams := range []bool {false , true } {
227
227
for _ , hasAuthorizer := range []bool {false , true } {
228
- var envOpts []cel.EnvOption
229
- if hasParams {
230
- envOpts = append (envOpts , cel .Variable (ParamsVarName , cel .DynType ))
231
- }
232
- if hasAuthorizer {
228
+ for _ , strictCost := range []bool {false , true } {
229
+ var envOpts []cel.EnvOption
230
+ if hasParams {
231
+ envOpts = append (envOpts , cel .Variable (ParamsVarName , cel .DynType ))
232
+ }
233
+ if hasAuthorizer {
234
+ envOpts = append (envOpts ,
235
+ cel .Variable (AuthorizerVarName , library .AuthorizerType ),
236
+ cel .Variable (RequestResourceAuthorizerVarName , library .ResourceCheckType ))
237
+ }
233
238
envOpts = append (envOpts ,
234
- cel .Variable (AuthorizerVarName , library .AuthorizerType ),
235
- cel .Variable (RequestResourceAuthorizerVarName , library .ResourceCheckType ))
236
- }
237
- envOpts = append (envOpts ,
238
- cel .Variable (ObjectVarName , cel .DynType ),
239
- cel .Variable (OldObjectVarName , cel .DynType ),
240
- cel .Variable (NamespaceVarName , namespaceType .CelType ()),
241
- cel .Variable (RequestVarName , requestType .CelType ()))
239
+ cel .Variable (ObjectVarName , cel .DynType ),
240
+ cel .Variable (OldObjectVarName , cel .DynType ),
241
+ cel .Variable (NamespaceVarName , namespaceType .CelType ()),
242
+ cel .Variable (RequestVarName , requestType .CelType ()))
242
243
243
- extended , err := baseEnv .Extend (
244
- environment.VersionedOptions {
245
- // Feature epoch was actually 1.26, but we artificially set it to 1.0 because these
246
- // options should always be present.
247
- IntroducedVersion : version .MajorMinor (1 , 0 ),
248
- EnvOptions : envOpts ,
249
- DeclTypes : []* apiservercel.DeclType {
250
- namespaceType ,
251
- requestType ,
244
+ extended , err := baseEnv .Extend (
245
+ environment.VersionedOptions {
246
+ // Feature epoch was actually 1.26, but we artificially set it to 1.0 because these
247
+ // options should always be present.
248
+ IntroducedVersion : version .MajorMinor (1 , 0 ),
249
+ EnvOptions : envOpts ,
250
+ DeclTypes : []* apiservercel.DeclType {
251
+ namespaceType ,
252
+ requestType ,
253
+ },
252
254
},
253
- },
254
- )
255
- if err != nil {
256
- panic (fmt .Sprintf ("environment misconfigured: %v" , err ))
255
+ )
256
+ if err != nil {
257
+ panic (fmt .Sprintf ("environment misconfigured: %v" , err ))
258
+ }
259
+ if strictCost {
260
+ extended , err = extended .Extend (environment .StrictCostOpt )
261
+ if err != nil {
262
+ panic (fmt .Sprintf ("environment misconfigured: %v" , err ))
263
+ }
264
+ }
265
+ envs [OptionalVariableDeclarations {HasParams : hasParams , HasAuthorizer : hasAuthorizer , StrictCost : strictCost }] = extended
257
266
}
258
- envs [OptionalVariableDeclarations {HasParams : hasParams , HasAuthorizer : hasAuthorizer }] = extended
259
267
}
260
268
}
261
269
return envs
0 commit comments