github.com/quay/claircore@v1.5.28/rhel/rhcc/coalescer.go (about) 1 package rhcc 2 3 import ( 4 "context" 5 6 "github.com/quay/claircore" 7 "github.com/quay/claircore/indexer" 8 ) 9 10 // coalescer takes individual layer artifacts and coalesces them to form the final image's 11 // package results 12 type coalescer struct{} 13 14 func (c *coalescer) Coalesce(ctx context.Context, ls []*indexer.LayerArtifacts) (*claircore.IndexReport, error) { 15 if ctx.Err() != nil { 16 return nil, ctx.Err() 17 } 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 len(l.Repos) == 0 { 26 continue 27 } 28 rs := make([]string, len(l.Repos)) 29 for i, r := range l.Repos { 30 rs[i] = r.ID 31 ir.Repositories[r.ID] = r 32 } 33 for _, pkg := range l.Pkgs { 34 if pkg.RepositoryHint != `rhcc` { 35 continue 36 } 37 ir.Packages[pkg.ID] = pkg 38 ir.Environments[pkg.ID] = []*claircore.Environment{ 39 { 40 PackageDB: pkg.PackageDB, 41 IntroducedIn: l.Hash, 42 RepositoryIDs: rs, 43 }, 44 } 45 } 46 } 47 return ir, nil 48 }