-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathapplier.go
40 lines (32 loc) · 1.11 KB
/
applier.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
package applier
import (
"golang.org/x/xerrors"
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
"github.com/aquasecurity/trivy/pkg/fanal/cache"
"github.com/aquasecurity/trivy/pkg/fanal/types"
)
type Applier struct {
cache cache.LocalArtifactCache
}
func NewApplier(c cache.LocalArtifactCache) Applier {
return Applier{cache: c}
}
func (a Applier) ApplyLayers(imageID string, layerKeys []string) (types.ArtifactDetail, error) {
var layers []types.BlobInfo
for _, key := range layerKeys {
blob, _ := a.cache.GetBlob(key) // nolint
if blob.SchemaVersion == 0 {
return types.ArtifactDetail{}, xerrors.Errorf("layer cache missing: %s", key)
}
layers = append(layers, blob)
}
mergedLayer := ApplyLayers(layers)
if mergedLayer.OS == nil {
return mergedLayer, analyzer.ErrUnknownOS // send back package and apps info regardless
} else if mergedLayer.Packages == nil {
return mergedLayer, analyzer.ErrNoPkgsDetected // send back package and apps info regardless
}
imageInfo, _ := a.cache.GetArtifact(imageID) // nolint
mergedLayer.HistoryPackages = imageInfo.HistoryPackages
return mergedLayer, nil
}