Skip to content

Commit

Permalink
Enrich command - handle errors when no response (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
barv-jfrog authored Nov 28, 2024
1 parent da21ea9 commit 560b98a
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions commands/enrich/enrich.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,21 @@ func AppendVulnsToJson(cmdResults *results.SecurityCommandResults) error {
fileName := getScaScanFileName(cmdResults)
fileContent, err := os.ReadFile(fileName)
if err != nil {
fmt.Println("Error reading file:", err)
return err
return fmt.Errorf("error reading file: %s", err.Error())
}
var data map[string]interface{}
err = json.Unmarshal(fileContent, &data)
if err != nil {
fmt.Println("Error parsing XML:", err)
return err
return fmt.Errorf("error parsing JSON: %s", err.Error())
}
var vulnerabilities []map[string]string
xrayResults := cmdResults.GetScaScansXrayResults()[0]
for _, vuln := range xrayResults.Vulnerabilities {
xrayResults := cmdResults.GetScaScansXrayResults()
if len(xrayResults) == 0 {
return fmt.Errorf("failed while getting sca scan from xray: %s", err.Error())
} else if len(xrayResults) > 1 {
log.Warn("Received %d results, parsing only first result", len(xrayResults))
}
for _, vuln := range xrayResults[0].Vulnerabilities {
for component := range vuln.Components {
vulnerability := map[string]string{"bom-ref": component, "id": vuln.Cves[0].Id}
vulnerabilities = append(vulnerabilities, vulnerability)
Expand All @@ -102,9 +105,14 @@ func AppendVulnsToXML(cmdResults *results.SecurityCommandResults) error {
return err
}
destination := result.FindElements("//bom")[0]
xrayResults := cmdResults.GetScaScansXrayResults()[0]
xrayResults := cmdResults.GetScaScansXrayResults()
if len(xrayResults) == 0 {
return fmt.Errorf("failed while getting sca scan from xray: %s", err.Error())
} else if len(xrayResults) > 1 {
log.Warn("Received %d results, parsing only first result", len(xrayResults))
}
vulns := destination.CreateElement("vulnerabilities")
for _, vuln := range xrayResults.Vulnerabilities {
for _, vuln := range xrayResults[0].Vulnerabilities {
for component := range vuln.Components {
addVuln := vulns.CreateElement("vulnerability")
addVuln.CreateAttr("bom-ref", component)
Expand Down

0 comments on commit 560b98a

Please sign in to comment.