1
0
mirror of https://github.com/aquasecurity/kube-bench.git synced 2024-12-01 20:38:09 +00:00

Add extra output manipulation flags, --noremediations, --nosummary and

--noresults.

These flags disable printing sections of the final output of kube-bench.
This commit is contained in:
Abubakr-Sadik Nii Nai Davis 2018-04-10 19:58:19 +00:00
parent ef6c017f54
commit ade064006e
2 changed files with 43 additions and 28 deletions

View File

@ -131,6 +131,8 @@ func colorPrint(state check.State, s string) {
// prettyPrint outputs the results to stdout in human-readable format // prettyPrint outputs the results to stdout in human-readable format
func prettyPrint(r *check.Controls, summary check.Summary) { func prettyPrint(r *check.Controls, summary check.Summary) {
// Print check results.
if !noResults {
colorPrint(check.INFO, fmt.Sprintf("%s %s\n", r.ID, r.Text)) colorPrint(check.INFO, fmt.Sprintf("%s %s\n", r.ID, r.Text))
for _, g := range r.Groups { for _, g := range r.Groups {
colorPrint(check.INFO, fmt.Sprintf("%s %s\n", g.ID, g.Text)) colorPrint(check.INFO, fmt.Sprintf("%s %s\n", g.ID, g.Text))
@ -140,8 +142,10 @@ func prettyPrint(r *check.Controls, summary check.Summary) {
} }
fmt.Println() fmt.Println()
}
// Print remediations. // Print remediations.
if !noRemediations {
if summary.Fail > 0 || summary.Warn > 0 { if summary.Fail > 0 || summary.Warn > 0 {
colors[check.WARN].Printf("== Remediations ==\n") colors[check.WARN].Printf("== Remediations ==\n")
for _, g := range r.Groups { for _, g := range r.Groups {
@ -153,8 +157,10 @@ func prettyPrint(r *check.Controls, summary check.Summary) {
} }
fmt.Println() fmt.Println()
} }
}
// Print summary setting output color to highest severity. // Print summary setting output color to highest severity.
if !noSummary {
var res check.State var res check.State
if summary.Fail > 0 { if summary.Fail > 0 {
res = check.FAIL res = check.FAIL
@ -169,3 +175,4 @@ func prettyPrint(r *check.Controls, summary check.Summary) {
summary.Pass, summary.Fail, summary.Warn, summary.Pass, summary.Fail, summary.Warn,
) )
} }
}

View File

@ -36,6 +36,9 @@ var (
masterFile string masterFile string
nodeFile string nodeFile string
federatedFile string federatedFile string
noResults bool
noSummary bool
noRemediations bool
) )
// RootCmd represents the base command when called without any subcommands // RootCmd represents the base command when called without any subcommands
@ -60,8 +63,13 @@ func Execute() {
func init() { func init() {
cobra.OnInitialize(initConfig) cobra.OnInitialize(initConfig)
// Output control
RootCmd.PersistentFlags().BoolVar(&noResults, "noresults", false, "Disable prints of results section")
RootCmd.PersistentFlags().BoolVar(&noSummary, "nosummary", false, "Disable printing of summary section")
RootCmd.PersistentFlags().BoolVar(&noRemediations, "noremediations", false, "Disable printing of remediations section")
RootCmd.PersistentFlags().BoolVar(&jsonFmt, "json", false, "Prints the results as JSON") RootCmd.PersistentFlags().BoolVar(&jsonFmt, "json", false, "Prints the results as JSON")
RootCmd.PersistentFlags().BoolVar(&pgSQL, "pgsql", false, "Save the results to PostgreSQL") RootCmd.PersistentFlags().BoolVar(&pgSQL, "pgsql", false, "Save the results to PostgreSQL")
RootCmd.PersistentFlags().StringVarP( RootCmd.PersistentFlags().StringVarP(
&checkList, &checkList,
"check", "check",