diff --git a/scanpipe/pipes/input.py b/scanpipe/pipes/input.py index f57e7eafd..0ca8c0cb2 100644 --- a/scanpipe/pipes/input.py +++ b/scanpipe/pipes/input.py @@ -19,7 +19,6 @@ # # ScanCode.io is a free software code scanning tool from nexB Inc. and others. # Visit https://github.com/aboutcode-org/scancode.io for support and download. - import shutil from pathlib import Path @@ -199,3 +198,7 @@ def load_inventory_from_xlsx(project, input_location): cleaned_data = clean_xlsx_data_to_model_data(model_class, row_data) if cleaned_data: object_maker_func(project, cleaned_data) + + if "LAYERS" in workbook: + layers_data = get_worksheet_data(worksheet=workbook["LAYERS"]) + project.update_extra_data({"layers": layers_data}) diff --git a/scanpipe/tests/data/outputs/docker_ghcr.io_kyverno_sbom.xlsx b/scanpipe/tests/data/outputs/docker_ghcr.io_kyverno_sbom.xlsx new file mode 100644 index 000000000..e6414efd6 Binary files /dev/null and b/scanpipe/tests/data/outputs/docker_ghcr.io_kyverno_sbom.xlsx differ diff --git a/scanpipe/tests/data/outputs/docker_ghcr.io_kyverno_sbom_expected.json b/scanpipe/tests/data/outputs/docker_ghcr.io_kyverno_sbom_expected.json new file mode 100644 index 000000000..de21973a3 --- /dev/null +++ b/scanpipe/tests/data/outputs/docker_ghcr.io_kyverno_sbom_expected.json @@ -0,0 +1,16 @@ +{ + "layers": [ + { + "size": "5886464", + "author": null, + "comment": null, + "created": "2021-11-12T17:19:44.795237917Z", + "image_id": "12ebda3111cec73a788b0e802a00de04ebf5e9765043925dd396c2d03a7c1e66", + "layer_id": "1a058d5342cc722ad5439cacae4b2b4eedde51d8fe8800fcf28444302355c16d", + "layer_tag": "img-12ebda-layer-01-1a058d", + "created_by": "/bin/sh -c #(nop) ADD file:762c899ec0505d1a32930ee804c5b008825f41611161be104076cba33b7e5b2b in / ", + "xlsx_errors": null, + "archive_location": "ghcr_io_kyverno_sbom.tar-extract/1a058d5342cc722ad5439cacae4b2b4eedde51d8fe8800fcf28444302355c16d.tar" + } + ] +} \ No newline at end of file diff --git a/scanpipe/tests/pipes/test_input.py b/scanpipe/tests/pipes/test_input.py index d81f92e24..55f8ebddf 100644 --- a/scanpipe/tests/pipes/test_input.py +++ b/scanpipe/tests/pipes/test_input.py @@ -118,6 +118,17 @@ def test_scanpipe_pipes_input_load_inventory_from_xlsx(self): self.assertEqual(8, project1.discovereddependencies.count()) self.assertEqual(0, project1.codebaserelations.count()) + def test_scanpipe_pipes_input_load_inventory_from_xlsx_layers_sheet(self): + project1 = Project.objects.create(name="Analysis") + input_location = self.data / "outputs" / "docker_ghcr.io_kyverno_sbom.xlsx" + input.load_inventory_from_xlsx(project1, input_location) + project1.refresh_from_db() + expected_location = ( + self.data / "outputs" / "docker_ghcr.io_kyverno_sbom_expected.json" + ) + expected = json.loads(expected_location.read_text()) + self.assertEqual(expected, project1.extra_data) + def test_scanpipe_pipes_input_load_inventory_from_project_xlsx_output(self): fixtures = self.data / "asgiref" / "asgiref-3.3.0_fixtures.json" call_command("loaddata", fixtures, **{"verbosity": 0})