@@ -27,7 +27,8 @@ var requiredFiles = []string{
27
27
type osReleaseAnalyzer struct {}
28
28
29
29
func (a osReleaseAnalyzer ) Analyze (_ context.Context , input analyzer.AnalysisInput ) (* analyzer.AnalysisResult , error ) {
30
- var id , versionID string
30
+ var family types.OSType
31
+ var versionID string
31
32
scanner := bufio .NewScanner (input .Content )
32
33
for scanner .Scan () {
33
34
line := scanner .Text ()
@@ -40,46 +41,14 @@ func (a osReleaseAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInp
40
41
41
42
switch key {
42
43
case "ID" :
43
- id = strings .Trim (value , `"'` )
44
+ id := strings .Trim (value , `"'` )
45
+ family = idToOSFamily (id )
44
46
case "VERSION_ID" :
45
47
versionID = strings .Trim (value , `"'` )
46
48
default :
47
49
continue
48
50
}
49
51
50
- var family types.OSType
51
- switch id {
52
- case "alpine" :
53
- family = types .Alpine
54
- case "bottlerocket" :
55
- family = types .Bottlerocket
56
- case "opensuse-tumbleweed" :
57
- family = types .OpenSUSETumbleweed
58
- case "opensuse-leap" , "opensuse" : // opensuse for leap:42, opensuse-leap for leap:15
59
- family = types .OpenSUSELeap
60
- case "sles" :
61
- family = types .SLES
62
- // There are various rebrands of SLE Micro, there is also one brief (and reverted rebrand)
63
- // for SLE Micro 6.0. which was called "SL Micro 6.0" until very short before release
64
- // and there is a "SLE Micro for Rancher" rebrand, which is used by SUSEs K8S based offerings.
65
- case "sle-micro" , "sl-micro" , "sle-micro-rancher" :
66
- family = types .SLEMicro
67
- case "photon" :
68
- family = types .Photon
69
- case "wolfi" :
70
- family = types .Wolfi
71
- case "chainguard" :
72
- family = types .Chainguard
73
- case "azurelinux" :
74
- family = types .Azure
75
- case "mariner" :
76
- family = types .CBLMariner
77
- case "echo" :
78
- family = types .Echo
79
- case "minimos" :
80
- family = types .MinimOS
81
- }
82
-
83
52
if family != "" && versionID != "" {
84
53
return & analyzer.AnalysisResult {
85
54
OS : types.OS {
@@ -93,6 +62,54 @@ func (a osReleaseAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInp
93
62
return nil , nil
94
63
}
95
64
65
+ func idToOSFamily (id string ) types.OSType {
66
+ switch id {
67
+ case "rhel" :
68
+ return types .RedHat
69
+ case "centos" :
70
+ return types .CentOS
71
+ case "rocky" :
72
+ return types .Rocky
73
+ case "almalinux" :
74
+ return types .Alma
75
+ case "ol" :
76
+ return types .Oracle
77
+ case "fedora" :
78
+ return types .Fedora
79
+ case "alpine" :
80
+ return types .Alpine
81
+ case "bottlerocket" :
82
+ return types .Bottlerocket
83
+ case "opensuse-tumbleweed" :
84
+ return types .OpenSUSETumbleweed
85
+ case "opensuse-leap" , "opensuse" : // opensuse for leap:42, opensuse-leap for leap:15
86
+ return types .OpenSUSELeap
87
+ case "sles" :
88
+ return types .SLES
89
+ // There are various rebrands of SLE Micro, there is also one brief (and reverted rebrand)
90
+ // for SLE Micro 6.0. which was called "SL Micro 6.0" until very short before release
91
+ // and there is a "SLE Micro for Rancher" rebrand, which is used by SUSEs K8S based offerings.
92
+ case "sle-micro" , "sl-micro" , "sle-micro-rancher" :
93
+ return types .SLEMicro
94
+ case "photon" :
95
+ return types .Photon
96
+ case "wolfi" :
97
+ return types .Wolfi
98
+ case "chainguard" :
99
+ return types .Chainguard
100
+ case "azurelinux" :
101
+ return types .Azure
102
+ case "mariner" :
103
+ return types .CBLMariner
104
+ case "echo" :
105
+ return types .Echo
106
+ case "minimos" :
107
+ return types .MinimOS
108
+ }
109
+ // This OS is not supported for this analyzer.
110
+ return ""
111
+ }
112
+
96
113
func (a osReleaseAnalyzer ) Required (filePath string , _ os.FileInfo ) bool {
97
114
return slices .Contains (requiredFiles , filePath )
98
115
}
0 commit comments