adding summary

This commit is contained in:
dwertent
2021-10-19 15:08:00 +03:00
parent 009d8275c1
commit b371fbad01
3 changed files with 25 additions and 14 deletions
+1 -1
View File
@@ -51,7 +51,7 @@ kubescape scan framework nsa --exclude-namespaces kube-system,kube-public --form
kubescape scan framework nsa --exclude-namespaces kube-system,kube-public --format junit --output results.xml
```
* Scan with exceptions, objects with exceptions will be presented as `warning` and not `fail` <img src="docs/new-feature.svg">
* Scan with exceptions, objects with exceptions will be presented as `warning` and not `fail`
```
kubescape scan framework nsa --exceptions examples/exceptions.json
```
+16 -7
View File
@@ -13,13 +13,14 @@ func NewSummary() Summary {
}
type ControlSummary struct {
TotalResources int
TotalFailed int
TotalWarnign int
Description string
Remediation string
ListInputKinds []string
WorkloadSummary map[string][]WorkloadSummary // <namespace>:[<WorkloadSummary>]
TotalResources int
TotalFailed int
TotalWarnign int
Description string
Remediation string
ListInputKinds []string
FailedWorkloads map[string][]WorkloadSummary // <namespace>:[<WorkloadSummary>]
ExcludedWorkloads map[string][]WorkloadSummary // <namespace>:[<WorkloadSummary>]
}
type WorkloadSummary struct {
@@ -41,3 +42,11 @@ func (controlSummary *ControlSummary) ToSlice() []string {
func (workloadSummary *WorkloadSummary) ToString() string {
return fmt.Sprintf("/%s/%s/%s/%s", workloadSummary.Group, workloadSummary.Namespace, workloadSummary.Kind, workloadSummary.Name)
}
func workloadSummaryFailed(workloadSummary *WorkloadSummary) bool {
return workloadSummary.Exception == nil
}
func workloadSummaryExclude(workloadSummary *WorkloadSummary) bool {
return workloadSummary.Exception != nil && workloadSummary.Exception.IsAlertOnly()
}
+8 -6
View File
@@ -8,14 +8,16 @@ import (
)
// Group workloads by namespace - return {"namespace": <[]WorkloadSummary>}
func groupByNamespace(resources []WorkloadSummary) map[string][]WorkloadSummary {
func groupByNamespace(resources []WorkloadSummary, status func(workloadSummary *WorkloadSummary) bool) map[string][]WorkloadSummary {
mapResources := make(map[string][]WorkloadSummary)
for i := range resources {
if r, ok := mapResources[resources[i].Namespace]; ok {
r = append(r, resources[i])
mapResources[resources[i].Namespace] = r
} else {
mapResources[resources[i].Namespace] = []WorkloadSummary{resources[i]}
if status(&resources[i]) {
if r, ok := mapResources[resources[i].Namespace]; ok {
r = append(r, resources[i])
mapResources[resources[i].Namespace] = r
} else {
mapResources[resources[i].Namespace] = []WorkloadSummary{resources[i]}
}
}
}
return mapResources