What a CEL expression may use: its variables and their types, custom
functions, and the message and enum types of its CEL.TypeProvider. The
standard CEL functions and macros, and CEL's own types, are always
available.
Build one with build/1 and pass it to CEL.check/2, CEL.compile/2
or CEL.eval/3. A CEL.Program keeps the environment it was compiled
with, so evaluation does not take one.
Summary
Functions
Builds an environment.
Types
Functions
Builds an environment.
env =
CEL.Env.build(
types: PB.CEL.types(MyApp.Schema),
container: "my.pkg",
vars: [user: {:message, "my.pkg.User"}, tags: {:list, :string}],
functions: [my_function]
)Options
:vars— the variables expressions may read, as a keyword list or map from name toCEL.Type.t/0.:functions— custom functions, asCEL.Functionstructs. See the "Custom CEL functions" guide.:types— the message and enum types expressions may use, as aCEL.TypeProvider.t/0, such asPB.CEL.types/1returns for a protobuf schema. Without it there are none. Message and enum names in:varsand:functionsmay be atoms or strings; each is resolved through the provider, and an unknown one raises, with or without a provider. The well-known types CEL builds in, such asgoogle.protobuf.Timestamp, need no provider.:container— the package names are resolved in, as withcontainerin other CEL implementations: with"my.pkg",Userresolves tomy.pkg.User.:abbreviations— fully qualified names expressions may refer to by their last segment, as withAbbrevsin cel-go: with["my.pkg.Decision"],Decision.REMOVEDmeansmy.pkg.Decision.REMOVEDwhatever the container. An abbreviation is used instead of the container, even when the container would resolve the name to something else, and hides a variable of the same name; variables a macro binds still hide it. Abbreviations apply to variables, types and enum values, not to function names.:validate_literals— a subset of[:duration, :timestamp, :regex]. Checking then rejects literal arguments evaluation would reject, such asduration('30d'),timestamp('nope')ors.matches('['). By default these fail when evaluated, as CEL specifies.
Raises CEL.OptionError for an unknown option or an invalid value.