From 2081f718bcbc178abdde1be83072f2ee667972e0 Mon Sep 17 00:00:00 2001 From: Peter van Dijk Date: Fri, 20 Sep 2024 18:41:58 +0200 Subject: [PATCH] dnf sbom: handle arch absence --- builder-support/helpers/generate-sbom-dnf.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/builder-support/helpers/generate-sbom-dnf.py b/builder-support/helpers/generate-sbom-dnf.py index c90025ec9a81..621990c64664 100755 --- a/builder-support/helpers/generate-sbom-dnf.py +++ b/builder-support/helpers/generate-sbom-dnf.py @@ -45,9 +45,11 @@ def addDependencyToSBOM(sbom, appInfos, pkg): bomRef = 'lib:' + pkg.name component = { 'name': pkg.name, 'bom-ref': bomRef, 'type': 'library'} if pkg.release: - component['version'] = (pkg.version if pkg.epoch == 0 else str(pkg.epoch) + ':' + pkg.version) + '-' + pkg.release + '.' + pkg.arch + component['version'] = (pkg.version if pkg.epoch == 0 else str(pkg.epoch) + ':' + pkg.version) + '-' + pkg.release else: - component['version'] = (pkg.version if pkg.epoch == 0 else str(pkg.epoch) + ':' + pkg.version) + '.' + pkg.arch + component['version'] = (pkg.version if pkg.epoch == 0 else str(pkg.epoch) + ':' + pkg.version) + if hasattr(pkg, 'arch'): + component['version'] += '.' + pkg.arch if hasattr(pkg, 'vendor') and pkg.vendor is not None: component['supplier'] = {'name': pkg.vendor} if hasattr(pkg, 'publisher') and pkg.publisher is not None: @@ -134,9 +136,12 @@ def generateSBOM(packageName, additionalDeps): component = { 'name': appName, 'bom-ref': 'pkg:' + appName, 'type': 'application'} if appInfos.release: - component['version'] = (appInfos.version if appInfos.epoch == 0 else str(appInfos.epoch) + ':' + appInfos.version) + '-' + appInfos.release + '.' + appInfos.arch + component['version'] = (appInfos.version if appInfos.epoch == 0 else str(appInfos.epoch) + ':' + appInfos.version) + '-' + appInfos.release else: - component['version'] = (appInfos.version if appInfos.epoch == 0 else str(appInfos.epoch) + ':' + appInfos.version) + '.' + appInfos.arch + component['version'] = (appInfos.version if appInfos.epoch == 0 else str(appInfos.epoch) + ':' + appInfos.version) + + if hasattr(appInfos, 'arch'): + component['version'] += '.' + appInfos.arch component['supplier'] = {'name': appInfos.vendor if appInfos.vendor != '' else 'PowerDNS.COM BV', 'url': ['https://www.powerdns.com']} component['licenses'] = [{'license': {'id': licenseToSPDXIdentifier(appInfos.license)}}]