-
Notifications
You must be signed in to change notification settings - Fork 518
/
type.go
109 lines (98 loc) · 2.22 KB
/
type.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package distro
import (
"github.com/anchore/syft/syft/linux"
)
// Type represents the different Linux distribution options
type Type string
const (
// represents the set of supported Linux Distributions
Debian Type = "debian"
Ubuntu Type = "ubuntu"
RedHat Type = "redhat"
CentOS Type = "centos"
Fedora Type = "fedora"
Alpine Type = "alpine"
Busybox Type = "busybox"
AmazonLinux Type = "amazonlinux"
OracleLinux Type = "oraclelinux"
ArchLinux Type = "archlinux"
OpenSuseLeap Type = "opensuseleap"
SLES Type = "sles"
Photon Type = "photon"
Windows Type = "windows"
Mariner Type = "mariner"
RockyLinux Type = "rockylinux"
AlmaLinux Type = "almalinux"
Gentoo Type = "gentoo"
Wolfi Type = "wolfi"
Chainguard Type = "chainguard"
)
// All contains all Linux distribution options
var All = []Type{
Debian,
Ubuntu,
RedHat,
CentOS,
Fedora,
Alpine,
Busybox,
AmazonLinux,
OracleLinux,
ArchLinux,
OpenSuseLeap,
SLES,
Photon,
Windows,
Mariner,
RockyLinux,
AlmaLinux,
Gentoo,
Wolfi,
Chainguard,
}
// IDMapping connects a distro ID like "ubuntu" to a Distro type
var IDMapping = map[string]Type{
"debian": Debian,
"ubuntu": Ubuntu,
"rhel": RedHat,
"centos": CentOS,
"fedora": Fedora,
"alpine": Alpine,
"busybox": Busybox,
"amzn": AmazonLinux,
"ol": OracleLinux,
"arch": ArchLinux,
"opensuse-leap": OpenSuseLeap,
"sles": SLES,
"photon": Photon,
"windows": Windows,
"mariner": Mariner,
"rocky": RockyLinux,
"almalinux": AlmaLinux,
"gentoo": Gentoo,
"wolfi": Wolfi,
"chainguard": Chainguard,
}
func TypeFromRelease(release linux.Release) Type {
// first try the release ID
t, ok := IDMapping[release.ID]
if ok {
return t
}
// use ID_LIKE as a backup
for _, l := range release.IDLike {
if t, ok := IDMapping[l]; ok {
return t
}
}
// first try the release name as a fallback
t, ok = IDMapping[release.Name]
if ok {
return t
}
return ""
}
// String returns the string representation of the given Linux distribution.
func (t Type) String() string {
return string(t)
}