Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot load dependent modules via REST API #207

Closed
tsandall opened this issue Dec 22, 2016 · 1 comment
Closed

Cannot load dependent modules via REST API #207

tsandall opened this issue Dec 22, 2016 · 1 comment
Labels

Comments

@tsandall
Copy link
Member

tsandall commented Dec 22, 2016

The REST API doesn't allow callers to load dependent modules one-by-one:

test1.rego:

package ex

import request.req1

x :- req1 > 1

test2.rego:

package ex

y :- x with request.req1 as 1000

Example:

torin:~$ curl -X PUT localhost:8181/v1/policies/test1 --data-binary @test1.rego
{
  "ID": "test1",
  "Module": {
    "Package": {
      "Path": [
        {
          "Type": "var",
          "Value": "data"
        },
        {
          "Type": "string",
          "Value": "ex"
        }
      ]
    },
    "Imports": null,
    "Rules": [
      {
        "Name": "x",
        "Value": {
          "Type": "boolean",
          "Value": true
        },
        "Body": [
          {
            "Index": 0,
            "Terms": [
              {
                "Type": "var",
                "Value": "gt"
              },
              {
                "Type": "ref",
                "Value": [
                  {
                    "Type": "var",
                    "Value": "request"
                  },
                  {
                    "Type": "string",
                    "Value": "req1"
                  }
                ]
              },
              {
                "Type": "number",
                "Value": 1
              }
            ]
          }
        ]
      }
    ]
  }
}torin:~$ curl -X PUT localhost:8181/v1/policies/test1 --data-binary @test2.rego
{
  "Code": 400,
  "Message": "error(s) occurred while compiling module(s), see Errors",
  "Errors": [
    {
      "Code": 2,
      "Location": {
        "File": "test1",
        "Row": 3,
        "Col": 1
      },
      "Message": "y: x is unsafe (variable x must appear in the output position of at least one non-negated expression)"
    }
  ]
}

However, if we run OPA and pass the modules via the command line, everything works fine:

Run OPA:

./opa_darwin_amd64 run -s --v=3 --logtostderr=1 ~/test1.rego ~/test2.rego

List policies:

torin:~$ curl localhost:8181/v1/policies --silent | jq '.[].ID'
"/Users/torin/test1.rego"
"/Users/torin/test2.rego"

Query for data:

torin:~$ curl localhost:8181/v1/data
{"ex":{"y":true}}
@tsandall tsandall added the bug label Dec 22, 2016
@tsandall
Copy link
Member Author

Oops. The second PUT was overwriting the first--as a result this behaviour was expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant