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
Stephan Renatus 20885fe4a9 golangci: bump version, addess all new findings
The previous version has been failing without any good reason for me,
so let's try this.

About the version pick: It's not the latest version (v1.62.0 at the
moment), because that would introduce a new revive rule,
redeclares-builtin-id, and that flags every variable called `min` or
`max` in the code base. I had started addressing these, but they were
just too many.

The new issues related to this version are mostly that it complains
whenever it finds a non-static string that makes its way into a printf-
like function. However, that's a common pattern in some place here, so
I've sprinkled some nolint:govet on it.

Signed-off-by: Stephan Renatus <stephan@styra.com>
2024-11-14 20:36:50 +01:00
Stephan Renatus c99b645194 ast: fuzzed parser bug, two codeql issues (#3988)
* storage/path.Ref: parse int64 into ast.Number
* ast/PtrRef: guard against giant paths

I don't believe this limit is every going to be reached. But CodeQL had flagged
this, and it's not entirely wrong. Let's error our on giant wonky inputs instead
of seeing what'll happen with it eventually.

* ast/parser: fix bad import alias var

The fuzzer came up with that!

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2021-11-08 14:10:32 +01:00
Stephan Renatus fb301d2713 cmd,storage: fix int conversion type errors (#3975)
Also fixes a panic in `opa oracle find-definition file:12` is file
didn't exit.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2021-11-06 08:49:38 +01:00
Teemu Koponen a6724c7456 ast: Use pointer receivers with Array.
This is to allow future mutating functions: with value receivers this
mutating any of the member variables is not possible.

Signed-off-by: Teemu Koponen <koponen@styra.com>
2020-08-03 13:36:33 -04:00
Teemu Koponen 3991328cad storage: Size the Path correctly in construction.
Improvements due to reduced allocations:

benchmark                                        old ns/op      new ns/op      delta
BenchmarkAuthzForbidAuthn-8                      30951          30871          -0.26%
BenchmarkAuthzForbidPath-8                       96070          95554          -0.54%
BenchmarkAuthzForbidMethod-8                     102412         101239         -1.15%
BenchmarkAuthzAllow10Paths-8                     99315          99859          +0.55%
BenchmarkAuthzAllow100Paths-8                    620837         595914         -4.01%
BenchmarkAuthzAllow1000Paths-8                   5423305        5301059        -2.25%
BenchmarkRESTAuthzForbidAuthn-8                  472427         469012         -0.72%
BenchmarkRESTAuthzForbidPath-8                   546472         541892         -0.84%
BenchmarkRESTAuthzForbidMethod-8                 551292         549082         -0.40%
BenchmarkRESTAuthzAllow10Paths-8                 546016         544676         -0.25%
BenchmarkRESTAuthzAllow100Paths-8                1106900        1099005        -0.71%
BenchmarkRESTAuthzAllow1000Paths-8               6201083        6004029        -3.18%
BenchmarkScheduler10x30-8                        12109234       12061512       -0.39%

Signed-off-by: Teemu Koponen <koponen@styra.com>
2019-08-26 16:07:09 -07:00
Torin Sandall a623dcd4c8 Handle escaped paths in data writes
These changes extend #702 to include writes. If the path segments are
escaped, the should be unescaped during parsing. This allows callers to
write keys like "foo/bar" into storage.

Fixes #695

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-04-12 17:07:48 -07:00
Torin Sandall 61823a2920 Refactor set and object types in ast package
Previously, sets and objects were not interfaces and as a result,
callers were relying on the underlying structure for operations such as
iteration.

These changes refactor the ast package to expose sets and objects as
interfaces so that we can change the underlying data structures without
affecting callers.
2017-12-15 09:16:34 -08:00
Matthew Mussomele 3821494c76 Support composite terms as reference operands 2017-07-31 08:05:36 -07:00
Torin Sandall 10f22906b5 Refactor storage layer interfaces
This is a large change set that contains a few backwards incompatible
changes. Summary of breaking changes:

- Remove storage.Storage in favour of storage.Store interface.
- Remove mount support.
- Remove storage of compiled policies.
- Modify storage.Store to support rollback.
- Modify storage.Store to support raw policy storage.
- Modify storage.Store to support indexing.
2017-06-23 13:18:15 -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 fe25593707 Update underlying number representation
These changes modify OPA to use json.Number to represent number values in
storage and the AST. Comparisons and numeric operations are handled by the
math/big package. Using json.Number avoids loss of precision when loading
integers greater than 2**53 and use of math/big avoids need for type
conversions in the built-in implementations. In the long run, the math/big
usage may be replaced with specific paths for smaller numbers.

Fixes #154
2016-12-05 15:30:38 -08:00
Torin Sandall 75cee19201 Add new storage.Path type 2016-12-02 10:14:49 -08:00