You can create a template for a policy rule by using Rego in the Create Template API. Rego is the native query language for Open Policy Agent (OPA), an open source policy engine. For information about Rego coding, see OPA Policy Language. Using Rego, you can define the logic to perform in the template.

List of Valid Rego Operations

The following is a list of safe, built-in OPA functions that are allowed for policy evaluation. These are basic operations needed for policy evaluation and exclude dangerous operations. The operations are required for the Create Template API.

Operator typeValid operators
Comparisoneq, equal, neq, gt, lt, gte, lte
Arithmetic operationsplus, minus, mul, div, abs, round, ceil, floor
String operationsconcat, contains, endswith, format_int, indexof, lower, replace, split, startswith, substring, trim, trim_left, trim_prefix, trim_right, trim_suffix, upper
Array operationsarray.concat, array.reverse, array.slice
Set operationsset_diff, intersection, union
Object operationsobject.get, object.keys, object.remove, object.union, object.union_n
Type conversionto_number
Aggregationcount, sum, max, min, sort, all, any
Logic operationsand, or
JSON operationsjson.filter, json.patch, json.remove, json.unmarshal
Encodingbase64.encode, base64.decode, base64url.encode, base64url.decode, urlquery.encode, urlquery.decode
Time operations (read-only, no system clock manipulation)time.now_ns, time.parse_ns, time.parse_rfc3339_ns, time.parse_duration_ns
Unitsunits.parse, units.parse_bytes
Regexregex.match, regex.find_all_string_submatch_n, regex.split
Graphgraph.reachable, graph.reachable_paths
Type checkingis_number, is_string, is_boolean, is_array, is_object, is_set, is_null
Type nametype_name