-
Notifications
You must be signed in to change notification settings - Fork 29
Closed
Description
Feature request checklist
- There are no issues that match the desired change
- The change is large enough it can't be addressed with a simple Pull Request
- If this is a bug, please file a Bug Report.
Change
To make CEL environment setup consistent across CEL implementations, I propose to add a runtime option equivalent to CEL-cpp InterpreterOptions.enable_comprehension
to CEL-Java and CEL-Go (corresponding ticket google/cel-go#1050).
CelOptions.enableComprehension
is true
by default. Setting it to false will disable comprehension expressions (e.g. exists()
, all()
-- except has()
). Under-the-hood it may simply call comprehensionMaxIterations(0)
to disable comprehension expressions, and reset it to the default value to enable them.
Example
private static final CelRuntime CEL_RUNTIME = CelRuntimeFactory
.standardCelRuntimeBuilder()
.setOptions(CelOptions.current().enableComprehension(false).build())
.build();
@Test
public void macros_comprehensionsDisabled() throws Exception {
CelCompiler CEL_COMPILER = CelCompilerFactory.standardCelCompilerBuilder()
.addVar("request", SimpleType.ANY)
.setResultType(SimpleType.BOOL)
.setStandardMacros(CelStandardMacro.STANDARD_MACROS)
.build();
String expr = "size(['foo', 'bar'].map(x, request[x])) == 2";
CelRuntime.Program program = CEL_RUNTIME.createProgram(CEL_COMPILER.compile(expr).getAst());
Map<String, ?> input = ImmutableMap.of("request", ImmutableMap.of("foo", "f", "bar", "b"));
CelEvaluationException celErr = assertThrows(CelEvaluationException.class, () -> program.eval(input));
assertThat(celErr.getErrorCode()).isEqualTo(CelErrorCode.ITERATION_BUDGET_EXCEEDED);
}
Related
Internal ref: go/grpc-cel-integration
Metadata
Metadata
Assignees
Labels
No labels