-
Notifications
You must be signed in to change notification settings - Fork 176
/
infra_assessment_types.go
106 lines (83 loc) · 4.35 KB
/
infra_assessment_types.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// InfraAssessmentSummary counts failed checks by severity.
type InfraAssessmentSummary struct {
// CriticalCount is the number of failed checks with critical severity.
CriticalCount int `json:"criticalCount"`
// HighCount is the number of failed checks with high severity.
HighCount int `json:"highCount"`
// MediumCount is the number of failed checks with medium severity.
MediumCount int `json:"mediumCount"`
// LowCount is the number of failed check with low severity.
LowCount int `json:"lowCount"`
}
// +kubebuilder:object:root=true
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:resource:scope=Cluster,shortName={clusterinfraassessment}
// +kubebuilder:printcolumn:name="Scanner",type=string,JSONPath=`.report.scanner.name`,description="The name of the infra assessement scanner"
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`,description="The age of the report"
// +kubebuilder:printcolumn:name="Critical",type=integer,JSONPath=`.report.summary.criticalCount`,priority=1,description="The number of failed checks with critical severity"
// +kubebuilder:printcolumn:name="High",type=integer,JSONPath=`.report.summary.highCount`,priority=1,description="The number of failed checks with high severity"
// +kubebuilder:printcolumn:name="Medium",type=integer,JSONPath=`.report.summary.mediumCount`,priority=1,description="The number of failed checks with medium severity"
// +kubebuilder:printcolumn:name="Low",type=integer,JSONPath=`.report.summary.lowCount`,priority=1,description="The number of failed checks with low severity"
// ClusterInfraAssessmentReport is a specification for the ClusterInfraAssessmentReport resource.
type ClusterInfraAssessmentReport struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Report InfraAssessmentReportData `json:"report"`
}
// +kubebuilder:object:root=true
// ClusterInfraAssessmentReportList is a list of ClusterInfraAssessmentRepor resources.
type ClusterInfraAssessmentReportList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []ClusterInfraAssessmentReport `json:"items"`
}
// +kubebuilder:object:root=true
// +kubebuilder:resource:shortName={infraassessment,infraassessments}
// +kubebuilder:printcolumn:name="Scanner",type=string,JSONPath=`.report.scanner.name`,description="The name of the infra assessment scanner"
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`,description="The age of the report"
// +kubebuilder:printcolumn:name="Critical",type=integer,JSONPath=`.report.summary.criticalCount`,priority=1,description="The number of failed checks with critical severity"
// +kubebuilder:printcolumn:name="High",type=integer,JSONPath=`.report.summary.highCount`,priority=1,description="The number of failed checks with high severity"
// +kubebuilder:printcolumn:name="Medium",type=integer,JSONPath=`.report.summary.mediumCount`,priority=1,description="The number of failed checks with medium severity"
// +kubebuilder:printcolumn:name="Low",type=integer,JSONPath=`.report.summary.lowCount`,priority=1,description="The number of failed checks with low severity"
// InfraAssessmentReport is a specification for the InfraAssessmentReport resource.
type InfraAssessmentReport struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Report InfraAssessmentReportData `json:"report"`
}
// +kubebuilder:object:root=true
// InfraAssessmentReportList is a list of Infra assessment resources.
type InfraAssessmentReportList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []InfraAssessmentReport `json:"items"`
}
type InfraAssessmentReportData struct {
Scanner Scanner `json:"scanner"`
Summary InfraAssessmentSummary `json:"summary"`
// Checks provides results of conducting audit steps.
Checks []Check `json:"checks"`
}
func InfraAssessmentSummaryFromChecks(checks []Check) InfraAssessmentSummary {
summary := InfraAssessmentSummary{}
for _, check := range checks {
if check.Success {
continue
}
switch check.Severity {
case SeverityCritical:
summary.CriticalCount++
case SeverityHigh:
summary.HighCount++
case SeverityMedium:
summary.MediumCount++
case SeverityLow:
summary.LowCount++
}
}
return summary
}