1
0
mirror of https://github.com/aquasecurity/kube-bench.git synced 2024-11-29 11:28:14 +00:00

Printing the actual test result of failed tests - when a flag is raised

fix #110
This commit is contained in:
Yoav Hizkiahou 2019-05-05 10:52:28 +03:00
parent c152088254
commit 3aa28c4c32
2 changed files with 13 additions and 0 deletions

View File

@ -19,6 +19,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"github.com/aquasecurity/kube-bench/check"
"github.com/golang/glog"
@ -142,6 +143,10 @@ func prettyPrint(r *check.Controls, summary check.Summary) {
colorPrint(check.INFO, fmt.Sprintf("%s %s\n", g.ID, g.Text))
for _, c := range g.Checks {
colorPrint(c.State, fmt.Sprintf("%s %s\n", c.ID, c.Text))
if includeTestOutput && c.State == check.FAIL && len(c.ActualValue) > 0 {
printRawOutput(c.ActualValue)
}
}
}
@ -240,3 +245,9 @@ func isMaster() bool {
}
return true
}
func printRawOutput(output string) {
for _, row := range strings.Split(output, "\n") {
fmt.Println(fmt.Sprintf("\t %s", row))
}
}

View File

@ -47,6 +47,7 @@ var (
noSummary bool
noRemediations bool
filterOpts FilterOpts
includeTestOutput bool
)
// RootCmd represents the base command when called without any subcommands
@ -87,6 +88,7 @@ func init() {
RootCmd.PersistentFlags().BoolVar(&pgSQL, "pgsql", false, "Save the results to PostgreSQL")
RootCmd.PersistentFlags().BoolVar(&filterOpts.Scored, "scored", true, "Run the scored CIS checks")
RootCmd.PersistentFlags().BoolVar(&filterOpts.Unscored, "unscored", true, "Run the unscored CIS checks")
RootCmd.PersistentFlags().BoolVar(&includeTestOutput, "include-test-output", false, "Prints the actual result when test fails")
RootCmd.PersistentFlags().StringVarP(
&filterOpts.CheckList,