Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Commit

Permalink
✨ Support dash as short for stdin (#434)
Browse files Browse the repository at this point in the history
* Support dash as short for stdin

Signed-off-by: Raffael Sahli <raffael.sahli@doodle.com>

* document dash stdin

Signed-off-by: Raffael Sahli <raffael.sahli@doodle.com>
  • Loading branch information
raffis authored Jun 9, 2022
1 parent 0ce511d commit 8a2ee04
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ Auditors can also be run individually.
| :---- | :----------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------- |
| | --format | The output format to use (one of "pretty", "logrus", "json") (default is "pretty") |
| -c | --kubeconfig | Path to local Kubernetes config file. Only used in local mode (default is `$HOME/.kube/config`) |
| -f | --manifest | Path to the yaml configuration to audit. Only used in manifest mode. |
| -f | --manifest | Path to the yaml configuration to audit. Only used in manifest mode. You may use `-` to read from stdin. |
| -n | --namespace | Only audit resources in the specified namespace. Not currently supported in manifest mode. |
| -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") |
Expand Down
28 changes: 18 additions & 10 deletions cmd/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import (
var rootConfig rootFlags

type rootFlags struct {
format string
kubeConfig string
manifest string
namespace string
minSeverity string
exitCode int
format string
kubeConfig string
manifest string
namespace string
minSeverity string
exitCode int
includeGenerated bool
}

Expand Down Expand Up @@ -91,11 +91,19 @@ func getReport(auditors ...kubeaudit.Auditable) *kubeaudit.Report {
auditor := initKubeaudit(auditors...)

if rootConfig.manifest != "" {
manifest, err := os.Open(rootConfig.manifest)
if err != nil {
log.WithError(err).Fatal("Error opening manifest file")
var f *os.File
if rootConfig.manifest == "-" {
f = os.Stdin
} else {
manifest, err := os.Open(rootConfig.manifest)
if err != nil {
log.WithError(err).Fatal("Error opening manifest file")
}

f = manifest
}
report, err := auditor.AuditManifest(manifest)

report, err := auditor.AuditManifest(f)
if err != nil {
log.WithError(err).Fatal("Error auditing manifest")
}
Expand Down

0 comments on commit 8a2ee04

Please sign in to comment.