How can I use OPA in server mode with dynamic data?

Viewed 9

I have an event-based system where the input data changes with each event (it's a payload in the event). The rego rule(s) are static for our purposes.

I run the server like this from command line:

./opa run --server --set=default_decision=example/allow ./example.rego

My rego looks like:

pacakge example

default python3 = false
python3 {
  pythonVersion := regex.split("python", input.runtime)[1]
  to_number(pythonVersion) >= 3.0
}

My input json is dynamic but contains a field 'python'.

Once the server is up I'm trying to call it like this:

curl localhost:8181/v1/data/example/python3 -i -d @input.json -H "Content-Type: application/json"

This gives me an error: {"result":false,"warning":{"code":"api_usage_warning","message":"'input' key missing from request"}}

How can I fix this? I can run this non-server mode with same rego/input.json like this: ./opa eval --data example.rego --input input.json "data.example.python3" This gives me a correct "true" response.

0 Answers
Related