-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathcontent_manifest.go
55 lines (43 loc) · 1.29 KB
/
content_manifest.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
47
48
49
50
51
52
53
54
55
package buildinfo
import (
"context"
"encoding/json"
"os"
"path/filepath"
"golang.org/x/xerrors"
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
"github.com/aquasecurity/trivy/pkg/fanal/types"
)
func init() {
analyzer.RegisterAnalyzer(&contentManifestAnalyzer{})
}
const contentManifestAnalyzerVersion = 1
type contentManifest struct {
ContentSets []string `json:"content_sets"`
}
// For Red Hat products
type contentManifestAnalyzer struct{}
func (a contentManifestAnalyzer) Analyze(_ context.Context, target analyzer.AnalysisInput) (*analyzer.AnalysisResult, error) {
var manifest contentManifest
if err := json.NewDecoder(target.Content).Decode(&manifest); err != nil {
return nil, xerrors.Errorf("invalid content manifest: %w", err)
}
return &analyzer.AnalysisResult{
BuildInfo: &types.BuildInfo{
ContentSets: manifest.ContentSets,
},
}, nil
}
func (a contentManifestAnalyzer) Required(filePath string, _ os.FileInfo) bool {
dir, file := filepath.Split(filepath.ToSlash(filePath))
if dir != "root/buildinfo/content_manifests/" {
return false
}
return filepath.Ext(file) == ".json"
}
func (a contentManifestAnalyzer) Type() analyzer.Type {
return analyzer.TypeRedHatContentManifestType
}
func (a contentManifestAnalyzer) Version() int {
return contentManifestAnalyzerVersion
}