Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
8da347b
build(deps): bump github.com/moby/buildkit from 0.18.0 to 0.18.1 (#1024)
dependabot[bot] Dec 16, 2024
1e7d052
build(deps): bump golang from 1.23.3-alpine to 1.23.4-alpine (#1025)
dependabot[bot] Dec 16, 2024
4299ce7
build(deps): bump alpine from 3.20.3 to 3.21.0 (#1026)
dependabot[bot] Dec 16, 2024
642e7cd
build(deps): bump github.com/magiconair/properties from 1.8.7 to 1.8.…
dependabot[bot] Jan 6, 2025
5b3e926
build(deps): bump github.com/CycloneDX/cyclonedx-go from 0.9.1 to 0.9…
dependabot[bot] Jan 6, 2025
7428841
fix: set jsonnet VM stack limits and add test coverage
thevilledev Jan 15, 2025
8e541da
fix: improve handling for YAML version directives
thevilledev Jan 18, 2025
151643b
fix: add output and tests for GitHub and Azure DevOps
thevilledev Jan 18, 2025
8b34fcb
fix: remove redundant error check in push command
thevilledev Jan 18, 2025
c4e656f
build(deps): bump golang from 1.23.4-alpine to 1.23.5-alpine
dependabot[bot] Jan 20, 2025
163bdd8
fix: prevent policy file overwrite on downloads (#1039)
thevilledev Jan 22, 2025
0bbb473
fix: max stack size already set by jsonnet.MakeVM()
thevilledev Jan 23, 2025
4df824c
build(deps): bump cuelang.org/go from 0.11.0 to 0.12.0
dependabot[bot] Jan 30, 2025
ea55b61
Merge pull request #1051 from open-policy-agent/dependabot/go_modules…
anderseknert Jan 31, 2025
1a4a428
build(deps): bump github.com/moby/buildkit from 0.18.1 to 0.19.0
dependabot[bot] Jan 31, 2025
744f867
Merge pull request #1046 from open-policy-agent/dependabot/go_modules…
anderseknert Jan 31, 2025
1a25844
Merge pull request #1043 from open-policy-agent/dependabot/docker/gol…
anderseknert Jan 31, 2025
154c1aa
build(deps): bump alpine from 3.21.0 to 3.21.2
dependabot[bot] Jan 31, 2025
1d47ac3
build(deps): bump github.com/hashicorp/go-getter from 1.7.6 to 1.7.8
dependabot[bot] Jan 31, 2025
d5e8a77
Merge pull request #1036 from open-policy-agent/dependabot/go_modules…
anderseknert Jan 31, 2025
24e9ca8
chore: optimize yaml document separator handling
thevilledev Jan 31, 2025
3096ca7
Merge pull request #1038 from thevilledev/fix/yaml-preamble-multidoc
anderseknert Jan 31, 2025
6b31946
Merge pull request #1040 from thevilledev/fix/missing-outputs
anderseknert Jan 31, 2025
a603656
Merge pull request #1037 from thevilledev/fix/recursive-jsonnet
anderseknert Jan 31, 2025
aa9e3c8
feat: enable relative jsonnet imports by setting a path-aware importer
thevilledev Jan 20, 2025
326a1a4
Merge pull request #1044 from thevilledev/fix/jsonnet-library-imports
anderseknert Jan 31, 2025
5063084
Merge pull request #1041 from thevilledev/fix/impossible-nil
anderseknert Jan 31, 2025
a770d29
fix: correct linters-settings in .golangci.yaml to enable misspell
thevilledev Jan 31, 2025
356ede4
Merge pull request #1035 from open-policy-agent/dependabot/docker/alp…
anderseknert Jan 31, 2025
6c867fc
Merge pull request #1052 from thevilledev/fix/linters-settings
anderseknert Jan 31, 2025
874f0bc
chore: add nilness check to govet linter
thevilledev Jan 31, 2025
f110dde
Merge pull request #1053 from thevilledev/style/enable-nilness-lint
anderseknert Feb 1, 2025
bad47e2
test(registry): add test for credentials store init failure
thevilledev Feb 1, 2025
3f67b78
feature: Documentation command (#1009)
xNok Feb 5, 2025
26b6c24
Merge pull request #1054 from thevilledev/test/registry-store-init
anderseknert Feb 5, 2025
256bf5e
test(policy): improve engine test coverage (#1055)
thevilledev Feb 8, 2025
19c82bc
build(deps): bump github.com/open-policy-agent/opa from 0.70.0 to 1.1…
dependabot[bot] Feb 9, 2025
6da5673
build(deps): bump golang from 1.23.5-alpine to 1.23.6-alpine (#1062)
dependabot[bot] Feb 11, 2025
eacba23
feat(engine): add query metadata to evaluation results (#1061)
thevilledev Feb 11, 2025
8a44613
engine: Refactor to allow for Rego version to be specified (#1059)
jalseth Feb 15, 2025
5decd18
feat(parser): handle UTF-8 BOM in JSON input (#1065)
thevilledev Feb 15, 2025
9efcd87
test(plugin): add comprehensive plugin package tests (#1056)
thevilledev Feb 15, 2025
abad255
feat: Implement SARIF output (#1042)
thevilledev Feb 15, 2025
155cd3c
chore: Change empty interface{} to any throughout the codebase (#1057)
jalseth Feb 19, 2025
278f735
chore: Update all examples to OPA V1 syntax (#1058)
jalseth Feb 19, 2025
cdd65ba
refactor(output): Add CheckResults type and helpers (#1063)
jalseth Feb 25, 2025
4154949
feat(test): Enable inter-query cache (#1073)
jalseth Feb 25, 2025
6424545
build(deps): bump github.com/open-policy-agent/opa from 1.1.0 to 1.2.…
dependabot[bot] Mar 1, 2025
8e0fdf2
build(deps): bump alpine from 3.21.2 to 3.21.3 (#1072)
dependabot[bot] Mar 1, 2025
6cb9d19
build(deps): bump github.com/moby/buildkit from 0.19.0 to 0.20.0 (#1076)
dependabot[bot] Mar 1, 2025
854183b
refactor(ci): replace Makefile-based Docker builds with GitHub Action…
Amamgbu Mar 1, 2025
43264f4
build(deps): bump golang from 1.23.6-alpine to 1.24.0-alpine (#1071)
dependabot[bot] Mar 1, 2025
d62aa8d
feat: add --absolute-paths flag to pull command (#1078)
thevilledev Mar 1, 2025
5ae180f
docs: clarify --trace flag behavior with --output flag (#1060)
thevilledev Mar 1, 2025
4435c65
fix: Conftest can now successfully load files using a file URL (e.g.…
pckvcode Mar 1, 2025
39bd5fc
ci: Revert "replace Makefile-based Docker builds with GitHub Action… …
jalseth Mar 1, 2025
a20159b
build(deps): bump github.com/moby/buildkit from 0.20.0 to 0.20.1 (#1083)
dependabot[bot] Mar 7, 2025
6a9a474
docs: add documentation feature to the navigation bar (#1087)
boranx Mar 14, 2025
21e1163
feat: add pre-commit hook support (#1077)
thevilledev Mar 20, 2025
1b1ce3a
build(deps): bump golang from 1.24.0-alpine to 1.24.1-alpine (#1086)
dependabot[bot] Mar 20, 2025
45bf533
build(deps): bump github.com/BurntSushi/toml from 1.4.0 to 1.5.0 (#1089)
dependabot[bot] Mar 20, 2025
8c8b13f
ci: Remove PR workflow access to all permissions from GITHUB_TOKEN (#…
jalseth Mar 23, 2025
32aac49
build(deps): bump github.com/moby/buildkit from 0.20.1 to 0.20.2 (#1091)
dependabot[bot] Mar 30, 2025
eac6f5e
build(deps): bump github.com/open-policy-agent/opa from 1.2.0 to 1.3.…
dependabot[bot] Mar 30, 2025
cb88a17
build(deps): bump golang from 1.24.1-alpine to 1.24.2-alpine (#1096)
dependabot[bot] Apr 8, 2025
813f329
build(deps): bump cuelang.org/go from 0.12.0 to 0.12.1 (#1094)
dependabot[bot] Apr 8, 2025
19f1eaf
build(deps): bump github.com/magiconair/properties from 1.8.9 to 1.8.…
dependabot[bot] Apr 12, 2025
688c88f
deps: Bump hcl2json to v0.6.7 (#1074)
jalseth Apr 12, 2025
e9612c3
refactor(ci): replace Makefile-based Docker builds with GitHub Action…
Amamgbu Apr 12, 2025
7bec660
docs: update default template link to use absolute URL (#1099)
thevilledev Apr 19, 2025
3ae2e78
chore: Update Github Actions via Dependabot (#1100)
mrueg Apr 19, 2025
b3d0491
build(deps): bump golangci/golangci-lint-action from 6 to 7 (#1103)
dependabot[bot] Apr 20, 2025
67a3c3e
build(deps): bump actions/setup-go from 4 to 5 (#1102)
dependabot[bot] Apr 20, 2025
609490f
build(deps): bump bats-core/bats-action from 1.5.4 to 3.0.1 (#1104)
dependabot[bot] Apr 20, 2025
4c5e5f5
ci: Move docker build to separate job in the PR workflow (#1105)
jalseth Apr 24, 2025
18a0f14
feat(runner): add support for symlinks (#1098)
Apr 26, 2025
06658d4
feat(output): redirect trace output to stderr (#1084)
thevilledev Apr 26, 2025
5ea0446
build(deps): bump github.com/moby/buildkit from 0.20.2 to 0.21.0 (#1101)
dependabot[bot] Apr 26, 2025
21a73eb
build(deps): bump github.com/moby/buildkit from 0.21.0 to 0.21.1 (#1111)
dependabot[bot] May 4, 2025
2797c99
build(deps): bump github.com/open-policy-agent/opa from 1.3.0 to 1.4.…
dependabot[bot] May 4, 2025
c0799c4
docs: Make examples in the docs compatible with v1 syntax (#1115)
jalseth May 7, 2025
3907482
cli: Make Rego v1 syntax the default (#1114)
jalseth May 7, 2025
e894c43
build(deps): bump golangci/golangci-lint-action from 7 to 8 (#1119)
dependabot[bot] May 7, 2025
9e56924
build(deps): bump github.com/google/go-jsonnet from 0.20.0 to 0.21.0 …
dependabot[bot] May 9, 2025
1441245
docs: Update README.md to make it compatible with v1 syntax (#1122)
IshentRas May 10, 2025
1fe40dd
Merge remote-tracking branch 'upstream/master'
janmooij May 16, 2025
03ff170
Merge remote-tracking branch 'upstream/master' into janmooij/v0.60.0
janmooij May 16, 2025
c50d866
fix: revert makefile changes
janmooij May 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(output): Add CheckResults type and helpers (open-policy-agen…
…t#1063)

Adding a new type for a slice of CheckResult to add helper methods for
checking if there were failures, warnings, or exceptions.

Signed-off-by: James Alseth <[email protected]>
  • Loading branch information
jalseth authored Feb 25, 2025
commit cdd65ba3a46b8292a96ac4a30ca3c04d4a28674e
6 changes: 2 additions & 4 deletions internal/commands/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,9 @@ func NewTestCommand(ctx context.Context) *cobra.Command {
return fmt.Errorf("running test: %w", err)
}

var exitCode int
exitCode := results.ExitCode()
if runner.FailOnWarn {
exitCode = output.ExitCodeFailOnWarn(results)
} else {
exitCode = output.ExitCode(results)
exitCode = results.ExitCodeFailOnWarn()
}

if !runner.Quiet || exitCode != 0 {
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func NewVerifyCommand(ctx context.Context) *cobra.Command {
return fmt.Errorf("running verification: %w", err)
}

exitCode := output.ExitCode(results)
exitCode := results.ExitCode()
if !runner.Quiet || exitCode != 0 {
outputter := output.Get(runner.Output, output.Options{
NoColor: runner.NoColor,
Expand Down
2 changes: 1 addition & 1 deletion output/azuredevops.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewAzureDevOps(w io.Writer) *AzureDevOps {
}

// Output outputs the results.
func (t *AzureDevOps) Output(checkResults []CheckResult) error {
func (t *AzureDevOps) Output(checkResults CheckResults) error {
var totalFailures int
var totalExceptions int
var totalWarnings int
Expand Down
10 changes: 5 additions & 5 deletions output/azuredevops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
func TestAzureDevOps(t *testing.T) {
tests := []struct {
name string
input []CheckResult
input CheckResults
expected []string
}{
{
name: "no warnings or errors",
input: []CheckResult{
input: CheckResults{
{
FileName: "examples/kubernetes/service.yaml",
Namespace: "namespace",
Expand All @@ -30,7 +30,7 @@ func TestAzureDevOps(t *testing.T) {
},
{
name: "records failure and warnings",
input: []CheckResult{
input: CheckResults{
{
FileName: "examples/kubernetes/service.yaml",
Namespace: "namespace",
Expand All @@ -50,7 +50,7 @@ func TestAzureDevOps(t *testing.T) {
},
{
name: "mixed failure, warnings and skipped",
input: []CheckResult{
input: CheckResults{
{
FileName: "examples/kubernetes/service.yaml",
Namespace: "namespace",
Expand All @@ -70,7 +70,7 @@ func TestAzureDevOps(t *testing.T) {
},
{
name: "handles stdin input",
input: []CheckResult{
input: CheckResults{
{
FileName: "-",
Namespace: "namespace",
Expand Down
2 changes: 1 addition & 1 deletion output/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewGitHub(w io.Writer) *GitHub {
}

// Output outputs the results.
func (t *GitHub) Output(checkResults []CheckResult) error {
func (t *GitHub) Output(checkResults CheckResults) error {
var totalFailures int
var totalExceptions int
var totalWarnings int
Expand Down
10 changes: 5 additions & 5 deletions output/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
func TestGitHub(t *testing.T) {
tests := []struct {
name string
input []CheckResult
input CheckResults
expected []string
}{
{
name: "no warnings or errors",
input: []CheckResult{
input: CheckResults{
{
FileName: "examples/kubernetes/service.yaml",
Namespace: "namespace",
Expand All @@ -29,7 +29,7 @@ func TestGitHub(t *testing.T) {
},
{
name: "records failure and warnings",
input: []CheckResult{
input: CheckResults{
{
FileName: "examples/kubernetes/service.yaml",
Namespace: "namespace",
Expand All @@ -48,7 +48,7 @@ func TestGitHub(t *testing.T) {
},
{
name: "mixed failure, warnings and skipped",
input: []CheckResult{
input: CheckResults{
{
FileName: "examples/kubernetes/service.yaml",
Namespace: "namespace",
Expand All @@ -67,7 +67,7 @@ func TestGitHub(t *testing.T) {
},
{
name: "handles stdin input",
input: []CheckResult{
input: CheckResults{
{
FileName: "-",
Namespace: "namespace",
Expand Down
2 changes: 1 addition & 1 deletion output/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewJSON(w io.Writer) *JSON {
}

// Output outputs the results.
func (j *JSON) Output(results []CheckResult) error {
func (j *JSON) Output(results CheckResults) error {
for r := range results {
if results[r].FileName == "-" {
results[r].FileName = ""
Expand Down
12 changes: 6 additions & 6 deletions output/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
func TestJSON(t *testing.T) {
tests := []struct {
name string
input []CheckResult
input CheckResults
expected []string
}{
{
name: "No warnings or errors",
input: []CheckResult{
input: CheckResults{
{
FileName: "examples/kubernetes/service.yaml",
Namespace: "namespace",
Expand All @@ -33,7 +33,7 @@ func TestJSON(t *testing.T) {
},
{
name: "A single failure",
input: []CheckResult{
input: CheckResults{
{
FileName: "examples/kubernetes/service.yaml",
Namespace: "namespace",
Expand All @@ -58,7 +58,7 @@ func TestJSON(t *testing.T) {
},
{
name: "A warning, a failure and a skipped test",
input: []CheckResult{
input: CheckResults{
{
FileName: "examples/kubernetes/service.yaml",
Namespace: "namespace",
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestJSON(t *testing.T) {
},
{
name: "Renames standard input file name to empty string",
input: []CheckResult{
input: CheckResults{
{
FileName: "-",
Namespace: "namespace",
Expand All @@ -120,7 +120,7 @@ func TestJSON(t *testing.T) {
},
{
name: "Multiple files",
input: []CheckResult{
input: CheckResults{
{FileName: "examples/kubernetes/service.yaml", Namespace: "namespace"},
{FileName: "examples/kubernetes/deployment.yaml", Namespace: "namespace"},
},
Expand Down
2 changes: 1 addition & 1 deletion output/junit.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewJUnit(w io.Writer, hideMessage bool) *JUnit {
}

// Output outputs the results.
func (j *JUnit) Output(results []CheckResult) error {
func (j *JUnit) Output(results CheckResults) error {
namespaceTests := make(map[string][]*parser.Test)
for _, result := range results {
ns := result.Namespace
Expand Down
10 changes: 5 additions & 5 deletions output/junit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
func TestJUnit(t *testing.T) {
tests := []struct {
name string
input []CheckResult
input CheckResults
hideMessage bool
expected []string
}{
{
name: "No warnings or failures",
input: []CheckResult{
input: CheckResults{
{
FileName: "examples/kubernetes/service.yaml",
Namespace: "namespace",
Expand All @@ -31,7 +31,7 @@ func TestJUnit(t *testing.T) {
},
{
name: "A warning, a failure and a skipped test",
input: []CheckResult{
input: CheckResults{
{
FileName: "examples/kubernetes/service.yaml",
Namespace: "namespace",
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestJUnit(t *testing.T) {
},
{
name: "Failure with a long description",
input: []CheckResult{
input: CheckResults{
{
FileName: "examples/kubernetes/service.yaml",
Namespace: "namespace",
Expand All @@ -90,7 +90,7 @@ This is the rest of the description of the failed test`}},
{
name: "Failure with --junit-hide-message set",
hideMessage: true,
input: []CheckResult{
input: CheckResults{
{
FileName: "examples/kubernetes/service.yaml",
Namespace: "namespace",
Expand Down
2 changes: 1 addition & 1 deletion output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
// Outputter controls how results of an evaluation will
// be recorded and reported to the end user.
type Outputter interface {
Output([]CheckResult) error
Output(CheckResults) error
Report([]*tester.Result, string) error
}

Expand Down
80 changes: 52 additions & 28 deletions output/result.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package output

import "fmt"
import (
"fmt"
"slices"
)

// Result describes the result of a single rule evaluation.
type Result struct {
Expand Down Expand Up @@ -85,46 +88,67 @@ type CheckResult struct {
Queries []QueryResult `json:"queries,omitempty"`
}

// HasFailure returns true if any failures were encountered.
func (cr CheckResult) HasFailure() bool {
return len(cr.Failures) > 0
}

// HasWarning returns true if any warnings were encountered.
func (cr CheckResult) HasWarning() bool {
return len(cr.Warnings) > 0
}

// HasException returns true if any exceptions were encountered.
func (cr CheckResult) HasException() bool {
return len(cr.Exceptions) > 0
}

// OnlySuccess returns true if there are no failures, warnings, or exceptions.
func (cr CheckResult) OnlySuccess() bool {
return len(cr.Failures) == 0 && len(cr.Warnings) == 0 && len(cr.Exceptions) == 0
}

// CheckResults is a slice of CheckResult.
type CheckResults []CheckResult

// HasFailure returns true if any of the checks in the list has a failure.
func (cr CheckResults) HasFailure() bool {
return slices.ContainsFunc(cr, func(x CheckResult) bool { return x.HasFailure() })
}

// HasWarning returns true if any of the checks in the list has a warning.
func (cr CheckResults) HasWarning() bool {
return slices.ContainsFunc(cr, func(x CheckResult) bool { return x.HasWarning() })
}

// HasException returns true if any of the checks in the list has an exception.
func (cr CheckResults) HasException() bool {
return slices.ContainsFunc(cr, func(x CheckResult) bool { return x.HasException() })
}

// OnlySuccess returns true if all of the checks have only success messages.
func (cr CheckResults) OnlySuccess() bool {
return !slices.ContainsFunc(cr, func(x CheckResult) bool { return !x.OnlySuccess() })
}

// ExitCode returns the exit code that should be returned
// given all of the returned results.
func ExitCode(results []CheckResult) int {
var hasFailure bool
for _, result := range results {
if len(result.Failures) > 0 {
hasFailure = true
}
}

if hasFailure {
func (cr CheckResults) ExitCode() int {
if cr.HasFailure() {
return 1
}

return 0
}

// ExitCodeFailOnWarn returns the exit code that should be returned
// given all of the returned results, and will consider warnings
// as failures.
func ExitCodeFailOnWarn(results []CheckResult) int {
var hasFailure bool
var hasWarning bool
for _, result := range results {
if len(result.Failures) > 0 {
hasFailure = true
}

if len(result.Warnings) > 0 {
hasWarning = true
}
}

if hasFailure {
func (cr CheckResults) ExitCodeFailOnWarn() int {
if cr.HasFailure() {
return 2
}

if hasWarning {
if cr.HasWarning() {
return 1
}

return 0
}
Loading