github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/pkg/scanners/options/scanner.go (about) 1 package options 2 3 import ( 4 "io" 5 "io/fs" 6 7 "github.com/khulnasoft-lab/defsec/pkg/framework" 8 ) 9 10 type ConfigurableScanner interface { 11 SetDebugWriter(io.Writer) 12 SetTraceWriter(io.Writer) 13 SetPerResultTracingEnabled(bool) 14 SetPolicyDirs(...string) 15 SetDataDirs(...string) 16 SetPolicyNamespaces(...string) 17 SetSkipRequiredCheck(bool) 18 SetPolicyReaders([]io.Reader) 19 SetPolicyFilesystem(fs.FS) 20 SetDataFilesystem(fs.FS) 21 SetUseEmbeddedPolicies(bool) 22 SetFrameworks(frameworks []framework.Framework) 23 SetSpec(spec string) 24 SetRegoOnly(regoOnly bool) 25 SetRegoErrorLimit(limit int) 26 SetUseEmbeddedLibraries(bool) 27 } 28 29 type ScannerOption func(s ConfigurableScanner) 30 31 func ScannerWithFrameworks(frameworks ...framework.Framework) ScannerOption { 32 return func(s ConfigurableScanner) { 33 s.SetFrameworks(frameworks) 34 } 35 } 36 37 func ScannerWithSpec(spec string) ScannerOption { 38 return func(s ConfigurableScanner) { 39 s.SetSpec(spec) 40 } 41 } 42 43 func ScannerWithPolicyReader(readers ...io.Reader) ScannerOption { 44 return func(s ConfigurableScanner) { 45 s.SetPolicyReaders(readers) 46 } 47 } 48 49 // ScannerWithDebug specifies an io.Writer for debug logs - if not set, they are discarded 50 func ScannerWithDebug(w io.Writer) ScannerOption { 51 return func(s ConfigurableScanner) { 52 s.SetDebugWriter(w) 53 } 54 } 55 56 func ScannerWithEmbeddedPolicies(embedded bool) ScannerOption { 57 return func(s ConfigurableScanner) { 58 s.SetUseEmbeddedPolicies(embedded) 59 } 60 } 61 62 func ScannerWithEmbeddedLibraries(enabled bool) ScannerOption { 63 return func(s ConfigurableScanner) { 64 s.SetUseEmbeddedLibraries(enabled) 65 } 66 } 67 68 // ScannerWithTrace specifies an io.Writer for trace logs (mainly rego tracing) - if not set, they are discarded 69 func ScannerWithTrace(w io.Writer) ScannerOption { 70 return func(s ConfigurableScanner) { 71 s.SetTraceWriter(w) 72 } 73 } 74 75 func ScannerWithPerResultTracing(enabled bool) ScannerOption { 76 return func(s ConfigurableScanner) { 77 s.SetPerResultTracingEnabled(enabled) 78 } 79 } 80 81 func ScannerWithPolicyDirs(paths ...string) ScannerOption { 82 return func(s ConfigurableScanner) { 83 s.SetPolicyDirs(paths...) 84 } 85 } 86 87 func ScannerWithDataDirs(paths ...string) ScannerOption { 88 return func(s ConfigurableScanner) { 89 s.SetDataDirs(paths...) 90 } 91 } 92 93 // ScannerWithPolicyNamespaces - namespaces which indicate rego policies containing enforced rules 94 func ScannerWithPolicyNamespaces(namespaces ...string) ScannerOption { 95 return func(s ConfigurableScanner) { 96 s.SetPolicyNamespaces(namespaces...) 97 } 98 } 99 100 func ScannerWithSkipRequiredCheck(skip bool) ScannerOption { 101 return func(s ConfigurableScanner) { 102 s.SetSkipRequiredCheck(skip) 103 } 104 } 105 106 func ScannerWithPolicyFilesystem(f fs.FS) ScannerOption { 107 return func(s ConfigurableScanner) { 108 s.SetPolicyFilesystem(f) 109 } 110 } 111 112 func ScannerWithDataFilesystem(f fs.FS) ScannerOption { 113 return func(s ConfigurableScanner) { 114 s.SetDataFilesystem(f) 115 } 116 } 117 118 func ScannerWithRegoOnly(regoOnly bool) ScannerOption { 119 return func(s ConfigurableScanner) { 120 s.SetRegoOnly(regoOnly) 121 } 122 } 123 124 func ScannerWithRegoErrorLimits(limit int) ScannerOption { 125 return func(s ConfigurableScanner) { 126 s.SetRegoErrorLimit(limit) 127 } 128 }