Skip to content

Commit

Permalink
Improve empty result handler
Browse files Browse the repository at this point in the history
  • Loading branch information
skjolber committed Jul 2, 2019
1 parent 760ffa1 commit 38a6d69
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 38a6d69

Please sign in to comment.