Skip to manual
gluon

Expression functions

CEL operators, macros and standard functions

The expression forms Gluon's type checker accepts, how to guard optional fields and where the runtime differs.

Model author or developer

Write expressions only in GOL fields that take CEL. The variables depend on the field: an object expression sees self, a policy sees subject, resource and context, and an action or Function sees its declared parameters. A variable from one kind of field is missing in another.

Functions and macros

FamilyNamesUse
Presencehas(value.field)Check an optional field before you read it
Sizesize(value), value.size()Count a list, map or string
Conversionstring, int, double, boolConvert a value; input that can't convert fails evaluation
Timetimestamp, duration, dateParse a string into a time value
String predicatescontains, startsWith, endsWith, matchesTest text against a substring or a pattern
Collection macrosexists, all, exists_oneTest a condition over the members
Collection transformsmap, filterBuild a new list from the members
Gluon helpersgluon.today, gluon.now, gluon.days, gluon.clamp, gluon.iban.valid, gluon.moneyEach has its own page in this section

date() passes the type checker but fails at runtime, because the runtime has no date() function. Use timestamp() or gluon.today() for now.

Operators

Arithmetic uses +, -, *, / and % on compatible types. Comparisons use ==, !=, <, <=, > and >=, and in tests membership. Conditions combine with !, && and ||, and condition ? yes : no picks a value. Field and index access must match the declared type. Subtracting two timestamps gives a duration.

Guard missing values

CEL
has(self.owner) && self.owner != ""

Guard every optional property with has(). The checker warns about an unguarded comparison with GLN-W206. In a policy, a condition over a missing value is unknown: an allow with that condition does not match, and a deny with it does.

Test the edges

Pin the clock with context.now in every time-dependent Test case. Add cases for an absent field, an empty list, input of the wrong type and a reader who is refused. An expression may run to 2,000 characters and a syntax-tree depth of 160, and it cannot reach the network.

A has() guard evaluated with the field present, then absent.
A has() guard evaluated with the field present, then absent.