This repository has been archived by the owner on Nov 18, 2021. It is now read-only.
forked from edwinfrc/voucher
-
Notifications
You must be signed in to change notification settings - Fork 2
/
severity.go
64 lines (58 loc) · 1.7 KB
/
severity.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
package voucher
import "fmt"
// Severity is a integer that represents how severe a vulnerability
// is.
type Severity int
// Severity constants, which represent the severities that we track. Other systems'
// severities should be converted to one of the following.
const (
NegligibleSeverity Severity = iota
LowSeverity Severity = iota
MediumSeverity Severity = iota
UnknownSeverity Severity = iota
HighSeverity Severity = iota
CriticalSeverity Severity = iota
)
const (
negligibleSeverityString = "negligible"
lowSeverityString = "low"
mediumSeverityString = "medium"
highSeverityString = "high"
criticalSeverityString = "critical"
unknownSeverityString = "unknown"
)
// String returns a string representation of a Severity.
func (s Severity) String() string {
switch s {
case NegligibleSeverity:
return negligibleSeverityString
case LowSeverity:
return lowSeverityString
case MediumSeverity:
return mediumSeverityString
case HighSeverity:
return highSeverityString
case CriticalSeverity:
return criticalSeverityString
}
return unknownSeverityString
}
// StringToSeverity returns the matching Severity to the passed string.
// Returns an error if there isn't a matching Severity.
func StringToSeverity(s string) (Severity, error) {
switch s {
case negligibleSeverityString:
return NegligibleSeverity, nil
case lowSeverityString:
return LowSeverity, nil
case mediumSeverityString:
return MediumSeverity, nil
case highSeverityString:
return HighSeverity, nil
case criticalSeverityString:
return CriticalSeverity, nil
case unknownSeverityString:
return UnknownSeverity, nil
}
return UnknownSeverity, fmt.Errorf("severity %s doesn't exist", s)
}