mirror of
https://github.com/aquasecurity/kube-bench.git
synced 2024-12-18 20:58:10 +00:00
Fix version command failing because of missing config file it does not need. (#377)
* Fix version command failing because of missing config file it does not need. * Fix typo * Remove reference to github issue in comment
This commit is contained in:
parent
787bf6ca4d
commit
3fba5f4dac
@ -65,6 +65,12 @@ func NewRunFilter(opts FilterOpts) (check.Predicate, error) {
|
|||||||
func runChecks(nodetype check.NodeType) {
|
func runChecks(nodetype check.NodeType) {
|
||||||
var summary check.Summary
|
var summary check.Summary
|
||||||
|
|
||||||
|
// Verify config file was loaded into Viper during Cobra sub-command initialization.
|
||||||
|
if configFileError != nil {
|
||||||
|
colorPrint(check.FAIL, fmt.Sprintf("Failed to read config file: %v\n", configFileError))
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
def := loadConfig(nodetype)
|
def := loadConfig(nodetype)
|
||||||
in, err := ioutil.ReadFile(def)
|
in, err := ioutil.ReadFile(def)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -49,6 +49,7 @@ var (
|
|||||||
filterOpts FilterOpts
|
filterOpts FilterOpts
|
||||||
includeTestOutput bool
|
includeTestOutput bool
|
||||||
outputFile string
|
outputFile string
|
||||||
|
configFileError error
|
||||||
)
|
)
|
||||||
|
|
||||||
// RootCmd represents the base command when called without any subcommands
|
// RootCmd represents the base command when called without any subcommands
|
||||||
@ -134,7 +135,14 @@ func initConfig() {
|
|||||||
|
|
||||||
// If a config file is found, read it in.
|
// If a config file is found, read it in.
|
||||||
if err := viper.ReadInConfig(); err != nil {
|
if err := viper.ReadInConfig(); err != nil {
|
||||||
|
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
||||||
|
// Config file not found; ignore error for now to prevent commands
|
||||||
|
// which don't need the config file exiting.
|
||||||
|
configFileError = err
|
||||||
|
} else {
|
||||||
|
// Config file was found but another error was produced
|
||||||
colorPrint(check.FAIL, fmt.Sprintf("Failed to read config file: %v\n", err))
|
colorPrint(check.FAIL, fmt.Sprintf("Failed to read config file: %v\n", err))
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user