Skip to content

Commit 16db01a

Browse files
rnjudgeNisha K
authored andcommitted
Fix CycloneDX report generation
Commit 0891287 introduced using the OCIImage class instead of DockerImage for container image analysis. There is a difference in the name and type of the variable that holds the repository tag ('repotags' list for DockerImage vs 'repotag' string for OCIImage) which is causing the CycloneDX format to break. This was not caught prior to the release because there are no tests for the CycloneDX format in the ci test file. This commit resolves the CycloneDX format bug by using the repository tag variable name depending on image type and also adds an appropriate test in the ci test file to try to avoid this issue in the future. Resolves #1097 Signed-off-by: Rose Judge <[email protected]>
1 parent 723f43d commit 16db01a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

ci/test_files_touched.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@
9999
'tern report -f spdxtagvalue -i photon:3.0',
100100
'tern report -f spdxjson -i photon:3.0',
101101
'tern report -d samples/alpine_python/Dockerfile',
102-
'tern report -f html -i photon:3.0'],
102+
'tern report -f html -i photon:3.0',
103+
'tern report -f cyclonedxjson -i photon:3.0'],
103104
# tern/formats/spdx
104105
re.compile('tern/formats/spdx'): [
105106
'tern report -f spdxtagvalue -i photon:3.0 -o spdx.spdx && ' \

tern/formats/cyclonedx/cyclonedxjson/image_helpers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
from tern.formats.cyclonedx import cyclonedx_common
1212
from packageurl import PackageURL
13+
from tern.classes.oci_image import OCIImage
14+
from tern.classes.docker_image import DockerImage
1315

1416

1517
def get_image_dict(image_obj):
@@ -28,9 +30,11 @@ def get_image_dict(image_obj):
2830
purl = PackageURL('docker', None, image_dict['name'], image_dict['version'])
2931
image_dict['purl'] = str(purl)
3032

31-
if image_obj.repotags:
33+
if isinstance(image_obj, DockerImage):
3234
for repotag in image_obj.repotags:
3335
image_dict['properties'].append(cyclonedx_common.get_property('tern:repotag', repotag))
36+
elif isinstance(image_obj, OCIImage):
37+
image_dict['properties'].append(cyclonedx_common.get_property('tern:repotag', image_obj.repotag))
3438

3539
os_guess = cyclonedx_common.get_os_guess(image_obj)
3640
if os_guess:

0 commit comments

Comments
 (0)