diff --git a/README.md b/README.md index 19e9a6d..cefa934 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,7 @@ Options: -l, --log="" Log to a file --all, --reportAll=true Display all vulnerabilities, even if they are approved -r, --report="" Report output file, as JSON + --exit-when-no-features=false Exit with status code 5 when no features are found for a particular image ``` ## Example whitelist yaml file diff --git a/main.go b/main.go index 0ae69d7..7cfd00e 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,7 @@ func main() { reportAll = app.BoolOpt("all reportAll", true, "Display all vulnerabilities, even if they are approved") reportFile = app.StringOpt("r report", "", "Report output file, as JSON") imageName = app.StringArg("IMAGE", "", "Name of the Docker image to scan") - exitWhenNoFeatures = app.BoolOpt("exit-when-no-features", false, "Exit with status code 1 when no features are found for a particular image") + exitWhenNoFeatures = app.BoolOpt("exit-when-no-features", false, "Exit with status code 5 when no features are found for a particular image") ) app.Before = func() { @@ -54,7 +54,9 @@ func main() { *reportAll, *exitWhenNoFeatures, }) - if len(result) > 0 { + if result == nil { + os.Exit(5) + } else if len(result) > 0 { os.Exit(1) } } diff --git a/scanner.go b/scanner.go index 114d055..2b486e6 100644 --- a/scanner.go +++ b/scanner.go @@ -40,8 +40,8 @@ func scan(config scannerConfig) []string { analyzeLayers(layerIds, config.clairURL, config.scannerIP) vulnerabilities := getVulnerabilities(config, layerIds) - if len(vulnerabilities) == 0 { - return []string{} + if vulnerabilities == nil { + return nil; // exit when no features } //Check vulnerabilities against whitelist and report