-
Notifications
You must be signed in to change notification settings - Fork 25
/
severitycounters.go
48 lines (39 loc) · 1.45 KB
/
severitycounters.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
package reportsummary
import "github.com/kubescape/opa-utils/reporthandling/apis"
type ISeverityCounters interface {
NumberOfResourcesWithCriticalSeverity() int
NumberOfResourcesWithHighSeverity() int
NumberOfResourcesWithMediumSeverity() int
NumberOfResourcesWithLowSeverity() int
Increase(severity string, amount int)
}
func (sc *SeverityCounters) NumberOfResourcesWithCriticalSeverity() int {
return sc.ResourcesWithCriticalSeverityCounter
}
func (sc *SeverityCounters) NumberOfResourcesWithHighSeverity() int {
return sc.ResourcesWithHighSeverityCounter
}
func (sc *SeverityCounters) NumberOfResourcesWithMediumSeverity() int {
return sc.ResourcesWithMediumSeverityCounter
}
func (sc *SeverityCounters) NumberOfResourcesWithLowSeverity() int {
return sc.ResourcesWithLowSeverityCounter
}
// Increase increments the counter of a given severity by a given amount
func (sc *SeverityCounters) Increase(severity string, amount int) {
var counterToIncrement *int
switch severity {
case apis.SeverityCriticalString:
counterToIncrement = &sc.ResourcesWithCriticalSeverityCounter
case apis.SeverityHighString:
counterToIncrement = &sc.ResourcesWithHighSeverityCounter
case apis.SeverityMediumString:
counterToIncrement = &sc.ResourcesWithMediumSeverityCounter
case apis.SeverityLowString:
counterToIncrement = &sc.ResourcesWithLowSeverityCounter
// Return without incrementing on unrecognized severities
default:
return
}
*counterToIncrement += amount
}