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

cmd/eval: add support for non-zero exit on undefined result #981

Closed
tsandall opened this issue Oct 4, 2018 · 0 comments
Closed

cmd/eval: add support for non-zero exit on undefined result #981

tsandall opened this issue Oct 4, 2018 · 0 comments

Comments

@tsandall
Copy link
Member

tsandall commented Oct 4, 2018

Users integrating OPA into pipelines or other automation systems use the opa eval subcommand to execute policies. In these situations, it may be useful if the opa eval subcommand exited with a non-zero code to indicate an undefined result or runtime error. E.g., the subcommand could exit with:

  • 0 to indicate success
  • 1 to indicate undefined
  • 2 to indicate errors

Example interaction:

$ opa eval --fail '1 = 1'
{
  "result": [
    {
      "expressions": [
        {
          "value": true,
          "text": "1 = 1",
          "location": {
            "row": 1,
            "col": 1
          }
        }
      ]
    }
  ]
}
$ echo $?
0
$ opa eval --fail '1 = 0'
{}
$ echo $?
1

The flag name --fail is copied from curl.

The changes to add support for this can be added to cmd/eval.go. If len(result.Result) == 0 at the end of the eval function, then the result is undefined. The eval function can modified to check for this case and return an error accordingly.

kichristensen added a commit to kichristensen/opa that referenced this issue Oct 17, 2018
Adds support for non-zero exit code when providing the --fail flag to
the eval command. 0 means no error, 1 means undefined result and 2 means
an error.
Fixes open-policy-agent#981

Signed-off-by: Kim Christensen <kimworking@gmail.com>
tsandall pushed a commit that referenced this issue Oct 18, 2018
* Add support for non-zero exit code

Adds support for non-zero exit code when providing the --fail flag to
the eval command. 0 means no error, 1 means undefined result and 2 means
an error.

Fixes #981

Signed-off-by: Kim Christensen <kimworking@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant