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