Array Built-ins
| Function | Description | OPA | Wasm | Swift | Java |
|---|---|---|---|---|---|
|
Concatenates two arrays. Arguments: Returns:x (array[any])the first array y (array[any])the second array z (array[any])the concatenation of | v0.17.0 | ✓ | 0.0.1 | 0.1.0 |
|
Non-recursively unpacks array items in arr into the flattened array. Other types are appended as-is. Arguments: Returns:arr (array[any])the array to be flattened flattened (array[any])array flattened one level | v1.13.0 | ✓ | ✗ | 0.3.0 |
|
Returns the reverse of a given array. Arguments: Returns:arr (array[any])the array to be reversed rev (array[any])an array containing the elements of | v0.36.0 | ✓ | 0.0.1 | 0.1.0 |
|
Returns a slice of a given array. If Arguments: Returns:arr (array[any])the array to be sliced start (number)the start index of the returned slice; if less than zero, it's clamped to 0 stop (number)the stop index of the returned slice; if larger than slice (array[any])the subslice of | v0.17.0 | ✓ | 0.0.1 | 0.1.0 |
Examples
array.concat
array.concat returns a new array with the elements of the second array
appended to the first. Policies use it to extend a base list — for example
default registries or hosts — with extra values from input or data.
Merging a base allowlist with extra entries
array.concat appends one array to another. Policies often keep a fixed
base list (for example default registries) and extend it with values from
input or data for a particular tenant or environment.
package play
allowed_registries := array.concat(data.base_registries, input.extra_registries)
default allow := false
allow if {
some registry in allowed_registries
startswith(input.image, sprintf("%s/", [registry]))
}
deny contains msg if {
not allow
msg := sprintf(
"image %q is not from an allowed registry: %v",
[input.image, allowed_registries],
)
}
{
"allow": false,
"allowed_registries": [
"registry.internal/prod",
"ghcr.io/example",
"registry.internal/staging"
],
"deny": [
"image \"docker.io/library/nginx:1.27\" is not from an allowed registry: [\"registry.internal/prod\", \"ghcr.io/example\", \"registry.internal/staging\"]"
]
}{
"extra_registries": [
"registry.internal/staging"
],
"image": "docker.io/library/nginx:1.27"
}
{
"base_registries": [
"registry.internal/prod",
"ghcr.io/example"
]
}