github.com/quay/claircore@v1.5.28/gobin/coalescer.go (about) 1 package gobin 2 3 import ( 4 "context" 5 "strings" 6 7 "github.com/quay/claircore" 8 "github.com/quay/claircore/indexer" 9 ) 10 11 type coalescer struct{} 12 13 func (c *coalescer) Coalesce(ctx context.Context, ls []*indexer.LayerArtifacts) (*claircore.IndexReport, error) { 14 ir := &claircore.IndexReport{ 15 Environments: map[string][]*claircore.Environment{}, 16 Packages: map[string]*claircore.Package{}, 17 Repositories: map[string]*claircore.Repository{}, 18 } 19 for _, l := range ls { 20 var rid string 21 for _, r := range l.Repos { 22 // Magic strings copied out of the osv package. 23 if r.Name != `go` || r.URI != `https://pkg.go.dev/` { 24 continue 25 } 26 rid = r.ID 27 ir.Repositories[r.ID] = r 28 break 29 } 30 for _, pkg := range l.Pkgs { 31 if !strings.HasPrefix(pkg.PackageDB, "go:") { 32 continue 33 } 34 ir.Packages[pkg.ID] = pkg 35 ir.Environments[pkg.ID] = []*claircore.Environment{ 36 { 37 PackageDB: pkg.PackageDB, 38 IntroducedIn: l.Hash, 39 RepositoryIDs: []string{rid}, 40 }, 41 } 42 } 43 } 44 return ir, nil 45 }