github.com/quay/claircore@v1.5.28/matchers/defaults/defaults.go (about) 1 // Importing this package registers default matchers via its init function. 2 package defaults 3 4 import ( 5 "context" 6 "sync" 7 "time" 8 9 "github.com/quay/claircore/alpine" 10 "github.com/quay/claircore/aws" 11 "github.com/quay/claircore/debian" 12 "github.com/quay/claircore/gobin" 13 "github.com/quay/claircore/java" 14 "github.com/quay/claircore/libvuln/driver" 15 "github.com/quay/claircore/matchers/registry" 16 "github.com/quay/claircore/oracle" 17 "github.com/quay/claircore/photon" 18 "github.com/quay/claircore/python" 19 "github.com/quay/claircore/rhel" 20 "github.com/quay/claircore/rhel/rhcc" 21 "github.com/quay/claircore/ruby" 22 "github.com/quay/claircore/suse" 23 "github.com/quay/claircore/ubuntu" 24 ) 25 26 var ( 27 once sync.Once 28 regerr error 29 ) 30 31 func init() { 32 ctx, done := context.WithTimeout(context.Background(), 1*time.Minute) 33 defer done() 34 once.Do(func() { regerr = inner(ctx) }) 35 } 36 37 // Error reports if an error was encountered when initializing the default 38 // matchers. 39 func Error() error { 40 return regerr 41 } 42 43 // defaultMatchers is a variable containing 44 // all the matchers libvuln will use to match 45 // index records to vulnerabilities. 46 var defaultMatchers = []driver.Matcher{ 47 &alpine.Matcher{}, 48 &aws.Matcher{}, 49 &debian.Matcher{}, 50 &gobin.Matcher{}, 51 &java.Matcher{}, 52 &oracle.Matcher{}, 53 &photon.Matcher{}, 54 &python.Matcher{}, 55 rhcc.Matcher, 56 &rhel.Matcher{}, 57 &ruby.Matcher{}, 58 &suse.Matcher{}, 59 &ubuntu.Matcher{}, 60 } 61 62 func inner(ctx context.Context) error { 63 for _, m := range defaultMatchers { 64 mf := driver.MatcherStatic(m) 65 registry.Register(m.Name(), mf) 66 } 67 68 return nil 69 }