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
e64f61fa
Commit
e64f61fa
authored
6 years ago
by
nshauli
Committed by
jerbia
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add --outputfile flag for writing json results to output file (#295)
parent
5e80f410
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
+25
-1
25 additions, 1 deletion
cmd/common.go
cmd/root.go
+3
-1
3 additions, 1 deletion
cmd/root.go
with
28 additions
and
2 deletions
cmd/common.go
+
25
−
1
View file @
e64f61fa
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
package
cmd
package
cmd
import
(
import
(
"bufio"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"os"
"os"
...
@@ -112,7 +113,7 @@ func runChecks(nodetype check.NodeType) {
...
@@ -112,7 +113,7 @@ func runChecks(nodetype check.NodeType) {
exitWithError
(
fmt
.
Errorf
(
"failed to output in JSON format: %v"
,
err
))
exitWithError
(
fmt
.
Errorf
(
"failed to output in JSON format: %v"
,
err
))
}
}
fmt
.
Print
ln
(
string
(
out
))
Print
Output
(
string
(
out
)
,
outputFile
)
}
else
{
}
else
{
// if we want to store in PostgreSQL, convert to JSON and save it
// if we want to store in PostgreSQL, convert to JSON and save it
if
(
summary
.
Fail
>
0
||
summary
.
Warn
>
0
||
summary
.
Pass
>
0
||
summary
.
Info
>
0
)
&&
pgSQL
{
if
(
summary
.
Fail
>
0
||
summary
.
Warn
>
0
||
summary
.
Pass
>
0
||
summary
.
Info
>
0
)
&&
pgSQL
{
...
@@ -251,3 +252,26 @@ func printRawOutput(output string) {
...
@@ -251,3 +252,26 @@ func printRawOutput(output string) {
fmt
.
Println
(
fmt
.
Sprintf
(
"
\t
%s"
,
row
))
fmt
.
Println
(
fmt
.
Sprintf
(
"
\t
%s"
,
row
))
}
}
}
}
func
writeOutputToFile
(
output
string
,
outputFile
string
)
error
{
file
,
err
:=
os
.
Create
(
outputFile
)
if
err
!=
nil
{
return
err
}
defer
file
.
Close
()
w
:=
bufio
.
NewWriter
(
file
)
fmt
.
Fprintln
(
w
,
output
)
return
w
.
Flush
()
}
func
PrintOutput
(
output
string
,
outputFile
string
)
{
if
len
(
outputFile
)
==
0
{
fmt
.
Println
(
output
)
}
else
{
err
:=
writeOutputToFile
(
output
,
outputFile
)
if
err
!=
nil
{
exitWithError
(
fmt
.
Errorf
(
"Failed to write to output file %s: %v"
,
outputFile
,
err
))
}
}
}
This diff is collapsed.
Click to expand it.
cmd/root.go
+
3
−
1
View file @
e64f61fa
...
@@ -47,7 +47,8 @@ var (
...
@@ -47,7 +47,8 @@ var (
noSummary
bool
noSummary
bool
noRemediations
bool
noRemediations
bool
filterOpts
FilterOpts
filterOpts
FilterOpts
includeTestOutput
bool
includeTestOutput
bool
outputFile
string
)
)
// RootCmd represents the base command when called without any subcommands
// RootCmd represents the base command when called without any subcommands
...
@@ -89,6 +90,7 @@ func init() {
...
@@ -89,6 +90,7 @@ func init() {
RootCmd
.
PersistentFlags
()
.
BoolVar
(
&
filterOpts
.
Scored
,
"scored"
,
true
,
"Run the scored CIS checks"
)
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
(
&
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
()
.
BoolVar
(
&
includeTestOutput
,
"include-test-output"
,
false
,
"Prints the actual result when test fails"
)
RootCmd
.
PersistentFlags
()
.
StringVar
(
&
outputFile
,
"outputfile"
,
""
,
"Writes the JSON results to output file"
)
RootCmd
.
PersistentFlags
()
.
StringVarP
(
RootCmd
.
PersistentFlags
()
.
StringVarP
(
&
filterOpts
.
CheckList
,
&
filterOpts
.
CheckList
,
...
...
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