Skip to content

Commit

Permalink
fix(cli): scan-pkg-manifest returns valid JSON when no vulns are found (
Browse files Browse the repository at this point in the history
  • Loading branch information
dmurray-lacework authored Jul 28, 2021
1 parent 7c00c09 commit 0cdcc7e
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions cli/cmd/vuln_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ To generate a package-manifest from the local host and scan it automatically:
return errors.Wrap(err, "unable to request an on-demand host vulnerability scan")
}

if err := buildVulnHostScanPkgManifestReports(response); err != nil {
if err := buildVulnHostScanPkgManifestReports(&response); err != nil {
return err
}

Expand Down Expand Up @@ -887,7 +887,7 @@ func hostScanPackagesVulnToTable(scan *api.HostVulnScanPkgManifestResponse) stri
}

func filterHostScanPackagesVulnDetails(vulns []api.HostScanPackageVulnDetails) []api.HostScanPackageVulnDetails {
var out []api.HostScanPackageVulnDetails
out := make([]api.HostScanPackageVulnDetails, 0)

for _, vuln := range vulns {
if vulCmdState.Fixable && vuln.HasFix() {
Expand Down Expand Up @@ -1088,21 +1088,17 @@ func buildListCVEReports(cves []api.HostVulnCVE) error {
}

// Build the cli output for vuln host scan-package-manifest
func buildVulnHostScanPkgManifestReports(response api.HostVulnScanPkgManifestResponse) error {
if len(response.Vulns) == 0 {
// @afiune add a helpful message, possible things are:
cli.OutputHuman(fmt.Sprintf("There are no vulnerabilities found! Time for %s\n", randomEmoji()))
return nil
}

func buildVulnHostScanPkgManifestReports(response *api.HostVulnScanPkgManifestResponse) error {
response.Vulns = filterHostScanPackagesVulnDetails(response.Vulns)

if cli.JSONOutput() {
if err := cli.OutputJSON(response); err != nil {
return err
}
return cli.OutputJSON(response)
}

if len(response.Vulns) == 0 {
cli.OutputHuman(fmt.Sprintf("There are no vulnerabilities found! Time for %s\n", randomEmoji()))
} else {
cli.OutputHuman(hostScanPackagesVulnToTable(&response))
cli.OutputHuman(hostScanPackagesVulnToTable(response))
}

return nil
Expand Down

0 comments on commit 0cdcc7e

Please sign in to comment.