-
Notifications
You must be signed in to change notification settings - Fork 530
/
type.go
219 lines (211 loc) · 5.12 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package pkg
import (
"github.com/anchore/packageurl-go"
)
// Type represents a Package Type for or within a language ecosystem (there may be multiple package types within a language ecosystem)
type Type string
const (
// the full set of supported packages
UnknownPkg Type = "UnknownPackage"
AlpmPkg Type = "alpm"
ApkPkg Type = "apk"
BinaryPkg Type = "binary"
CocoapodsPkg Type = "pod"
ConanPkg Type = "conan"
DartPubPkg Type = "dart-pub"
DebPkg Type = "deb"
DotnetPkg Type = "dotnet"
ErlangOTPPkg Type = "erlang-otp"
GemPkg Type = "gem"
GithubActionPkg Type = "github-action"
GithubActionWorkflowPkg Type = "github-action-workflow"
GoModulePkg Type = "go-module"
GraalVMNativeImagePkg Type = "graalvm-native-image"
HackagePkg Type = "hackage"
HexPkg Type = "hex"
JavaPkg Type = "java-archive"
JenkinsPluginPkg Type = "jenkins-plugin"
KbPkg Type = "msrc-kb"
LinuxKernelPkg Type = "linux-kernel"
LinuxKernelModulePkg Type = "linux-kernel-module"
NixPkg Type = "nix"
NpmPkg Type = "npm"
PhpComposerPkg Type = "php-composer"
PhpPeclPkg Type = "php-pecl"
PortagePkg Type = "portage"
PythonPkg Type = "python"
Rpkg Type = "R-package"
RpmPkg Type = "rpm"
RustPkg Type = "rust-crate"
SwiftPkg Type = "swift"
WordpressPluginPkg Type = "wordpress-plugin"
)
// AllPkgs represents all supported package types
var AllPkgs = []Type{
AlpmPkg,
ApkPkg,
BinaryPkg,
CocoapodsPkg,
ConanPkg,
DartPubPkg,
DebPkg,
DotnetPkg,
ErlangOTPPkg,
GemPkg,
GithubActionPkg,
GithubActionWorkflowPkg,
GoModulePkg,
HackagePkg,
HexPkg,
JavaPkg,
JenkinsPluginPkg,
KbPkg,
LinuxKernelPkg,
LinuxKernelModulePkg,
NixPkg,
NpmPkg,
PhpComposerPkg,
PhpPeclPkg,
PortagePkg,
PythonPkg,
Rpkg,
RpmPkg,
RustPkg,
SwiftPkg,
WordpressPluginPkg,
}
// PackageURLType returns the PURL package type for the current package.
//
//nolint:funlen
func (t Type) PackageURLType() string {
switch t {
case AlpmPkg:
return "alpm"
case ApkPkg:
return packageurl.TypeAlpine
case CocoapodsPkg:
return packageurl.TypeCocoapods
case ConanPkg:
return packageurl.TypeConan
case DartPubPkg:
return packageurl.TypePub
case DebPkg:
return "deb"
case DotnetPkg:
return "dotnet"
case ErlangOTPPkg:
return packageurl.TypeOTP
case GemPkg:
return packageurl.TypeGem
case HexPkg:
return packageurl.TypeHex
case GithubActionPkg, GithubActionWorkflowPkg:
// note: this is not a real purl type, but it is the closest thing we have for now
return packageurl.TypeGithub
case GoModulePkg:
return packageurl.TypeGolang
case HackagePkg:
return packageurl.TypeHackage
case JavaPkg, JenkinsPluginPkg:
return packageurl.TypeMaven
case LinuxKernelPkg:
return "generic/linux-kernel"
case LinuxKernelModulePkg:
return packageurl.TypeGeneric
case PhpComposerPkg:
return packageurl.TypeComposer
case PhpPeclPkg:
return "pecl"
case PythonPkg:
return packageurl.TypePyPi
case PortagePkg:
return "portage"
case NixPkg:
return "nix"
case NpmPkg:
return packageurl.TypeNPM
case Rpkg:
return packageurl.TypeCran
case RpmPkg:
return packageurl.TypeRPM
case RustPkg:
return "cargo"
case SwiftPkg:
return packageurl.TypeSwift
case WordpressPluginPkg:
return "wordpress-plugin"
default:
// TODO: should this be a "generic" purl type instead?
return ""
}
}
func TypeFromPURL(p string) Type {
purl, err := packageurl.FromString(p)
if err != nil {
return UnknownPkg
}
ptype := purl.Type
if ptype == "generic" {
ptype = purl.Name
}
return TypeByName(ptype)
}
//nolint:funlen
func TypeByName(name string) Type {
switch name {
case packageurl.TypeDebian:
return DebPkg
case packageurl.TypeRPM:
return RpmPkg
case "alpm":
return AlpmPkg
case packageurl.TypeAlpine, "alpine":
return ApkPkg
case packageurl.TypeMaven:
return JavaPkg
case packageurl.TypeComposer:
return PhpComposerPkg
case "pecl":
return PhpPeclPkg
case packageurl.TypeGolang:
return GoModulePkg
case packageurl.TypeNPM:
return NpmPkg
case packageurl.TypePyPi:
return PythonPkg
case packageurl.TypeGem:
return GemPkg
case "cargo", "crate":
return RustPkg
case packageurl.TypePub:
return DartPubPkg
case "dotnet": // here to support legacy use cases
return DotnetPkg
case packageurl.TypeCocoapods:
return CocoapodsPkg
case packageurl.TypeConan:
return ConanPkg
case packageurl.TypeHackage:
return HackagePkg
case "portage":
return PortagePkg
case packageurl.TypeHex:
return HexPkg
case packageurl.TypeOTP:
return ErlangOTPPkg
case "linux-kernel":
return LinuxKernelPkg
case "linux-kernel-module":
return LinuxKernelModulePkg
case "nix":
return NixPkg
case packageurl.TypeCran:
return Rpkg
case packageurl.TypeSwift:
return SwiftPkg
case "wordpress-plugin":
return WordpressPluginPkg
default:
return UnknownPkg
}
}