24 Commits

Author SHA1 Message Date
Jacob Hochstetler 2cc948d872 TLM: Upgrade to v1 tablewriter (#7937)
- Updated test fixtures and various test fixes.

Signed-off-by: Jacob Hochstetler <jacob.hochstetler@gmail.com>
2025-10-01 10:44:42 +02:00
Johan Fylling 3f857572a0 inspect: Fixing missing annotations location in opa inspect with JSON format (#7727)
Fixing: #7459

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2025-06-25 14:48:41 +02:00
Anders Eknert d2a415e25d opa check --bundle report virtual/base doc conflicts (#7701)
A tiny first step to have more tooling correctly report
virtual and base document conflicts, as detailed in #7694.

This PR fixes the `opa check` command to report conflicts
of this type when the `-b`/`--bundle` flag is provided. The
bundle flag is required as without that, `opa check` should
only verify policies and not load data at all.

While I was in the `cmd` directory, I got annoyed with how
many of these commands store the same constants for their
`--format` flag, so I decided to fix that too, even if it
wasn't related to what I originally planned to do. I hope
it's not too distracting.

Signed-off-by: Anders Eknert <anders@styra.com>
2025-06-16 12:24:42 +02:00
Anders Eknert 8ba08ac80c Apply modernize linter fixes (#7599)
Following up on #7566, and now applying the more exciting
modernizations. fmt.Appendf was new to me! But especially
the contains checks are so much better IMHO. I have reviewed
all changes myself and did a few manual changes where it
became obvious that things could be improved a little further.

(the modernize analyzer still has some issues running against
OPA, and I have manually worked around those for the time being)

Signed-off-by: Anders Eknert <anders@styra.com>
2025-05-20 23:12:13 +02:00
Anders Eknert afb30d3f9d Add gocritic linter, fix a bunch of stuff (#7377)
Brace yourselves! For there are many touched files here. No changes
in semantics however.

Spent a long time trying out the various optional rules gocritic
provides, and settled for a few of them. There are more I really
like, but that would take many hours to address across the codebase.

Perhaps others find gocritic too pedantic? If so, we can merge the
fixes without enabling the rule.

Signed-off-by: Anders Eknert <anders@styra.com>
2025-02-24 16:28:41 +01:00
Anders Eknert 55e87e79ae Add perfsprint linter (#7334)
And update code to conform to the rule.

- Replace unnecessary fmt.Sprintf with string concatenation
- Replace fmt.Sprint with more efficient strconv.Itoa
- Replace static fmt.Errorf calls with more efficient errors.New

Thanks @srenatus for pushing me down this rabbit hole!

Signed-off-by: Anders Eknert <anders@styra.com>
2025-01-31 20:24:05 +01:00
Johan Fylling 563321d26b Rego v1 capabilities and keywords update (#7216)
* Separating v0- and v1 keywords
* Adding `rego_v1` capability feature

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-12-17 11:50:11 +01: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
Tyler Schade 5226cf3137 add ability for opa inspect to inspect a single file outside of any bundle (#6873)
add ability for opa inspect to inspect a single file outside of any bundle

Signed-off-by: Tyler Schade <tyler.schade@solo.io>
2024-07-21 20:22:52 +02:00
Johan Fylling b4679c25c6 Fix/inspect unknowns in with stmt (#6824)
Fixes: #6812
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-06-19 12:45:44 +02:00
Johan Fylling e23d771711 Add rego_version attribute to bundle manifest (#6579)
Adding a global `rego_version` attribute to bundle manifest, to inform OPA runtime about what rego-version (v0/v1) to use to parse/compile contained Rego files.
The rego-version of individual Rego files can be overridden through the `file_rego_versions` manifest attribute.

Implements: #6578

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-04-10 19:06:07 +02:00
Johan Fylling 0d703291ab ast+cmd: Allowing bundle to contain calls to unknown Rego functions when inspected
Fixes: #6591
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-02-15 10:45:47 -08: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
Johan Fylling 9f63fdb041 ast+cmd: Allowing bundle to contain calls to unknown functions when inspected (#6462)
Fixes: #6457

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2023-12-20 14:38:20 +01:00
Torin Sandall 8a8dd09f78 cmd: fix inspect to omit unnecessary whitespace
Signed-off-by: Torin Sandall <torin@styra.com>
2023-10-30 09:36:35 -07:00
Stephan Renatus cca81970d1 loader: change extension handler type (#6015)
This

1. changes the extension.Handler type to make it more flexible
2. simplifies the extension usage -- it used to be called in many places,
   but it could all be handled through util.Unmarshal and util.UnmarshalJSON
   instead

We've previously marked it as "EXPERIMENTAL", so we should have enough
leeway to change this now.

NOTE: As a consequence of (2.), we're no longer accepting trailing data for
json files loaded with OPA. I believe it wasn't intentional to ignore bad data
before -- now, it'll be an error.

Signed-off-by: Stephan Renatus <stephan@styra.com>
2023-06-16 09:37:33 +02:00
Johan Fylling f93d0f8fea bundle: Retain metadata annotations for Wasm entrypoints during inspection (#5603)
* Pruning METADATA blocks associated with Wasm compiled entrypoints from Rego source in bundle
* Adding metadata annotations to wasm entrypoint declarations in bundle .manifest file
* Reading metadata annotations from both Rego source and .manifest file in bundle during `inspect`

Fixes: #5588
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2023-02-03 12:15:21 +01:00
Johan Fylling c6226621c4 ast: Adding rego.metadata.* built-in functions (#4537)
New functions:
* rego.metadata.chain(): returns the chain of metadata, starting from the active rule, going outward
* rego.metadata.rule(): returns the metadata for the active rule

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2022-04-13 11:46:11 +02:00
Stephan Renatus 60e564fdaf cmd/inspect: render "related resources" and small misc changes (#4399)
Some small changes:

* cmd/inspect: inline ast.DropHead() as dropDataPrefix() -- to avoid the extra export in the ast package
* docs/annotations: update related_resources example
* cmd/inspect: unexport PageWidth
* cmd/inspect: make usage text markdown-friendly

   This looks better on the website docs, and doesn't matter much when
   viewed on the CLI.

* cmd/inspect: add test for pretty annotations output
* cmd/inspect: also render related_resources in pretty mode

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-03-03 11:17:56 +01:00
Johan Fylling 35d7e58a84 cmd: Adding annotations listing to inspect command (#4388)
By passing `-a` to `opa inspect`, it will pretty-print information
about the rules' and packages' annotations.

For all annotations, including related_resources, use `-fjson`.

Fixes: #4387

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2022-03-03 10:10:37 +01:00
Emily 7efa40b3b4 cmd/inspect: Update inspect to pretty print by default (#4021)
Inspect previously pretty printed only when -f pretty was specified. This change ensures that inspect pretty prints by default, and a user can specify --format=json to avoid relying on implicit default behaviour.

Fixes: #4021

Signed-off-by: Emily Tao
<tao.emily@yahoo.ca>
Signed-off-by: Emily Tao <tao.emily@yahoo.ca>
2021-11-30 21:53:05 +01:00
Ashutosh Narkar ec62838bb2 cmd/inspect: Add namespace for data file at root
Earlier we used an empty namespace for data file located
at bundle root. This change now uses "data" as the
namespace for a data file at root.

Fixes: #4022

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2021-11-22 23:59:06 -08:00
Ashutosh Narkar cdebc859ad Add command for bundle inspection
This commit adds a new subcommand in opa that inspects
a bundle and summarizes its structure and contents.

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2021-10-19 14:02:41 -07:00