Skip to content

Commit 1b797d9

Browse files
authored
Make opa check respect --ignore when --bundle flag is set (#7137)
Fixes #7136 Signed-off-by: Anders Eknert <[email protected]>
1 parent 8e44b98 commit 1b797d9

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

cmd/check.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package cmd
77
import (
88
"fmt"
99
"io"
10+
"io/fs"
1011
"os"
1112

1213
"github.com/spf13/cobra"
@@ -87,6 +88,7 @@ func checkModules(params checkParams, args []string) error {
8788
WithSkipBundleVerification(true).
8889
WithProcessAnnotation(true).
8990
WithCapabilities(capabilities).
91+
WithFilter(filterFromPaths(params.ignore)).
9092
AsBundle(path)
9193
if err != nil {
9294
return err
@@ -130,6 +132,12 @@ func checkModules(params checkParams, args []string) error {
130132
return nil
131133
}
132134

135+
func filterFromPaths(paths []string) loader.Filter {
136+
return func(abspath string, info fs.FileInfo, depth int) bool {
137+
return loaderFilter{Ignore: paths}.Apply(abspath, info, depth)
138+
}
139+
}
140+
133141
func outputErrors(format string, err error) {
134142
var out io.Writer
135143
if err != nil {

cmd/check_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,27 @@ func TestCheckIgnoresNonRegoFiles(t *testing.T) {
188188
})
189189
}
190190

191+
func TestCheckIgnoreBundleMode(t *testing.T) {
192+
t.Parallel()
193+
194+
files := map[string]string{
195+
"ignore.rego": `invalid rego`,
196+
"include.rego": `package valid`,
197+
}
198+
199+
test.WithTempFS(files, func(root string) {
200+
params := newCheckParams()
201+
202+
params.ignore = []string{"ignore.rego"}
203+
params.bundleMode = true
204+
205+
err := checkModules(params, []string{root})
206+
if err != nil {
207+
t.Fatalf("unexpected error: %v", err)
208+
}
209+
})
210+
}
211+
191212
func TestCheckFailsOnInvalidRego(t *testing.T) {
192213
files := map[string]string{
193214
"test.rego": `package test

0 commit comments

Comments
 (0)