From 7c4033b718a4558e36c32e323df09a27480250b8 Mon Sep 17 00:00:00 2001 From: Christoph Hartmann Date: Fri, 16 Feb 2024 19:55:18 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20remove=20useless=20if=20conditio?= =?UTF-8?q?ns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sbom/sbom.go | 78 +++++++++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/sbom/sbom.go b/sbom/sbom.go index 095d328986..94d7956aac 100644 --- a/sbom/sbom.go +++ b/sbom/sbom.go @@ -98,54 +98,52 @@ func GenerateBom(r *ReportCollectionJson) ([]Sbom, error) { bom.Packages = append(bom.Packages, bomPkg) } } - if rb.PythonPackages != nil { - for _, pkg := range rb.PythonPackages { - bomPkg := &Package{ - Name: pkg.Name, - Version: pkg.Version, - Purl: pkg.Purl, - Cpes: pkg.CPEs, - Type: "pypi", - } - // deprecated path, all files are now in the FilePaths field - // TODO: update once the python resource returns multiple results - if pkg.FilePath != "" { - bomPkg.EvidenceList = append(bomPkg.EvidenceList, &Evidence{ - Type: EvidenceType_EVIDENCE_TYPE_FILE, - Value: pkg.FilePath, - }) - } + for _, pkg := range rb.PythonPackages { + bomPkg := &Package{ + Name: pkg.Name, + Version: pkg.Version, + Purl: pkg.Purl, + Cpes: pkg.CPEs, + Type: "pypi", + } - for _, filepath := range pkg.FilePaths { - bomPkg.EvidenceList = append(bomPkg.EvidenceList, &Evidence{ - Type: EvidenceType_EVIDENCE_TYPE_FILE, - Value: filepath, - }) - } + // deprecated path, all files are now in the FilePaths field + // TODO: update once the python resource returns multiple results + if pkg.FilePath != "" { + bomPkg.EvidenceList = append(bomPkg.EvidenceList, &Evidence{ + Type: EvidenceType_EVIDENCE_TYPE_FILE, + Value: pkg.FilePath, + }) + } - bom.Packages = append(bom.Packages, bomPkg) + for _, filepath := range pkg.FilePaths { + bomPkg.EvidenceList = append(bomPkg.EvidenceList, &Evidence{ + Type: EvidenceType_EVIDENCE_TYPE_FILE, + Value: filepath, + }) } + + bom.Packages = append(bom.Packages, bomPkg) } - if rb.NpmPackages != nil { - for _, pkg := range rb.NpmPackages { - bomPkg := &Package{ - Name: pkg.Name, - Version: pkg.Version, - Purl: pkg.Purl, - Cpes: pkg.CPEs, - Type: "npm", - } - for _, filepath := range pkg.FilePaths { - bomPkg.EvidenceList = append(bomPkg.EvidenceList, &Evidence{ - Type: EvidenceType_EVIDENCE_TYPE_FILE, - Value: filepath, - }) - } + for _, pkg := range rb.NpmPackages { + bomPkg := &Package{ + Name: pkg.Name, + Version: pkg.Version, + Purl: pkg.Purl, + Cpes: pkg.CPEs, + Type: "npm", + } - bom.Packages = append(bom.Packages, bomPkg) + for _, filepath := range pkg.FilePaths { + bomPkg.EvidenceList = append(bomPkg.EvidenceList, &Evidence{ + Type: EvidenceType_EVIDENCE_TYPE_FILE, + Value: filepath, + }) } + + bom.Packages = append(bom.Packages, bomPkg) } } boms = append(boms, bom)