Skip to content

Commit

Permalink
Add --no-color flag (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
genevieveluyt committed Jun 30, 2022
1 parent c1d5057 commit dbeb9b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ For more information on kubernetes config files, see https://kubernetes.io/docs/

Kubeaudit produces results with three levels of severity:

`Error`: A security issue or invalid kubernetes configuration
`Warning`: A best practice recommendation
`Info`: Informational, no action required. This includes results that are [overridden](#override-errors)
- `Error`: A security issue or invalid kubernetes configuration
- `Warning`: A best practice recommendation
- `Info`: Informational, no action required. This includes results that are [overridden](#override-errors)

The minimum severity level can be set using the `--minSeverity/-m` flag.

By default kubeaudit will output results in a human-readable way. If the output is intended to be further processed, it can be set to output JSON using the `--format json` flag. To output results as logs (the previous default) use `--format logrus`.
By default kubeaudit will output results in a human-readable way. If the output is intended to be further processed, it can be set to output JSON using the `--format json` flag. To output results as logs (the previous default) use `--format logrus`. Some output formats include colors to make results easier to read in a terminal. To disable colors (for example, if you are sending output to a text file), you can use the `--no-color` flag.

If there are results of severity level `error`, kubeaudit will exit with exit code 2. This can be changed using the `--exitcode/-e` flag.

Expand Down Expand Up @@ -220,6 +220,7 @@ Auditors can also be run individually.
| -g | --includegenerated | Include generated resources in scan (such as Pods generated by deployments). If you would like kubeaudit to produce results for generated resources (for example if you have custom resources or want to catch orphaned resources where the owner resource no longer exists) you can use this flag. |
| -m | --minseverity | Set the lowest severity level to report (one of "error", "warning", "info") (default "info") |
| -e | --exitcode | Exit code to use if there are results with severity of "error". Conventionally, 0 is used for success and all non-zero codes for an error. (default 2) |
| | --no-color | Don't use colors in the output (the default is true) |

## Configuration File

Expand Down
3 changes: 3 additions & 0 deletions cmd/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type rootFlags struct {
minSeverity string
exitCode int
includeGenerated bool
noColor bool
}

// RootCmd defines the shell command usage for kubeaudit.
Expand Down Expand Up @@ -54,6 +55,7 @@ func init() {
RootCmd.PersistentFlags().StringVarP(&rootConfig.format, "format", "p", "pretty", "The output format to use (one of \"pretty\", \"logrus\", \"json\")")
RootCmd.PersistentFlags().StringVarP(&rootConfig.namespace, "namespace", "n", apiv1.NamespaceAll, "Only audit resources in the specified namespace. Not currently supported in manifest mode.")
RootCmd.PersistentFlags().BoolVarP(&rootConfig.includeGenerated, "includegenerated", "g", false, "Include generated resources in scan (eg. pods generated by deployments).")
RootCmd.PersistentFlags().BoolVar(&rootConfig.noColor, "no-color", false, "Don't produce colored output.")
RootCmd.PersistentFlags().StringVarP(&rootConfig.manifest, "manifest", "f", "", "Path to the yaml configuration to audit. Only used in manifest mode.")
RootCmd.PersistentFlags().IntVarP(&rootConfig.exitCode, "exitcode", "e", 2, "Exit code to use if there are results with severity of \"error\". Conventionally, 0 is used for success and all non-zero codes for an error.")
}
Expand All @@ -72,6 +74,7 @@ func runAudit(auditable ...kubeaudit.Auditable) func(cmd *cobra.Command, args []

printOptions := []kubeaudit.PrintOption{
kubeaudit.WithMinSeverity(KubeauditLogLevels[strings.ToLower(rootConfig.minSeverity)]),
kubeaudit.WithColor(!rootConfig.noColor),
}

switch rootConfig.format {
Expand Down

0 comments on commit dbeb9b5

Please sign in to comment.