Last active
March 8, 2023 22:12
-
-
Save epequeno/3f80ba4ef7302e2d0936249650ac0f69 to your computer and use it in GitHub Desktop.
opa eval cli example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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