18 Commits

Author SHA1 Message Date
Anders Eknert e43ef0a979 Use any in place of interface{} (#7566)
Earlier this evening I tried to run the Go
[modernize](https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize)
analyzer on OPA. That didn't go as planned:

- https://github.com/golang/go/issues/73661
- https://github.com/golang/go/issues/73663

While we wait for that to be fixed, I figured an old-fashioned
search-and-replace across the repo may work for at least the
`interface{}` to `any` conversion. That should help make it easier
to see the other fixes as applied by the modernize tool once it has
had those issues resolved.

Signed-off-by: Anders Eknert <anders@styra.com>
2025-05-12 13:57:48 +02:00
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 aeda97e8ee ast: Extending support for file-level assignments (:=) (#4583)
Updated support for:
* default values
* rules with `else` keyword
* partial rules
* functions

Fixes: #4555

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2022-04-20 13:28:51 +02: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 2b77240883 ast: Fix ordering of rule type checking errors
Previously the type checker would not sort errors before returning
them. As a result, the ordering of errors would depend on the order of
rules passed to the type checker (which is non-deterministic due to Go
map iteration order.)

These changes update the type checker to sort errors by location
before before returning them. This way the errors reported by opa test
and opa check and everything else are consistent across runs.

Fixes #1620

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2019-08-16 11:15:02 -04:00
Torin Sandall 557f8bb999 ast: Update parser to support rule assignments
Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2019-08-07 14:22:45 -04:00
Torin Sandall 4a4af6b178 Remove dead code associated with input doc errors
In b23cb4e the compiler was changed to allow queries to refer to the
input document without the input document being defined. Those changes
did not remove all of the code associated with input errors.

These changes remove the remaining (dead) code associated with input
errors and also update the server to allow Data API POST requests that
do not specify an input document.
2017-08-29 10:49:23 -07:00
Torin Sandall 3690fe8f05 Initial type checking implementation 2017-04-26 15:04:48 -07:00
Torin Sandall 039c7bdd02 Update error codes and messages throughout
- Refactor error codes to use strings instead of ints.

- Simplify error messages throughout.

- Ensure location set on all expressions. There were a couple locations
  in the parser/compiler where locations were not being set.

- Fallback to rule location in topdown in case location not set. This
  ensures that users get useful locations for API requests with paths
  that refer to virtual docs exactly.

Also add Find function to ast.Value. Useful for extracting values
dynamically. Eventually can support JSON pointers.

Fixes #237
2017-02-16 10:29:57 -08:00
Torin Sandall 4cb1d67bbd Update REPL to support with modifier
Also, reword error message for missing/undefined input document.
2017-02-03 08:39:35 -08:00
Torin Sandall 5906ea302b Update ast to support with modifier 2017-02-03 08:39:35 -08:00
Torin Sandall d65ccff7de Fix handling of missing input document
These changes update OPA to analyze queries to determine if an input
document is required. In the future, more sophisticated checks could be
performed (e.g., JSON schema validation).

If an input document is required but not provided, OPA will return HTTP
400 (per the documentation). This was broken in #197.

Fixes #227
2017-01-25 10:10:35 -08:00
Torin Sandall 7fa8a1e311 Refactor to use snake_case in API models
Also, move server types into file separate from server.

Fixes #222
2017-01-20 09:30:09 -08:00
Torin Sandall 725e7e77d1 Tweak error message prefix
Do not display the column number if the filename is set.
2016-11-29 16:08:48 -08:00
Torin Sandall ba37295dc8 Refactor built-in check for re-use 2016-11-24 12:22:23 -08:00
Torin Sandall 1a6d7a5a09 Include location attribute on ast errors
Previously, errors returned by the parser and compiler would encode the
location information in the error string. Now, the location information is
structured and can be readily used by consumers.
2016-10-25 09:26:36 -07:00
Torin Sandall 19afe35b84 Fix compiler error reporting
Before, callers would either flatten errors to a string or pick the first
error reported by the compiler. This was a bad approach and lead to an issue
for users running OPA from the command line, for example:

 $ opa run test.rego

If test.rego failed to compile, the run command would only print the first
error...

This change lets callers treat all compiler errors as a single error and
factors the flattening into the Error() implementation of the new ast.Errors
type.
2016-09-29 09:24:32 -07:00