-
Notifications
You must be signed in to change notification settings - Fork 25
/
prioritizedresourcemethods.go
70 lines (58 loc) · 1.99 KB
/
prioritizedresourcemethods.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
package prioritization
// SetResourceID set the resource ID
func (pr *PrioritizedResource) SetResourceID(resourceID string) {
pr.ResourceID = resourceID
}
// GetResourceID get the resource ID
func (pr *PrioritizedResource) GetResourceID() string {
return pr.ResourceID
}
// =============================== Score ====================================
// CalculateScore calculates resource score, which is a sum of its priority vectors scores
func (pr *PrioritizedResource) CalculateScore() float64 {
var score float64 = 0
for i := range pr.PriorityVector {
score += pr.PriorityVector[i].GetScore()
}
return score
}
// GetScore returns the score of the prioritized resource
func (pr *PrioritizedResource) GetScore() float64 {
return pr.Score
}
// SetScore updates the score of the prioritized resource
func (pr *PrioritizedResource) SetScore(score float64) {
pr.Score = score
}
// =============================== Severity ====================================
// CalculateSeverity calculates resource severity, which is the max severity of its priority vectors scores
func (pr *PrioritizedResource) CalculateSeverity() int {
var severity int = 0
for i := range pr.PriorityVector {
if pr.PriorityVector[i].GetSeverity() > severity {
severity = pr.PriorityVector[i].GetSeverity()
}
}
return severity
}
func (pr *PrioritizedResource) GetSeverity() int {
return pr.Severity
}
func (pr *PrioritizedResource) SetSeverity(severity int) {
pr.Severity = severity
}
// ================================= Listing ==================================
// ListControlsIDs return a list of controls IDs from all priority vectors of a given resource
func (pr *PrioritizedResource) ListControlsIDs() []string {
ids := make([]string, 0)
for i := range pr.PriorityVector {
if pr.PriorityVector[i].GetType() == ControlPriorityVectorType {
iter := pr.PriorityVector[i].GetIterator()
for iter.HasNext() {
control := iter.Next().(*PriorityVectorControl)
ids = append(ids, control.ControlID)
}
}
}
return ids
}