5 Commits

Author SHA1 Message Date
Johan Fylling a179a24c48 v1 API
All packages, except for `cmd` and `internal`, have been moved into a new `v1` root package.

Old packages are kept for backwards-compatibility reasons. All contained code is replaced with simple type aliases and proxy functions to `v1` implementations.

Old packages default to the Rego v0 syntax, new `v1` packages default to the Rego v1 syntax.

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-12-12 15:27:34 +01:00
Johan Fylling 7bb6dbe36b Preparing for v1 API
Moving (most) source to v1 root package to prepare for v0/v1 API separation.

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-12-12 15:09:03 +01:00
Stephan Renatus f2db31dd1c CLI: display error details for ErrorDetail errors in eval output (#3739)
Before, errors displayed through the presentation package's prettyError()
method would never show their details. The expectation in the code was
that any error that has details would include them in its own Error()
string method.

When error types return their details using an interface, such as

    type ErrorDetail interface {
        Lines() []string
    }

and their Error() method only return a short error message, then that
detail would never make it to the user in any of the non-JSON output
variants.

Before:

    $ opa eval -t wasm '1+1'
    {
      "errors": [
        {
          "message": "engine not found",
          "details": "WebAssembly runtime not supported in this build.\n----------------------------------------------------------------------------------\nPlease download an OPA binary with Wasm enabled from\nhttps://www.openpolicyagent.org/docs/latest/#running-opa\nor build it yourself (with Wasm enabled).\n----------------------------------------------------------------------------------\n"
        }
      ]
    }
    $ opa -fpretty -t wasm '1+1'
    1 error occurred: engine not found

Now:

    $ opa eval -t wasm '1+1'
    {
      "errors": [
        {
          "message": "engine not found",
          "details": "WebAssembly runtime not supported in this build.\n----------------------------------------------------------------------------------\nPlease download an OPA binary with Wasm enabled from\nhttps://www.openpolicyagent.org/docs/latest/#running-opa\nor build it yourself (with Wasm enabled).\n----------------------------------------------------------------------------------"
        }
      ]
    }
    $ opa eval -fpretty -t wasm '1+1'
    1 error occurred: engine not found
    WebAssembly runtime not supported in this build.
    ----------------------------------------------------------------------------------
    Please download an OPA binary with Wasm enabled from
    https://www.openpolicyagent.org/docs/latest/#running-opa
    or build it yourself (with Wasm enabled).
    ----------------------------------------------------------------------------------

This also surfaces the error details in REPL sessions:

    $ opa run
    OPA 0.32.0-dev (commit 3da95f9c-dirty, built at 2021-08-16T11:24:46Z)

    Run 'help' to see a list of commands and check for updates.

    > target wasm
    > true
    1 error occurred: engine not found
    WebAssembly runtime not supported in this build.
    ----------------------------------------------------------------------------------
    Please download an OPA binary with Wasm enabled from
    https://www.openpolicyagent.org/docs/latest/#running-opa
    or build it yourself (with Wasm enabled).
    ----------------------------------------------------------------------------------
    >

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2021-08-18 19:31:53 +02:00
Stephan Renatus 6e4377af59 rego: make wasmtime-go dependency "more optional" (#3708)
Users of OPA as a library are concerned about big binary blobs in their vendor/
directories. Even more so if they don't use them. This is the case for anyone
using OPA as library, but not using the wasm-backed evaluation feature.

With this change, importers of any packages other than `server` and `cmd`
will have to explicitly opt-in to using wasm evaluation features by having an
underscore import somewhere:

    import _ "github.com/open-policy-agent/opa/features/wasm"

Fixes #3545.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2021-08-16 11:48:43 +02:00
Stephan Renatus bac175533b rego+topdown: allow custom builtins via rego pkg to halt (#3645)
Before, functions provided via arguments to `rego.New()` hadn't been
able to halt the topdown evaluation.

Now, they do, if they return a `*rego.HaltError`.

Fixes #3534.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2021-07-13 17:46:14 +02:00