-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathalpine.go
50 lines (39 loc) · 1.06 KB
/
alpine.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
package alpine
import (
"bufio"
"context"
"os"
"golang.org/x/exp/slices"
"golang.org/x/xerrors"
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
fos "github.com/aquasecurity/trivy/pkg/fanal/analyzer/os"
"github.com/aquasecurity/trivy/pkg/fanal/types"
)
func init() {
analyzer.RegisterAnalyzer(&alpineOSAnalyzer{})
}
const version = 1
var requiredFiles = []string{"etc/alpine-release"}
type alpineOSAnalyzer struct{}
func (a alpineOSAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput) (*analyzer.AnalysisResult, error) {
scanner := bufio.NewScanner(input.Content)
for scanner.Scan() {
line := scanner.Text()
return &analyzer.AnalysisResult{
OS: types.OS{
Family: types.Alpine,
Name: line,
},
}, nil
}
return nil, xerrors.Errorf("alpine: %w", fos.AnalyzeOSError)
}
func (a alpineOSAnalyzer) Required(filePath string, _ os.FileInfo) bool {
return slices.Contains(requiredFiles, filePath)
}
func (a alpineOSAnalyzer) Type() analyzer.Type {
return analyzer.TypeAlpine
}
func (a alpineOSAnalyzer) Version() int {
return version
}