-
Notifications
You must be signed in to change notification settings - Fork 100
/
report.go
52 lines (43 loc) · 1.65 KB
/
report.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
package ruler
type Reports []Report
type Report struct {
Object string `json:"object"`
Valid bool `json:"valid"`
FileName string `json:"fileName"`
Rules []RuleRef `json:"-"`
Message string `json:"message,omitempty"`
Score int `json:"score"`
Scoring RuleScoring `json:"scoring,omitempty"`
}
type RuleScoring struct {
Critical []RuleRef `json:"critical,omitempty"`
Passed []RuleRef `json:"passed,omitempty"`
Advise []RuleRef `json:"advise,omitempty"`
}
type RuleRef struct {
ID string `json:"id"`
Selector string `json:"selector"`
Reason string `json:"reason"`
Weight int `json:"weight,omitempty"`
Link string `json:"href,omitempty"`
Containers int `json:"-"`
Points int `json:"points"`
}
// This implements a custom sort interface (Len, Swap, Less) for the report listing.
// Each scan can produce a different ordering of the reported tests. To have a single
// deterministic report response for the same input requires sort to never draw.
// Assumption below is: the combination of points, then selector text, should be unique
// This is applied to the output of scan for each of the Critical and Advisory lists.
type RuleRefCustomOrder []RuleRef
func (rr RuleRefCustomOrder) Len() int { return len(rr) }
func (rr RuleRefCustomOrder) Swap(i, j int) { rr[i], rr[j] = rr[j], rr[i] }
func (rr RuleRefCustomOrder) Less(i, j int) bool {
if rr[i].Points != rr[j].Points {
// no integer absolute fn in golang
if rr[i].Points > 0 || rr[j].Points > 0 {
return rr[i].Points > rr[j].Points
}
return rr[i].Points < rr[j].Points
}
return rr[i].Selector < rr[j].Selector
}