mirror of
https://github.com/aquasecurity/kube-bench.git
synced 2025-02-16 17:42:05 +00:00
Do not clutter the output with error messages from commands in the audit pipeline.
This commit is contained in:
parent
6ee9bedfb8
commit
b1a76360e7
@ -63,7 +63,7 @@ type Check struct {
|
|||||||
// Run executes the audit commands specified in a check and outputs
|
// Run executes the audit commands specified in a check and outputs
|
||||||
// the results.
|
// the results.
|
||||||
func (c *Check) Run() {
|
func (c *Check) Run() {
|
||||||
var out bytes.Buffer
|
var out, serr bytes.Buffer
|
||||||
|
|
||||||
// Check if command exists or exit with WARN.
|
// Check if command exists or exit with WARN.
|
||||||
for _, cmd := range c.Commands {
|
for _, cmd := range c.Commands {
|
||||||
@ -87,7 +87,8 @@ func (c *Check) Run() {
|
|||||||
// cmd0 err should terminate chain
|
// cmd0 err should terminate chain
|
||||||
cs := c.Commands
|
cs := c.Commands
|
||||||
|
|
||||||
cs[0].Stderr = os.Stderr
|
// Initialize command pipeline
|
||||||
|
cs[0].Stderr = &serr
|
||||||
cs[n-1].Stdout = &out
|
cs[n-1].Stdout = &out
|
||||||
i := 1
|
i := 1
|
||||||
|
|
||||||
@ -99,27 +100,26 @@ func (c *Check) Run() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
cs[i].Stderr = os.Stderr
|
cs[i].Stderr = &serr
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start command pipeline
|
||||||
i = 0
|
i = 0
|
||||||
for i < n {
|
for i < n {
|
||||||
err := cs[i].Start()
|
cs[i].Start()
|
||||||
if err != nil {
|
i++
|
||||||
fmt.Fprintf(os.Stderr, "%s: %s\n", cs[i].Args, err)
|
}
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
errw := cs[i].Wait()
|
// Complete command pipeline
|
||||||
if err != nil {
|
i = 0
|
||||||
fmt.Fprintf(os.Stderr, "%s: %s\n", cs[i].Args, errw)
|
for i < n {
|
||||||
os.Exit(1)
|
cs[i].Wait()
|
||||||
}
|
|
||||||
|
|
||||||
if i < n-1 {
|
if i < n-1 {
|
||||||
cs[i].Stdout.(io.Closer).Close()
|
cs[i].Stdout.(io.Closer).Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user