-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
oracle.go
57 lines (43 loc) · 1.32 KB
/
oracle.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
56
57
package redhatbase
import (
"bufio"
"context"
"os"
"strings"
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
"github.com/aquasecurity/trivy/pkg/fanal/utils"
"golang.org/x/xerrors"
aos "github.com/aquasecurity/trivy/pkg/fanal/analyzer/os"
"github.com/aquasecurity/trivy/pkg/fanal/types"
)
const oracleAnalyzerVersion = 1
func init() {
analyzer.RegisterAnalyzer(&oracleOSAnalyzer{})
}
type oracleOSAnalyzer struct{}
func (a oracleOSAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput) (*analyzer.AnalysisResult, error) {
scanner := bufio.NewScanner(input.Content)
for scanner.Scan() {
line := scanner.Text()
result := redhatRe.FindStringSubmatch(strings.TrimSpace(line))
if len(result) != 3 {
return nil, xerrors.New("oracle: invalid oracle-release")
}
return &analyzer.AnalysisResult{
OS: types.OS{Family: aos.Oracle, Name: result[2]},
}, nil
}
return nil, xerrors.Errorf("oracle: %w", aos.AnalyzeOSError)
}
func (a oracleOSAnalyzer) Required(filePath string, _ os.FileInfo) bool {
return utils.StringInSlice(filePath, a.requiredFiles())
}
func (a oracleOSAnalyzer) requiredFiles() []string {
return []string{"etc/oracle-release"}
}
func (a oracleOSAnalyzer) Type() analyzer.Type {
return analyzer.TypeOracle
}
func (a oracleOSAnalyzer) Version() int {
return oracleAnalyzerVersion
}