This repository has been archived by the owner on Oct 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
report_view.go
117 lines (102 loc) · 3.81 KB
/
report_view.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
107
108
109
110
111
112
113
114
115
116
117
package kubebench
import (
"fmt"
"strconv"
"github.com/aquasecurity/starboard-octant-plugin/pkg/plugin/view"
"github.com/aquasecurity/starboard/pkg/apis/aquasecurity/v1alpha1"
"github.com/vmware-tanzu/octant/pkg/view/component"
)
// NewReport creates a new view component for displaying the specified CISKubeBenchReport.
func NewReport(kubeBenchReportsDefined bool, report *v1alpha1.CISKubeBenchReport) (flexLayout component.FlexLayout) {
flexLayout = *component.NewFlexLayout("CIS Kubernetes Benchmark")
if !kubeBenchReportsDefined {
flexLayout.AddSections(component.FlexLayoutSection{
{
Width: component.WidthFull,
View: component.NewMarkdownText(fmt.Sprintf(
"The `%[1]s` resource, which represents kube-bench reports, is not defined.\n"+
"> You can create this resource definition by running the [Starboard CLI][starboard-cli] init command:\n"+
"> ```\n"+
"> $ kubectl starboard init\n"+
"> ```\n"+
"or\n"+
"> ```\n"+
"> $ kubectl apply -f https://raw.githubusercontent.com/aquasecurity/starboard/main/deploy/crd/ciskubebenchreports.crd.yaml\n"+
"> ```\n"+
"\n"+
"[starboard-cli]: https://github.com/aquasecurity/starboard#starboard-cli",
v1alpha1.CISKubeBenchReportCRName,
)),
},
})
return
}
if report == nil {
flexLayout.AddSections(component.FlexLayoutSection{
{
Width: component.WidthFull,
View: component.NewMarkdownText("This report is not available.\n" +
"> Note that [kube-bench] reports are represented by instances of the `ciskubebenchreports.aquasecurity.github.io` resource.\n" +
"> You can create such a report by running [kube-bench] with [Starboard CLI][starboard-cli]:\n" +
"> ```\n" +
"> $ kubectl starboard scan ciskubebenchreports\n" +
"> ```\n" +
"\n" +
"[kube-bench]: https://github.com/aquasecurity/kube-bench\n" +
"[starboard-cli]: https://github.com/aquasecurity/starboard#starboard-cli"),
},
})
return
}
uiSections := make([]component.FlexLayoutItem, len(report.Report.Sections))
for i, section := range report.Report.Sections {
uiSections[i] = component.FlexLayoutItem{
Width: component.WidthFull,
View: createTableForSection(section),
}
}
uiSections = append([]component.FlexLayoutItem{
{
Width: component.WidthThird,
View: view.NewReportMetadata(report.ObjectMeta),
},
{
Width: component.WidthThird,
View: view.NewScannerSummary(report.Report.Scanner),
},
{
Width: component.WidthThird,
View: NewCISKubeBenchSummary(report.Report.Summary),
},
}, uiSections...)
flexLayout.AddSections(uiSections)
return
}
func createTableForSection(section v1alpha1.CISKubeBenchSection) component.Component {
table := component.NewTableWithRows(
fmt.Sprintf("%s %s", section.ID, section.Text), "There are no results!",
component.NewTableCols("Status", "Number", "Description", "Scored"),
[]component.TableRow{})
for _, test := range section.Tests {
for _, result := range test.Results {
tr := component.TableRow{
"Status": component.NewText(result.Status),
"Number": component.NewText(result.TestNumber),
"Description": component.NewText(result.TestDesc),
"Scored": component.NewText(strconv.FormatBool(result.Scored)),
}
table.Add(tr)
}
}
return table
}
func NewCISKubeBenchSummary(summary v1alpha1.CISKubeBenchSummary) (summaryComponent *component.Summary) {
summaryComponent = component.NewSummary("Summary")
summaryComponent.Add([]component.SummarySection{
{Header: "PASS ", Content: component.NewText(strconv.Itoa(summary.PassCount))},
{Header: "INFO", Content: component.NewText(strconv.Itoa(summary.InfoCount))},
{Header: "WARN ", Content: component.NewText(strconv.Itoa(summary.WarnCount))},
{Header: "FAIL ", Content: component.NewText(strconv.Itoa(summary.FailCount))},
}...)
return
}