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
161 lines (139 loc) · 4.85 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package configaudit
import (
"fmt"
"sort"
"strconv"
"strings"
"github.com/aquasecurity/starboard-octant-plugin/pkg/plugin/view"
"github.com/aquasecurity/starboard/pkg/apis/aquasecurity/v1alpha1"
"github.com/aquasecurity/starboard/pkg/kube"
"github.com/vmware-tanzu/octant/pkg/view/component"
)
func NewReport(workload kube.Object, isConfigAuditReportsCRDefined bool, report *v1alpha1.ConfigAuditReport) *component.FlexLayout {
flexLayout := component.NewFlexLayout("")
flexLayout.AddSections(component.FlexLayoutSection{
{
Width: component.WidthFull,
View: component.NewMarkdownText("#### Config Audit Reports"),
},
})
if !isConfigAuditReportsCRDefined {
flexLayout.AddSections(component.FlexLayoutSection{
{
Width: component.WidthFull,
View: component.NewMarkdownText(fmt.Sprintf(
"The `%[1]s` resource, which represents config audit 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/configauditreports.crd.yaml\n"+
"> ```\n"+
"\n"+
"[starboard-cli]: https://github.com/aquasecurity/starboard#starboard-cli",
v1alpha1.ConfigAuditReportCRName,
)),
},
})
return flexLayout
}
if report == nil {
flexLayout.AddSections(component.FlexLayoutSection{
{
Width: component.WidthFull,
View: component.NewMarkdownText(fmt.Sprintf(
"Config audit reports are not available.\n"+
"> Note that config audit reports are represented by instances of the `%[1]s` resource.\n"+
"> You can create such reports by running [Polaris][polaris] with [Starboard CLI][starboard-cli]:\n"+
"> ```\n"+
"> $ kubectl starboard scan configauditreports %[2]s/%[3]s --namespace %[4]s\n"+
"> ```\n"+
"\n"+
"[polaris]: https://www.fairwinds.com/polaris\n"+
"[starboard-cli]: https://github.com/aquasecurity/starboard#starboard-cli",
v1alpha1.ConfigAuditReportCRName,
strings.ToLower(string(workload.Kind)),
workload.Name,
workload.Namespace,
)),
},
})
return flexLayout
}
flexLayout.AddSections(component.FlexLayoutSection{
{
Width: component.WidthThird,
View: view.NewReportMetadata(report.ObjectMeta),
},
{
Width: component.WidthThird,
View: view.NewScannerSummary(report.Report.Scanner),
},
{
Width: component.WidthThird,
View: NewSummary(report.Report),
},
})
var items []component.FlexLayoutItem
items = append(items, component.FlexLayoutItem{
Width: component.WidthThird,
View: createCardComponent("Pod Template", report.Report.PodChecks),
})
var containerNames []string
for containerName := range report.Report.ContainerChecks {
containerNames = append(containerNames, containerName)
}
sort.Strings(containerNames)
for _, containerName := range containerNames {
items = append(items, component.FlexLayoutItem{
Width: component.WidthThird,
View: createCardComponent(fmt.Sprintf("Container %s", containerName), report.Report.ContainerChecks[containerName]),
})
}
flexLayout.AddSections(items)
return flexLayout
}
func createCardComponent(title string, checks []v1alpha1.Check) *component.Card {
card := component.NewCard(component.TitleFromString(title))
card.SetBody(createChecksTable(checks))
return card
}
func createChecksTable(checks []v1alpha1.Check) component.Component {
table := component.NewTableWithRows(
"", "There are no checks!",
component.NewTableCols("ID", "Severity", "Category"),
[]component.TableRow{})
for _, c := range checks {
tr := component.TableRow{
"ID": CheckIDWithIcon(c),
"Severity": component.NewText(fmt.Sprintf("%s", c.Severity)),
"Category": component.NewText(c.Category),
}
table.Add(tr)
}
return table
}
func CheckIDWithIcon(check v1alpha1.Check) component.Component {
iconShape := "check-circle"
iconClass := "is-success"
if !check.Success && check.Severity == "warning" {
iconShape = "info-circle"
iconClass = "is-warning"
}
if !check.Success && check.Severity == "danger" {
iconShape = "exclamation-circle"
iconClass = "is-danger"
}
status := component.NewMarkdownText(fmt.Sprintf(`<clr-icon shape="%s" class="is-solid %s"></clr-icon> %s`, iconShape, iconClass, check.ID))
status.EnableTrustedContent()
return status
}
func NewSummary(report v1alpha1.ConfigAuditReportData) *component.Summary {
return component.NewSummary("Summary", []component.SummarySection{
{Header: "pass", Content: component.NewText(strconv.Itoa(report.Summary.PassCount))},
{Header: "warning", Content: component.NewText(strconv.Itoa(report.Summary.WarningCount))},
{Header: "danger", Content: component.NewText(strconv.Itoa(report.Summary.DangerCount))},
}...)
}