8 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
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 a60ef72799 Even less allocs (#7190)
**main**
```
BenchmarkLintAllEnabled-10    1	2640715625 ns/op	6385110200 B/op	116296633 allocs/op
```

**pr**
```
BenchmarkLintAllEnabled-10    1	2597179708 ns/op	6183614112 B/op	108421141 allocs/op
```

(I renamed the benchmark, but this is the same as "regal linting itself"
used in the past)

Another 8 million allocations cut off from `regal lint bundle`,
and a whopping 10% improvements to wall clock time!

The most significant improvement is the Equal implementation for
refs, since that is called all over the place. But there are many
other fixes here, and they all contribute something substantial
(and fixes that only have had marginal impact have been left out).

Signed-off-by: Anders Eknert <anders@styra.com>
2024-11-24 11:24:29 +01:00
Manuel Rüger 9cab6c95cf chore: Replace ghodss/yaml with sigs.k8s.io/yaml (#6195)
This is a fork that is maintained by the kubernetes community.

https://github.com/kubernetes-sigs/yaml

Signed-off-by: Manuel Rüger <manuel@rueg.eu>
2023-08-30 15:08:36 +02:00
Stephan Renatus 51f9acbf98 internal/strvals: port helm strvals fix (CLI --set arguments)(#5315)
The impact of this in OPA is minimal: when passing for example

    --set "abc[9999999999999]=123"

to `opa run` or `opa exec`, it would run out of memory. With this change, it
will return an error instead:

    $ opa exec --set "abc[9999999999999]=123" .
    {"err":"config error: failed parsing --set data: index of 9999999999999 is greater than maximum supported index of 65536",
     "level":"error","msg":"Unexpected error.","time":"2022-10-27T10:24:01+02:00"}

Since these parameters are never user-controlled, or accessible at
runtime, any attack vector here involves having access to a machines
CLI, and is thus equivalent to already having local user rights. The
affected instance of OPA would be the instance that is started -- so no
others would be affected.

Thanks to @pjbgf for bringing this up on the security mailing list.

See also the issue in helm,
https://github.com/fluxcd/flux2/security/advisories/GHSA-p2g7-xwvr-rrw3.

The changes have been ported from @mattfarina fix in
https://github.com/helm/helm/commit/225f8d7732aba378378e7507655157b1d26cd514.

More stuff has happened on that package in helm, and new features have been
added -- but I've refrained from pulling all that in.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-10-27 10:41:05 +02:00
Ashutosh Narkar 62e9bab0a5 internal: Update the return value for typed value null
This commit updates the parser for --set options
to return empty struct as return value when null
is specified. This is needed to set an empty object
with the CLI overrides for a null typed value.

Fixes: #3846

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2021-10-06 12:10:22 -07: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
Patrick East de50c4372d Borrow the strvals package from helm
We will use it (or a modified version) to allow for setting config easier on the CLI.

Signed-off-by: Patrick East <east.patrick@gmail.com>
2019-04-10 10:39:16 -07:00