github.com/devseccon/trivy@v0.47.1-0.20231123133102-bd902a0bd996/pkg/scanner/post/post_scan.go (about) 1 package post 2 3 import ( 4 "context" 5 6 "golang.org/x/xerrors" 7 8 "github.com/devseccon/trivy/pkg/types" 9 ) 10 11 type Scanner interface { 12 Name() string 13 Version() int 14 PostScan(ctx context.Context, results types.Results) (types.Results, error) 15 } 16 17 func RegisterPostScanner(s Scanner) { 18 // Avoid duplication 19 postScanners[s.Name()] = s 20 } 21 22 func DeregisterPostScanner(name string) { 23 delete(postScanners, name) 24 } 25 26 func ScannerVersions() map[string]int { 27 versions := make(map[string]int) 28 for _, s := range postScanners { 29 versions[s.Name()] = s.Version() 30 } 31 return versions 32 } 33 34 var postScanners = make(map[string]Scanner) 35 36 func Scan(ctx context.Context, results types.Results) (types.Results, error) { 37 var err error 38 for _, s := range postScanners { 39 results, err = s.PostScan(ctx, results) 40 if err != nil { 41 return nil, xerrors.Errorf("%s post scan error: %w", s.Name(), err) 42 } 43 } 44 return results, nil 45 }