-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(misconf): pass options to Rego scanner as is (#7529)
Signed-off-by: nikpivkin <[email protected]>
- Loading branch information
Showing
33 changed files
with
570 additions
and
1,095 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package rego | ||
|
||
import ( | ||
"io" | ||
"io/fs" | ||
|
||
"github.com/aquasecurity/trivy/pkg/iac/scanners/options" | ||
) | ||
|
||
func WithPolicyReader(readers ...io.Reader) options.ScannerOption { | ||
return func(s options.ConfigurableScanner) { | ||
if ss, ok := s.(*Scanner); ok { | ||
ss.policyReaders = readers | ||
} | ||
} | ||
} | ||
|
||
func WithEmbeddedPolicies(include bool) options.ScannerOption { | ||
return func(s options.ConfigurableScanner) { | ||
if ss, ok := s.(*Scanner); ok { | ||
ss.includeEmbeddedPolicies = include | ||
} | ||
} | ||
} | ||
|
||
func WithEmbeddedLibraries(include bool) options.ScannerOption { | ||
return func(s options.ConfigurableScanner) { | ||
if ss, ok := s.(*Scanner); ok { | ||
ss.includeEmbeddedLibraries = include | ||
} | ||
} | ||
} | ||
|
||
// WithTrace specifies an io.Writer for trace logs (mainly rego tracing) - if not set, they are discarded | ||
func WithTrace(w io.Writer) options.ScannerOption { | ||
return func(s options.ConfigurableScanner) { | ||
if ss, ok := s.(*Scanner); ok { | ||
ss.traceWriter = w | ||
} | ||
} | ||
} | ||
|
||
func WithPerResultTracing(enabled bool) options.ScannerOption { | ||
return func(s options.ConfigurableScanner) { | ||
if ss, ok := s.(*Scanner); ok { | ||
ss.tracePerResult = enabled | ||
} | ||
} | ||
} | ||
|
||
func WithPolicyDirs(paths ...string) options.ScannerOption { | ||
return func(s options.ConfigurableScanner) { | ||
if ss, ok := s.(*Scanner); ok { | ||
ss.policyDirs = paths | ||
} | ||
} | ||
} | ||
|
||
func WithDataDirs(paths ...string) options.ScannerOption { | ||
return func(s options.ConfigurableScanner) { | ||
if ss, ok := s.(*Scanner); ok { | ||
ss.dataDirs = paths | ||
} | ||
} | ||
} | ||
|
||
// WithPolicyNamespaces - namespaces which indicate rego policies containing enforced rules | ||
func WithPolicyNamespaces(namespaces ...string) options.ScannerOption { | ||
return func(s options.ConfigurableScanner) { | ||
if ss, ok := s.(*Scanner); ok { | ||
for _, namespace := range namespaces { | ||
ss.ruleNamespaces[namespace] = struct{}{} | ||
} | ||
} | ||
} | ||
} | ||
|
||
func WithPolicyFilesystem(fsys fs.FS) options.ScannerOption { | ||
return func(s options.ConfigurableScanner) { | ||
if ss, ok := s.(*Scanner); ok { | ||
ss.policyFS = fsys | ||
} | ||
} | ||
} | ||
|
||
func WithDataFilesystem(fsys fs.FS) options.ScannerOption { | ||
return func(s options.ConfigurableScanner) { | ||
if ss, ok := s.(*Scanner); ok { | ||
ss.dataFS = fsys | ||
} | ||
} | ||
} | ||
|
||
func WithRegoErrorLimits(limit int) options.ScannerOption { | ||
return func(s options.ConfigurableScanner) { | ||
if ss, ok := s.(*Scanner); ok { | ||
ss.regoErrorLimit = limit | ||
} | ||
} | ||
} | ||
|
||
func WithCustomSchemas(schemas map[string][]byte) options.ScannerOption { | ||
return func(s options.ConfigurableScanner) { | ||
if ss, ok := s.(*Scanner); ok { | ||
ss.customSchemas = schemas | ||
} | ||
} | ||
} |
Oops, something went wrong.