Writing Expressions
Basic Syntax
Expressions are written in CEL and look similar to expressions in C, JavaScript, or Python. They can include variables, literals, and operators.
Variables
Variables are used to refer to values. For example, identity
might refer to a user object.
identity.age >= 18 // Checks if the user's age is 18 or more.
Supported Variables
You can find the ngrok supported variables here:
Literals
CEL supports several literal types:
- Boolean:
true
,false
- Integer:
42
,-7
- String:
"hello"
,'world'
- List:
[1, 2, 3]
- Map:
{"key1": "value1", "key2": "value2"}
Operators
CEL provides a rich set of operators for performing arithmetic, comparison, and logical operations:
- Arithmetic:
+
,-
,*
,/
,%
- Comparison:
==
,!=
,<
,<=
,>
,>=
- Logical:
&&
,||
,!
Using Arithmetic
5 * (3 - 1) // Evaluates to 10
Using Comparison and Logical Operators
// Checks if the user is 18 or older and is in the US
identity.age >= 18 && identity.country == "US"
Working with Strings
String Concatenation
To combine strings, use the +
operator:
"Hello, " + "world!" // Results in "Hello, world!"
String Functions
CEL provides several built-in functions to work with strings, enabling you to perform transformations, query information, or compare strings.
size()
Returns the number of characters in the string:
size("Hello") // Evaluates to 5