Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
kube-bench
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
aquasecurity
kube-bench
Commits
46bbcdd9
Unverified
Commit
46bbcdd9
authored
6 years ago
by
Liz Rice
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #106 from aquasecurity/additional-flags
Add extra output manipulation flags
parents
ef6c017f
ade06400
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cmd/common.go
+33
-26
33 additions, 26 deletions
cmd/common.go
cmd/root.go
+8
-0
8 additions, 0 deletions
cmd/root.go
with
41 additions
and
26 deletions
cmd/common.go
+
33
−
26
View file @
46bbcdd9
...
...
@@ -131,41 +131,48 @@ func colorPrint(state check.State, s string) {
// prettyPrint outputs the results to stdout in human-readable format
func
prettyPrint
(
r
*
check
.
Controls
,
summary
check
.
Summary
)
{
colorPrint
(
check
.
INFO
,
fmt
.
Sprintf
(
"%s %s
\n
"
,
r
.
ID
,
r
.
Text
))
for
_
,
g
:=
range
r
.
Groups
{
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
))
// Print check results.
if
!
noResults
{
colorPrint
(
check
.
INFO
,
fmt
.
Sprintf
(
"%s %s
\n
"
,
r
.
ID
,
r
.
Text
))
for
_
,
g
:=
range
r
.
Groups
{
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
))
}
}
}
fmt
.
Println
()
fmt
.
Println
()
}
// Print remediations.
if
summary
.
Fail
>
0
||
summary
.
Warn
>
0
{
colors
[
check
.
WARN
]
.
Printf
(
"== Remediations ==
\n
"
)
for
_
,
g
:=
range
r
.
Groups
{
for
_
,
c
:=
range
g
.
Checks
{
if
c
.
State
!=
check
.
PASS
{
fmt
.
Printf
(
"%s %s
\n
"
,
c
.
ID
,
c
.
Remediation
)
if
!
noRemediations
{
if
summary
.
Fail
>
0
||
summary
.
Warn
>
0
{
colors
[
check
.
WARN
]
.
Printf
(
"== Remediations ==
\n
"
)
for
_
,
g
:=
range
r
.
Groups
{
for
_
,
c
:=
range
g
.
Checks
{
if
c
.
State
!=
check
.
PASS
{
fmt
.
Printf
(
"%s %s
\n
"
,
c
.
ID
,
c
.
Remediation
)
}
}
}
fmt
.
Println
()
}
fmt
.
Println
()
}
// Print summary setting output color to highest severity.
var
res
check
.
State
if
summary
.
Fail
>
0
{
res
=
check
.
FAIL
}
else
if
summary
.
Warn
>
0
{
res
=
check
.
WARN
}
else
{
res
=
check
.
PASS
}
if
!
noSummary
{
var
res
check
.
State
if
summary
.
Fail
>
0
{
res
=
check
.
FAIL
}
else
if
summary
.
Warn
>
0
{
res
=
check
.
WARN
}
else
{
res
=
check
.
PASS
}
colors
[
res
]
.
Printf
(
"== Summary ==
\n
"
)
fmt
.
Printf
(
"%d checks PASS
\n
%d checks FAIL
\n
%d checks WARN
\n
"
,
summary
.
Pass
,
summary
.
Fail
,
summary
.
Warn
,
)
colors
[
res
]
.
Printf
(
"== Summary ==
\n
"
)
fmt
.
Printf
(
"%d checks PASS
\n
%d checks FAIL
\n
%d checks WARN
\n
"
,
summary
.
Pass
,
summary
.
Fail
,
summary
.
Warn
,
)
}
}
This diff is collapsed.
Click to expand it.
cmd/root.go
+
8
−
0
View file @
46bbcdd9
...
...
@@ -36,6 +36,9 @@ var (
masterFile
string
nodeFile
string
federatedFile
string
noResults
bool
noSummary
bool
noRemediations
bool
)
// RootCmd represents the base command when called without any subcommands
...
...
@@ -60,8 +63,13 @@ func Execute() {
func
init
()
{
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
(
&
pgSQL
,
"pgsql"
,
false
,
"Save the results to PostgreSQL"
)
RootCmd
.
PersistentFlags
()
.
StringVarP
(
&
checkList
,
"check"
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment