25 Commits

Author SHA1 Message Date
Ville Vesilehto f77322b3fb build: bump Go version requirement to 1.24 (#7839)
Go 1.23 is no longer supported as per Go release policy.

Changes:

- Use Go v1.24.6 as the project SDK requirement
- Apply lint fixes for Go 1.24
- Fix "non-constant format string in call" issues as seen in CI.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2025-08-24 09:02:09 +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 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
Anders Eknert bd5ceb5142 Enable unused-receiver linter (revive) (#7448)
Signed-off-by: Anders Eknert <anders@styra.com>
2025-03-14 11:41:25 +01: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 58c7d7aff2 Bump golangci-lint -> 1.64.5 (#7374)
Also:
- Replace deprecated tenv linter with usetesting, and address
  the issues it reported (nice!)

Signed-off-by: Anders Eknert <anders@styra.com>
2025-02-19 10:29:17 +01:00
Anders Eknert f32199e9be Add decision ID to opa exec output (#7373)
Signed-off-by: Anders Eknert <anders@styra.com>
2025-02-18 21:38:14 +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 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
Anders Eknert af8f915846 Add mirror linter
This flags unnecessary conversions of byte->string and vice versa

Signed-off-by: Anders Eknert <anders@eknert.com>
2024-09-26 13:45:37 -07:00
Johan Fylling 5521453d87 cmd: Adding --v0-compatible flag (#7065)
To make OPA behave as v0.x post v1.0 release.
If used simultaneously with `--v1-compatible` flag, the `--v0-compatible` flag takes precedence.

Also, future-proofing `cmd` package tests for 1.0.

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-09-26 00:45:51 +02:00
Stephan Renatus ed14340916 cmd/exec: remove "pretty" format (#6923)
This was never supported, and the flag is thus confusing. Since the
only supported format is "json" (the default), the flag is redundant
now. However, I've kept it so if someone uses `opa exec --format=json`
somewhere, their calls won't become invalid.

If someone had been using `opa exec --format=pretty`, they will now
see an error, but I think that's less confusing: pretty formatting
is just not supported for 'opa exec'.

Signed-off-by: Stephan Renatus <stephan@styra.com>
2024-08-13 14:40:44 +02:00
Johan Fylling e50a3061f5 cmd/exec: Supporting simultaneous input from stdin and files (#6831)
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-06-26 15:54:01 +02:00
Colin J Lacy 96800d747b cmd/exec: adds --stdin-input (-I) flag for input piping or manual entry (#6822)
Signed-off-by: Colin Lacy <colinjlacy@gmail.com>
2024-06-26 15:04:54 +02:00
Johan Fylling 5464b005e8 Bumping golangci-lint to v1.59.1 (#6817)
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-06-19 15:13:43 +02:00
Philip Conrad 6b7ede0ee0 cmd/exec: Add timeout flag to help prevent infinite hangs. (#6633)
This commit adds a `--timeout` duration flag to the `opa exec` CLI command.
This flag helps out in use cases such as CI, where stalling indefinitely
is undesirable behavior.

Fixes: #6613

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
2024-03-18 12:22:41 -04:00
Colin J Lacy 4bfae4e64e cmd: add env var backups to command flags (#6508)
Signed-off-by: Colin Lacy <colinjlacy@gmail.com>
2024-01-29 15:15:35 +01: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
Ashutosh Narkar eade10ae0e build: Remove rootless image variant
All published OPA images now run with a non-root uid/gid.
The uid:gid is set to 1000:1000 for all images. As a result
there is no longer a need for the --rootless image variant
hence it will not be published as part of future releases.
This change is in line with container security best practices.
OPA can still be run with root privileges by explicitly setting the user,
either with the --user argument for docker run, or by specifying
the securityContext in the Kubernetes Pod specification.

Fixes: #4295

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2023-11-02 08:55:09 -07:00
Ronnie-personal c3854aa6ae feat(cmd): Adding fail-non-empty flag (#6153)
Add fail-non-empty flag to opa exec

Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
2023-08-21 11:30:25 +02:00
Charlie Egan d584a15d53 [cmd] Implement rootless deprecation messages
I have added a system for showing fatal and non-fatal deprecation warnings. It's configurable by command and environment.

If we merge this PR, running a rootless image with any OPA command other than `opa run` will result in a fatal error and exit code 1.

It's possible for users to continue to use the image by unsetting: OPA_DOCKER_IMAGE_TAG=rootless.

`opa run` will show the message, but it's not fatal for this command. This is intended to avoid production disruption.

Signed-off-by: Charlie Egan <charlie@styra.com>
2023-07-14 11:38:17 -07: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
Byron Lagrone 235ee309da cmd/exec: add --fail and --fail-defined flags (#5295)
Adds the ability to exit with a non-zero exit code for 'opa exec' by adding the
--fail and --fail-defined flags matching their respective behaviors in 'opa eval':

- Setting the --fail-defined flag allows exit of opa exec with a zero code if all
   results are undefined and there are no errors, or a non-zero code in the
   event of any defined results and/or errors.
   On non-zero exits the error message includes the number of failures/errors
   as well as a reference to the --fail-defined flag being set.
- The --fail flag behaves as the inverse of --fail-defined.

Fixes: #5007

Signed-off-by: Byron Lagrone <byron.lagrone@seqster.com>
2022-10-26 10:43:07 +02:00
Sergey Vilgelm 5e51af9244 logger: Configure timestamp format (#5050)
With this, we allow the user to configure the logger's timestamp format by:
* cli argument `log-timestamp-format`
* environment variable `OPA_LOG_TIMESTAMP_FORMAT`

Fixes #2413.

Signed-off-by: Sergey Vilgelm <sergey@vilgelm.com>
2022-08-29 14:23:48 +02:00
Torin Sandall 55b053b79a cmd/exec: Add new exec subcommand
This is just a skeleton but the basic functionality is there: run OPA
in a "one shot" mode against a set of input files and print the
results for each.

Fixes #3525

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2021-12-22 17:46:37 +01:00