Search code examples
jsonyamlopen-policy-agent

Different input formats in OPA when query using rest api vs local tool


When evaluating a query in Open Policy Agent (OPA) using local tool with opa eval command the input of the query is just a normal json/yaml. Ex input yaml:

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
  labels:
    app: nginx

But when evaluate a query using opa rest api the json/yaml value has to be embedded under a key called input. Ex :

input:
  apiVersion: v1
  kind: Pod
  metadata:
    name: nginx-pod
    labels:
      app: nginx

If the value is read from a file then the key input also needed to included which is not suitable in some applications where yaml files are manifests.

I want to know whether my approach to query opa rest api is correct and whether there exist a methed where the key input is not needed when query using opa rest api.


Solution

  • Yes, this is the main difference between v0 (no input) and v1 (input) of the data API. Simply replace /v1/data/ in your query with /v0/data. See the docs for further details.