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