github.com/quay/claircore@v1.5.28/python/coalescer.go (about) 1 package python 2 3 import ( 4 "context" 5 6 "github.com/quay/claircore" 7 "github.com/quay/claircore/indexer" 8 ) 9 10 func NewCoalescer(_ context.Context) (indexer.Coalescer, error) { 11 return &coalescer{}, nil 12 } 13 14 type coalescer struct { 15 } 16 17 func (c *coalescer) Coalesce(ctx context.Context, ls []*indexer.LayerArtifacts) (*claircore.IndexReport, error) { 18 ir := &claircore.IndexReport{ 19 Environments: map[string][]*claircore.Environment{}, 20 Packages: map[string]*claircore.Package{}, 21 Repositories: map[string]*claircore.Repository{}, 22 } 23 24 for _, l := range ls { 25 // If we didn't find at least one pip repo in this layer 26 // no point in searching for packages. 27 if len(l.Repos) == 0 { 28 continue 29 } 30 rs := make([]string, len(l.Repos)) 31 for i, r := range l.Repos { 32 rs[i] = r.ID 33 ir.Repositories[r.ID] = r 34 } 35 for _, pkg := range l.Pkgs { 36 ir.Packages[pkg.ID] = pkg 37 ir.Environments[pkg.ID] = []*claircore.Environment{ 38 &claircore.Environment{ 39 PackageDB: pkg.PackageDB, 40 IntroducedIn: l.Hash, 41 RepositoryIDs: rs, 42 }, 43 } 44 } 45 } 46 return ir, nil 47 }