Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enrich command - handle errors when no response #251

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading