Commit Graph

24 Commits

Author SHA1 Message Date
Sebastian Spaink 9d2c957c8b Generate a JSON Schema for the bundle manifest (#8684)
resolve: https://github.com/open-policy-agent/opa/issues/8661

Similar to the [plan.schema.json
](https://github.com/open-policy-agent/opa/pull/8676)this manifest will
be published on the website under
https://openpolicyagent.org/schemas/bundle/v1/manifest.schema.json

---------

Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com>
Co-authored-by: Stephan Renatus <s_renatus@apple.com>
2026-05-21 10:39:17 -05:00
Sebastian Spaink 796db6b8d2 Generate a JSON Schema for the IR plan (#8676)
resolve: https://github.com/open-policy-agent/opa/issues/8662 

Generate a schema for the IR plan and publish it to the website at schemas/ir/v1/plan.schema.json 

resolve: https://github.com/open-policy-agent/opa/issues/6266

Fix the upper case Index in MakeNumberRefStmt by supporting both, lower and upper case.

---------

Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com>
2026-05-19 15:16:25 -05:00
Sebastian Spaink 1de861f2d6 Add support for days, weeks and years in parse_duration_ns (#8463)
Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com>
2026-04-13 20:20:51 +00:00
Philip Conrad 84b23ccedd bugfix: Add back default cmd.RootCommand definition. (#7811)
This commit fixes an issue when upgrading codebases to OPA v1.7.0.

In PR #7797, we introduced the ability to provide "branding"
information in OPA commands and help messages, which would
allow easier customized OPA distributions in the future.

However, this changeset removed the public symbol `cmd.RootCommand`,
and required refactoring to use `cmd.Command`, which breaks automated
upgrades, such as those done by Dependabot.

This PR adds back the missing symbol, with the original/default "OPA"
branding provided. This should allow existing codebases to upgrade
without requiring any code changes.

Signed-off-by: Philip Conrad <philip@chariot-chaser.net>
2025-07-31 12:55:34 -04:00
kevinstyra 94a953150a cmd: allow branding
This change allows users that build their own executable or "spin" of
OPA to give it a name, and have it reference itself properly in help
texts.

It's a vanity thing, but I think some people would appreciate it, hat
tip to the international association of pedants.

Signed-off-by: Stephan Renatus <stephan@styra.com>
Co-authored-by: kevinstyra <83973046+kevinstyra@users.noreply.github.com>
2025-07-24 11:33:23 +02:00
kevinstyra 36bae2aac6 cmd: use command.RunE to return errors and perform orderly shutdown of OPA
`os.Exit` immediately exits the program and doesn't run defer functions.
This can be problematic as any command.OnFinalize routines and any logic
after the command.Execute won't be run.

Also suppress all RunE cobra error and usage messages. These would be
printed twice otherwise.

Signed-off-by: Stephan Renatus <stephan@styra.com>
Co-authored-by: Kevin St. Pierre <kevin@styra.com>
2025-07-23 17:17:50 +02: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
Torin Sandall 16fccc9a76 ast: extend capabilities to return min compatible version
This commit adds the ability to determine the minimum compatible OPA
version for a set of capabilities. This can be coupled with the
capabilities generated by the compiler to determine the min. compatible
version of a policy/bundle. The build has been extended to generate the
version index that lets us quickly check the required version for each
builtin/feature/keyword in the capabilities.

Signed-off-by: Torin Sandall <torin@styra.com>
2023-10-30 09:36:35 -07:00
Ivan b7c1a1c183 CLI: don't print error twice (#5122)
Cobra will already print the error, there is no need to do it again.

Fixes #5115.

Signed-off-by: Iván Peña Hernández <ivanphdz13@gmail.com>
2022-09-12 19:56:50 +02:00
Stephan Renatus 21ac58bddc build/wasm: use golang1.16 go:embed mechanism (#5123)
With the embed directive, we no longer need our custom code that predates
Go 1.16. Also, with the release of 1.19, we no longer desire compatibility
with anything predating 1.16, so this cleanup becomes possible.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-09-12 17:42:44 +02:00
Stephan Renatus e8deba62bd types, ast, docs: Add support for named function arg declarations
This commit adds support for named argument declarations for built-in
functions as well as additional metadata/annotations on built-in
functions (e.g., descriptions, categories, etc.) This commit allows us
to generate a data file (builtin_metadata.json) that other tools can
consume to improve the Rego authoring experience.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>

Co-authored-by: Torin Sandall <torinsandall@gmail.com>
2022-05-24 09:38:07 -07:00
Stephan Renatus 5a1ed9c7fa wasm: replace unused functions by stub (#3206)
We're in this situation: performing dead code analysis on wasm isn't too
hard, but it requires a representation of all wasm instructions: we'd need
to be able to parse the "runtime" wasm bits, i.e., what's built using llvm
from C code. When building upon that wasm module, we process the function
bodies uninterpreted -- they are all just `[]byte` to us.

This restriction lets us get by without implementing all the wasm
instructions -- we only write what we use, and read a bare minimum to work
as outlined above.

To still be able to remove dead code, this change employs a trick: at build
time, when the aforementioned runtime wasm module is compiled, we're calling
wasm-opt on it to extract its call graph. We'll use that, together with the
functions actually planned in our wasm compiler (using the subset of
instructions that we understand), to remove all unused functions from the
name section, and replace their function bodies with `unreachable`.

We cannot really remove them, since that would require reindexing all
functions; and we cannot do that without replacing the function indices at
their call sites in the "runtime" wasm module.

Another restriction to the impact of this approach is call_indirect: We
need to keep every function that's referenced in the table -- we don't know
which function might be calling them indirectly. In a follow-up, we could
record that information and use it to further reduce the code size: we know
that if none of the regex-related builtins are used, we could also stub out
the re2-related functions.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2021-03-11 10:25:16 +01:00
Torin Sandall 063f1f385d ast: Add capabilities struct and file generation
Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2020-07-23 19:35:22 -04:00
Torin Sandall ea5f975ff9 build: Replace gen-opa-wasm.sh with generic go runner
There is nothing wasm-specific about the script and it will need to be
reused for feature generation.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2020-07-23 19:35:22 -04:00
Torin Sandall db030e0b14 ast: New parser implementation
This commit replaces the existing PEG generated parser with a parser
implemented by hand. The new parser is more efficient (avoiding old
problems with pathological input cases like {{{{{{{{{}}}}}}}} and
deeply-nested composites in general) and offers better opportunities
for improved error reporting (which has been improved already but
there is still room to grow.)

During the test process of implementing the new parser, we identified
a few issues that were present in the old parser. Those issues are
fixed by this commit.

Fixes #1251
Fixes #501
Fixes #2198
Fixes #2199
Fixes #2200
Fixes #2201
Fixes #2202
Fixes #2203

Co-authored-by: Torin Sandall <torinsandall@gmail.com>
Co-authored-by: Patrick East <east.patrick@gmail.com>

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
Signed-off-by: Patrick East <east.patrick@gmail.com>
2020-03-26 04:57:12 -07:00
Patrick East b48c534722 Run make fmt with new goimports cmd
Signed-off-by: Patrick East <east.patrick@gmail.com>
2019-09-27 09:55:11 -04:00
Patrick East 5c1c232353 Remove install-deps, instead go run from vendor
This avoids the need to go-install anything.

Signed-off-by: Patrick East <east.patrick@gmail.com>
2019-09-26 15:30:13 -07:00
Torin Sandall 031fba9c2f Fix cross-compile issue in go generate step
The WASM changes broke cross-compiling because go generate executes go
run ... which inherits the GOOS and GOARCH environment variables. To
resolve this we just wrap the go rnu ... command in a script that
overwrites the environment variables so that the host GOOS and GOARCH
are used. For some reason go generate does not allow you to specify
environment variables inline, e.g., FOO=BAR go run ...

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-10-25 08:40:08 -07:00
Torin Sandall 90bda056b4 Add C library implementing operations for WASM
These changes add a C library that implements low-level data operations
and JSON parsing for WASM policies. The output of the WASM build process
are checked into the repository so that OPA can easily access the
bytecode for test and other purposes.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-10-08 17:29:18 -07:00
Torin Sandall 299606cdac Rename the language to Rego
Rego: Latin verb for rule/govern/control.
2016-05-09 08:56:55 -07:00
Torin Sandall 8ed63b76dd Add variables to the grammar
This change set also includes a bit of refactoring:

- Renamed jsonlog to opalog
- Renamed Dictionary to Object
- Split AST into separate files
- Tweaked parser definition to separate terms with whitespace
- Renamed helper functions in parser_test.go to distinguish from cases
- Moved reflection helper into test suite and renamed
- Modified Term.String() to make output more readable
- Reorganized the grammar file
- Allow scalars and variables as object keys. We will deal with this when
serializing to JSON.
2016-03-31 13:51:33 -07:00
Torin Sandall e2297a7833 Basic infrastructure and process documentation
- Updated source code layout to use standard Go project structure.
- Makefile for build and test execution.
- Glide for dependency management.
- Integrated spf13/cobra for command line entry point.
- Added docs on release and development process.
2016-03-30 08:58:21 -07:00
Tim Hinrichs cecbc34247 Add parser test 2016-01-04 13:40:04 -08:00
Tim Hinrichs 0ebb14c374 Added Travis CI file 2015-12-28 15:04:42 -08:00