github.com/quay/claircore@v1.5.28/ruby/coalescer.go (about) 1 package ruby 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 func (c *coalescer) Coalesce(_ context.Context, ls []*indexer.LayerArtifacts) (*claircore.IndexReport, error) { 17 ir := &claircore.IndexReport{ 18 Environments: map[string][]*claircore.Environment{}, 19 Packages: map[string]*claircore.Package{}, 20 Repositories: map[string]*claircore.Repository{}, 21 } 22 23 for _, l := range ls { 24 // If we didn't find at least one gem repo in this layer 25 // no point in searching for packages. 26 if len(l.Repos) == 0 { 27 continue 28 } 29 rs := make([]string, len(l.Repos)) 30 for i, r := range l.Repos { 31 rs[i] = r.ID 32 ir.Repositories[r.ID] = r 33 } 34 for _, pkg := range l.Pkgs { 35 ir.Packages[pkg.ID] = pkg 36 ir.Environments[pkg.ID] = []*claircore.Environment{ 37 { 38 PackageDB: pkg.PackageDB, 39 IntroducedIn: l.Hash, 40 RepositoryIDs: rs, 41 }, 42 } 43 } 44 } 45 return ir, nil 46 }