github.com/quay/claircore@v1.5.28/matchers/options.go (about) 1 package matchers 2 3 import ( 4 "github.com/quay/claircore/libvuln/driver" 5 ) 6 7 // WithEnabled configures the Matchers to only run the specified 8 // matchers. 9 // 10 // If enabled == nil all default matchers will run (same as not providing this option to the constructor at all). 11 // If len(enabled) == 0 no default matchers will run. 12 // If len(enabled) > 0 only provided matchers will be ran. 13 func WithEnabled(enabled []string) MatchersOption { 14 return func(m *Matchers) { 15 if enabled == nil { 16 return 17 } 18 19 factories := map[string]driver.MatcherFactory{} 20 for _, enable := range enabled { 21 for name, factory := range m.factories { 22 if name == enable { 23 factories[name] = factory 24 } 25 } 26 } 27 m.factories = factories 28 } 29 } 30 31 // WithConfigs tells the Matchers to configure each matcher where 32 // a configuration is provided. 33 // 34 // Configuration of individual matchers is delegated to matchers/registry/registry.go 35 // Note: this option is optimal when ran after WithEnabled option. However, 36 // this option has no strict depedency on others. 37 func WithConfigs(cfgs Configs) MatchersOption { 38 return func(m *Matchers) { 39 m.configs = cfgs 40 } 41 } 42 43 // WithOutOfTree allows callers to provide their own out-of-tree 44 // matchers. 45 func WithOutOfTree(outOfTree []driver.Matcher) MatchersOption { 46 return func(m *Matchers) { 47 m.matchers = outOfTree 48 } 49 }