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:
parent
e2cf08aaad
commit
0c1c5aa2e0
@ -76,6 +76,21 @@ type Summary struct {
|
|||||||
Info int `json:"total_info"`
|
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.
|
// Predicate a predicate on the given Group and Check arguments.
|
||||||
type Predicate func(group *Group, check *Check) bool
|
type Predicate func(group *Group, check *Check) bool
|
||||||
|
|
||||||
|
@ -243,9 +243,19 @@ func printSummary(summary check.Summary, sectionName string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
colors[res].Printf("== Summary %s ==\n", sectionName)
|
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",
|
if statusList == "" {
|
||||||
summary.Pass, summary.Fail, summary.Warn, summary.Info,
|
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,
|
// loadConfig finds the correct config dir based on the kubernetes version,
|
||||||
|
@ -799,7 +799,7 @@ func TestWriteStdoutOutputStatusList(t *testing.T) {
|
|||||||
os.Stdout = rescueStdout
|
os.Stdout = rescueStdout
|
||||||
|
|
||||||
for _, n := range tt.notContains {
|
for _, n := range tt.notContains {
|
||||||
assert.NotContains(t, string(out), fmt.Sprintf("[%s]", n))
|
assert.NotContains(t, string(out), n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user