1
0
mirror of https://github.com/aquasecurity/kube-bench.git synced 2024-11-30 03:48:13 +00:00

Only print summary messages from --status

Added a Summary.Results method to make it possible to get a specific
State result.
This commit is contained in:
Manuel Tiago Pereira 2021-11-01 17:28:41 +00:00
parent e2cf08aaad
commit 0c1c5aa2e0
No known key found for this signature in database
GPG Key ID: 0F7AEBEEEEB5DC0C
3 changed files with 29 additions and 4 deletions

View File

@ -76,6 +76,21 @@ type Summary struct {
Info int `json:"total_info"`
}
func (s Summary) Results(c State) int {
var r int
switch c {
case "PASS":
r = s.Pass
case "FAIL":
r = s.Fail
case "WARN":
r = s.Warn
case "INFO":
r = s.Info
}
return r
}
// Predicate a predicate on the given Group and Check arguments.
type Predicate func(group *Group, check *Check) bool

View File

@ -243,9 +243,19 @@ func printSummary(summary check.Summary, sectionName string) {
}
colors[res].Printf("== Summary %s ==\n", sectionName)
fmt.Printf("%d checks PASS\n%d checks FAIL\n%d checks WARN\n%d checks INFO\n\n",
summary.Pass, summary.Fail, summary.Warn, summary.Info,
)
if statusList == "" {
fmt.Printf("%d checks PASS\n%d checks FAIL\n%d checks WARN\n%d checks INFO\n\n", summary.Pass, summary.Fail, summary.Warn, summary.Info)
return
}
statusMap := parseStatus(statusList)
var summaryBuilder strings.Builder
for s, b := range statusMap {
if b {
summaryBuilder.WriteString(fmt.Sprintf("%d checks %v\n", summary.Results(s), s))
}
}
summaryBuilder.WriteString("\n")
fmt.Printf(summaryBuilder.String())
}
// loadConfig finds the correct config dir based on the kubernetes version,

View File

@ -799,7 +799,7 @@ func TestWriteStdoutOutputStatusList(t *testing.T) {
os.Stdout = rescueStdout
for _, n := range tt.notContains {
assert.NotContains(t, string(out), fmt.Sprintf("[%s]", n))
assert.NotContains(t, string(out), n)
}
}
}