This repository was archived by the owner on May 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseverity.go
More file actions
53 lines (47 loc) · 1.3 KB
/
severity.go
File metadata and controls
53 lines (47 loc) · 1.3 KB
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
package vulnerability
import (
"strings"
)
// Severity represents the severity of a vulnerability, as defined by the Gitlab API.
type Severity string
const (
SeverityUnknown Severity = "unknown"
SeverityInfo Severity = "info"
SeverityLow Severity = "low"
SeverityMedium Severity = "medium"
SeverityHigh Severity = "high"
SeverityCritical Severity = "critical"
)
// ToSeverity converts a string to a Severity, returning SeverityUnknown if the string is not recognized.
func ToSeverity(severity string) Severity {
switch strings.ToLower(severity) {
case "info":
return SeverityInfo
case "low":
return SeverityLow
case "medium":
return SeverityMedium
case "high":
return SeverityHigh
case "critical":
return SeverityCritical
}
return SeverityUnknown
}
// ToSeverities converts a slice of strings to a slice of Severities.
func ToSeverities(severities []string) []Severity {
result := make([]Severity, 0)
for _, severity := range severities {
result = append(result, ToSeverity(severity))
}
return result
}
// ContainsSeverity checks if a slice of Severities contains a specific Severity, returning true if it does.
func ContainsSeverity(severity Severity, severities []Severity) bool {
for _, s := range severities {
if s == severity {
return true
}
}
return false
}