Skip to content

Commit ede4645

Browse files
committed
Add package supplier info to SPDX reports
This commit adds `pkg_supplier` attribute values as `PackageSupplier` field values in Tag Value and JSON SPDX documents . Resolves #1205 Signed-off-by: Rose Judge <[email protected]>
1 parent bb2a724 commit ede4645

File tree

7 files changed

+15
-1
lines changed

7 files changed

+15
-1
lines changed

tern/formats/spdx/spdx.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def package(self):
2121
'copyright': 'PackageCopyrightText',
2222
'download_url': 'PackageDownloadLocation',
2323
'src_name': 'SourcePackageName',
24-
'src_version': 'SourcePackageVersion'}
24+
'src_version': 'SourcePackageVersion',
25+
'pkg_supplier': 'PackageSupplier'}
2526

2627
def image_layer(self):
2728
return {'tar_file': 'PackageFileName'}

tern/formats/spdx/spdxjson/image_helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def get_image_dict(image_obj, template):
8484
'name': mapping['PackageName'],
8585
'SPDXID': spdx_common.get_image_spdxref(image_obj),
8686
'versionInfo': mapping['PackageVersion'],
87+
'supplier': 'NOASSERTION', # always NOASSERTION
8788
'downloadLocation': 'NOASSERTION', # always NOASSERTION
8889
'filesAnalyzed': False, # always false
8990
'licenseConcluded': 'NOASSERTION', # always NOASSERTION

tern/formats/spdx/spdxjson/layer_helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ def get_layer_dict(layer_obj):
150150
'name': os.path.basename(layer_obj.tar_file),
151151
'SPDXID': spdx_common.get_layer_spdxref(layer_obj),
152152
'versionInfo': layer_obj.layer_index,
153+
'supplier': 'NOASSERTION', # always NOASSERTION
153154
'packageFileName': layer_obj.tar_file,
154155
'downloadLocation': 'NONE',
155156
'filesAnalyzed': bool(layer_obj.files_analyzed),

tern/formats/spdx/spdxjson/package_helpers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ def get_package_dict(package, template):
5858
JSON dictionary representation of the package. The analyzed files will
5959
go in a separate dictionary for the JSON document.'''
6060
mapping = package.to_dict(template)
61+
supplier_str = 'Organization: ' + mapping['PackageSupplier']
6162
pkg_ref, _ = spdx_common.get_package_spdxref(package)
6263
package_dict = {
6364
'name': mapping['PackageName'],
6465
'SPDXID': pkg_ref,
6566
'versionInfo': mapping['PackageVersion'] if mapping['PackageVersion']
6667
else 'NOASSERTION',
68+
'supplier': supplier_str if mapping['PackageSupplier'] else 'NOASSERTION',
6769
'downloadLocation': mapping['PackageDownloadLocation'] if
6870
mapping['PackageDownloadLocation'] else 'NOASSERTION',
6971
'filesAnalyzed': False, # always false for packages

tern/formats/spdx/spdxtagvalue/image_helpers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ def get_image_block(image_obj, template):
101101
block += 'SPDXID: {}\n'.format(spdx_common.get_image_spdxref(image_obj))
102102
# Package Version
103103
block += 'PackageVersion: {}\n'.format(mapping['PackageVersion'])
104+
# Package Supplier (always NOASSERTION)
105+
block += 'PackageSupplier: NOASSERTION\n'
104106
# Package Download Location (always NOASSERTION)
105107
block += 'PackageDownloadLocation: NOASSERTION\n'
106108
# Files Analyzed (always false)

tern/formats/spdx/spdxtagvalue/layer_helpers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ def get_layer_block(layer_obj, template):
117117
block += 'SPDXID: {}\n'.format(spdx_common.get_layer_spdxref(layer_obj))
118118
# Package Version. For Layer objects, this is just the layer_index
119119
block += 'PackageVersion: {}\n'.format(layer_obj.layer_index)
120+
# Package Supplier (always NOASSERTION)
121+
block += 'PackageSupplier: NOASSERTION\n'
120122
# Package File Name
121123
block += 'PackageFileName: {}\n'.format(layer_obj.tar_file)
122124
# Package Download Location (always NONE for layers)

tern/formats/spdx/spdxtagvalue/package_helpers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ def get_package_block(package_obj, template):
8686
# Package Version
8787
if mapping['PackageVersion']:
8888
block += 'PackageVersion: {}\n'.format(mapping['PackageVersion'])
89+
# Package Supplier
90+
if mapping['PackageSupplier']:
91+
block += 'PackageSupplier: Organization: {}\n'.format(mapping['PackageSupplier'])
92+
else:
93+
block += 'PackageSupplier: NOASSERTION\n'
8994
# Package Download Location
9095
if mapping['PackageDownloadLocation']:
9196
block += 'PackageDownloadLoaction: {}\n'.format(

0 commit comments

Comments
 (0)