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
b4237ccb
Commit
b4237ccb
authored
7 years ago
by
Liz Rice
Browse files
Options
Downloads
Patches
Plain Diff
Better error handling when reading YAML files
parent
f920d61a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
check/controls.go
+5
-9
5 additions, 9 deletions
check/controls.go
check/test_test.go
+4
-1
4 additions, 1 deletion
check/test_test.go
cmd/common.go
+6
-2
6 additions, 2 deletions
cmd/common.go
with
15 additions
and
12 deletions
check/controls.go
+
5
−
9
View file @
b4237ccb
...
@@ -17,7 +17,6 @@ package check
...
@@ -17,7 +17,6 @@ package check
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"os"
yaml
"gopkg.in/yaml.v2"
yaml
"gopkg.in/yaml.v2"
)
)
...
@@ -46,19 +45,16 @@ type Summary struct {
...
@@ -46,19 +45,16 @@ type Summary struct {
}
}
// NewControls instantiates a new master Controls object.
// NewControls instantiates a new master Controls object.
func
NewControls
(
t
NodeType
,
in
[]
byte
)
*
Controls
{
func
NewControls
(
t
NodeType
,
in
[]
byte
)
(
*
Controls
,
error
)
{
var
err
error
c
:=
new
(
Controls
)
c
:=
new
(
Controls
)
err
=
yaml
.
Unmarshal
(
in
,
c
)
err
:
=
yaml
.
Unmarshal
(
in
,
c
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"%s
\n
"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to unmarshal YAML: %s"
,
err
)
os
.
Exit
(
1
)
}
}
if
t
!=
c
.
Type
{
if
t
!=
c
.
Type
{
fmt
.
Fprintf
(
os
.
Stderr
,
"non-%s controls file specified
\n
"
,
t
)
return
nil
,
fmt
.
Errorf
(
"non-%s controls file specified"
,
t
)
os
.
Exit
(
1
)
}
}
// Prepare audit commands
// Prepare audit commands
...
@@ -68,7 +64,7 @@ func NewControls(t NodeType, in []byte) *Controls {
...
@@ -68,7 +64,7 @@ func NewControls(t NodeType, in []byte) *Controls {
}
}
}
}
return
c
return
c
,
nil
}
}
// RunGroup runs all checks in a group.
// RunGroup runs all checks in a group.
...
...
This diff is collapsed.
Click to expand it.
check/test_test.go
+
4
−
1
View file @
b4237ccb
...
@@ -30,7 +30,10 @@ func init() {
...
@@ -30,7 +30,10 @@ func init() {
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
"Failed reading test data: "
+
err
.
Error
())
panic
(
"Failed reading test data: "
+
err
.
Error
())
}
}
controls
=
NewControls
(
MASTER
,
in
)
controls
,
err
=
NewControls
(
MASTER
,
in
)
if
err
!=
nil
{
panic
(
"Failed creating test controls: "
+
err
.
Error
())
}
}
}
func
TestTestExecute
(
t
*
testing
.
T
)
{
func
TestTestExecute
(
t
*
testing
.
T
)
{
...
...
This diff is collapsed.
Click to expand it.
cmd/common.go
+
6
−
2
View file @
b4237ccb
...
@@ -88,7 +88,7 @@ func runChecks(t check.NodeType) {
...
@@ -88,7 +88,7 @@ func runChecks(t check.NodeType) {
in
,
err
:=
ioutil
.
ReadFile
(
file
)
in
,
err
:=
ioutil
.
ReadFile
(
file
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"error opening %s controls file: %
s
\n
"
,
t
,
err
)
fmt
.
Fprintf
(
os
.
Stderr
,
"error opening %s controls file: %
v
\n
"
,
t
,
err
)
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
...
@@ -97,7 +97,11 @@ func runChecks(t check.NodeType) {
...
@@ -97,7 +97,11 @@ func runChecks(t check.NodeType) {
s
=
strings
.
Replace
(
s
,
"$etcdConfDir"
,
viper
.
Get
(
"etcdConfDir"
)
.
(
string
),
-
1
)
s
=
strings
.
Replace
(
s
,
"$etcdConfDir"
,
viper
.
Get
(
"etcdConfDir"
)
.
(
string
),
-
1
)
s
=
strings
.
Replace
(
s
,
"$flanneldConfDir"
,
viper
.
Get
(
"flanneldConfDir"
)
.
(
string
),
-
1
)
s
=
strings
.
Replace
(
s
,
"$flanneldConfDir"
,
viper
.
Get
(
"flanneldConfDir"
)
.
(
string
),
-
1
)
controls
:=
check
.
NewControls
(
t
,
[]
byte
(
s
))
controls
,
err
:=
check
.
NewControls
(
t
,
[]
byte
(
s
))
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"error setting up %s controls: %v
\n
"
,
t
,
err
)
os
.
Exit
(
1
)
}
if
groupList
!=
""
&&
checkList
==
""
{
if
groupList
!=
""
&&
checkList
==
""
{
ids
:=
cleanIDs
(
groupList
)
ids
:=
cleanIDs
(
groupList
)
...
...
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