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

feat: change image data field #342

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
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
14 changes: 7 additions & 7 deletions sbom/test_update_component_sbom.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@

class TestUpdateComponentSBOM(unittest.TestCase):
def test_get_component_to_purls_map_single_arch(self) -> None:
release_note_images = [
images = [
{"component": "comp1", "purl": "purl1"},
{"component": "comp1", "purl": "purl2"},
{"component": "comp2", "purl": "purl3"},
]

result = get_component_to_purls_map(release_note_images)
result = get_component_to_purls_map(images)
assert result == {
"comp1": ["purl1", "purl2"],
"comp2": ["purl3"],
}

def test_get_component_to_purls_map_multi_arch(self) -> None:
release_note_images = [
images = [
{
"component": "comp1",
"purl": "pkg:oci/bar@sha256%3Aabcde?arch=amd64&repository_url=registry.io/foo",
Expand All @@ -35,7 +35,7 @@ def test_get_component_to_purls_map_multi_arch(self) -> None:
},
]

result = get_component_to_purls_map(release_note_images)
result = get_component_to_purls_map(images)
assert result == {
"comp1": ["pkg:oci/bar@sha256%3Afoosha1?repository_url=registry.io/foo"],
"comp1_amd64": [
Expand Down Expand Up @@ -167,7 +167,7 @@ def test_update_sboms_with_cyclonedex_format(
# defined in the mock_open
test_cyclonedx_sbom = {
"bomFormat": "CycloneDX",
"releaseNotes": {"content": {"images": "foo"}},
"images": "foo",
}

with patch(
Expand Down Expand Up @@ -195,7 +195,7 @@ def test_update_sboms_with_spdx_format(
) -> None:
# combining the content of data.json and sbom, since there can only be one read_data
# defined in the mock_open
test_spdx_sbom = {"spdxVersion": "2.3", "releaseNotes": {"content": {"images": "foo"}}}
test_spdx_sbom = {"spdxVersion": "2.3", "images": "foo"}

with patch(
"builtins.open", mock_open(read_data=json.dumps(test_spdx_sbom))
Expand All @@ -222,7 +222,7 @@ def test_update_sboms_with_wrong_format(
# defined in the mock_open
test_spdx_sbom = {
"notSbom": "NoSbomVersion",
"releaseNotes": {"content": {"images": "foo"}},
"images": "foo",
}

with patch(
Expand Down
4 changes: 1 addition & 3 deletions sbom/update_component_sbom.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ def update_sboms(data_path: str, input_path: str, output_path: str) -> None:
with open(data_path, "r") as data_file:
data = json.load(data_file)

component_to_purls_map = get_component_to_purls_map(
data["releaseNotes"]["content"].get("images", [])
)
component_to_purls_map = get_component_to_purls_map(data.get("images", []))
# get all json files in input dir
input_jsons = glob.glob(os.path.join(input_path, "*.json"))
# loop through files
Expand Down
Loading