Skip to content

Instantly share code, notes, and snippets.

@epequeno
Last active March 8, 2023 22:12
Show Gist options
  • Save epequeno/3f80ba4ef7302e2d0936249650ac0f69 to your computer and use it in GitHub Desktop.
Save epequeno/3f80ba4ef7302e2d0936249650ac0f69 to your computer and use it in GitHub Desktop.
opa eval cli example
$ ls -1
example.rego
input.json
$ bat -pp example.rego
package example
default allow := false
allow {
count(violation) == 0
}
violation[server.id] {
some server
public_server[server]
server.protocols[_] == "http"
}
violation[server.id] {
server := input.servers[_]
server.protocols[_] == "telnet"
}
public_server[server] {
some i, j
server := input.servers[_]
server.ports[_] == input.ports[i].id
input.ports[i].network == input.networks[j].id
input.networks[j].public
}
$ opa eval -f pretty -i input.json -d example.rego "input.servers[_].id"
+---------------------+
| input.servers[_].id |
+---------------------+
| "app" |
| "db" |
| "cache" |
| "ci" |
| "busybox" |
+---------------------+
$ opa eval -f pretty -i input.json -d example.rego "data.example.public_server[_].id"
+----------------------------------+
| data.example.public_server[_].id |
+----------------------------------+
| "app" |
| "ci" |
+----------------------------------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment