14 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
Johan Fylling 36dd26ac92 rego-v1: Future-proofing test pkg tests to be 1.0 compatible (#7030)
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-09-18 14:18:00 +02:00
Johan Fylling b36151d992 Adding --v1-compatible flag to all previously unsupported command line commands (#6521)
In addition to those commands already supported:

* build
* check
* eval
* fmt
* test

support has been added to the following commands:

* `bench`
* `deps`
* `exec`
* `inspect`
* `parse`
* `run` (command `server` and `REPL`)

Fixes: #6520

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-01-24 15:42:32 +01:00
Anders Eknert a0ed11bbf2 SDK: Fix typo in test package error message (#6331)
Signed-off-by: Anders Eknert <anders@styra.com>
2023-10-20 08:51:19 +02:00
Eng Zer Jun b3ae18d3a3 perf: avoid unnecessary byte/string conversion
We can use alternative functions/methods to avoid unnecessary
byte/string conversion calls.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2023-05-23 10:00:59 -07:00
Charlie Egan 26ce80a5ac sdk: Return provenance information in Result types (#5460)
This will allow users of the SDK to see the version information of the
bundles used in decisions as well as the OPA SDK version.

Signed-off-by: Charlie Egan <charlieegan3@users.noreply.github.com>
2022-12-13 09:04:34 +00:00
Anders Eknert 9a597feb2e chore: don't use the deprecated ioutil functions (#5319)
Another annoyance removed :P

Signed-off-by: Anders Eknert <anders@eknert.com>
2022-10-27 14:30:26 +02:00
Philip Conrad b2d92a33c1 Add prealloc linter check + linter fixes (#5139)
This commit adds the `prealloc` linter to the list of linters for OPA, and fixes up the miscellaneous locations in the code that the linter found where we could easily preallocate slices.

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
2022-09-15 15:09:54 -04:00
carabasdaniel 2c650693ab OCI: skip reloading bundle if tarball SHA did not change (#4658)
Fixes #4637.

Signed-off-by: carabasdaniel <dani@aserto.com>
2022-05-13 10:41:01 +02:00
Torin Sandall 7fad61ad40 sdk/test: error if mock bundle not prefixed correctly
The test server expects mock bundle files to be prefixed with
/bundles/ so return an error if they are not (otherwise the user has
to dig into the test server code to figure out why their test is not working.)

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2021-12-22 17:46:37 +01:00
Will Beason 3be1d08b87 Change check-lint to use golangci-lint (#3465)
golint is deprecated. The author of the code no longer supports the
codebase. golangci-lint is faster than golint, and is in use by other
opa repositories (e.g. Gatekeeper).

This commit changes tools.go to reference golangci (so it ends up in
vendor) and modifies check-lint to use golangci instead.

Breaking API Changes:

- plugins/rest/rest.go: Fix typo "AllowInsureTLS" -> "AllowInsecureTLS"
- storage/errors.go: Removed unused IndexingNotSupportedErr

Signed-off-by: Will Beason <willbeason@google.com>
2021-05-19 07:52:02 +02:00
Torin Sandall f43a77141d sdk: Add readiness signal to the test server
This commit updates the test server so that callers can control when
the server becomes ready. This allows us to test the async option on
the SDK without worrying about race conditions. I.e., we can block
server readiness and assert that the SDK returns undefined until ready.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2021-05-12 13:40:22 -04:00
Torin Sandall 34ff7c738b sdk: Add new SDK package for embedding OPA
This commit adds a new top-level package for integration with OPA. The
SDK defines a simple interface for OPA integrations that require the
management APIs. The APIs allow callers to instantiate an instance of
OPA by specifying the OPA configuration as a file or byte slice. The
SDK implements basic lifecycle management so that callers can control
whether startup blocks the calling thread (or not). Also, callers can
control the log level of debug and console logs emitted by the OPA. In
the future, other options could be exposed but for now we choose to
keep the API as simple as possible (as we will be aiming for
consistency across multiple languages eventually, we want to keep the
surface area small as possible.)

For policy queries, users can supply wallclock time, the decision
name, and the value of the input document. The SDK ensures the
wallclock time is consistent across time.now_ns() and the decision log
record (for replay purposes). The SDK incldues a dedicated
"sdk_decision_eval" metric that records the total decision latency for
monitoring purposes. The SDK ensures the input document is not
processed more than necessary (i.e., it parses into an AST value which
is reused for decision log masking.) Finally, the SDK includes a UUID
in the result which can be used for correlation with the decision log.

Co-authored-by: Torin Sandall <torinsandall@gmail.com>
Co-authored-by: Anders Eknert <anders@eknert.com>

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
Signed-off-by: Anders Eknert <anders@eknert.com>
2021-05-10 11:34:14 -04:00