Skip to content

Commit ced13f7

Browse files
committed
Add support for all_formats/all_outputs in REST API #1880
Signed-off-by: tdruez <[email protected]>
1 parent 1fbe437 commit ced13f7

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

docs/command-line-interface.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,11 @@ Displays status information about the ``PROJECT`` project.
419419

420420
.. _cli_output:
421421

422-
`$ scanpipe output --project PROJECT --format {json,csv,xlsx,spdx,cyclonedx,attribution}`
423-
-----------------------------------------------------------------------------------------
422+
`$ scanpipe output --project PROJECT --format {json,csv,xlsx,spdx,cyclonedx,attribution,ort-package-list}`
423+
----------------------------------------------------------------------------------------------------------
424424

425-
Outputs the ``PROJECT`` results as JSON, XLSX, CSV, SPDX, CycloneDX, and Attribution.
425+
Outputs the ``PROJECT`` results as JSON, XLSX, CSV, SPDX, CycloneDX,
426+
ORT package-list.yml, and Attribution.
426427
The output files are created in the ``PROJECT`` :guilabel:`output/` directory.
427428

428429
Multiple formats can be provided at once::

docs/output-files.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ Additional sheets are included **only when relevant** (i.e., when data is availa
285285

286286
SPDX
287287
^^^^
288-
289288
ScanCode.io can generate Software Bill of Materials (SBOM) in the **SPDX** format,
290289
which is an open standard for communicating software component information.
291290
SPDX is widely used for license compliance, security analysis, and software supply
@@ -309,7 +308,6 @@ The SPDX output includes:
309308

310309
CycloneDX
311310
^^^^^^^^^
312-
313311
ScanCode.io can generate **CycloneDX** SBOMs, a lightweight standard designed for
314312
security and dependency management. CycloneDX is optimized for vulnerability analysis
315313
and software supply chain risk assessment.

docs/rest-api.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,10 +694,16 @@ Finally, use this action to download the project results in the provided
694694
``output_format`` as an attachment file.
695695

696696
Data:
697-
- ``output_format``: ``json``, ``xlsx``, ``spdx``, ``cyclonedx``, ``attribution``
697+
- ``output_format``: ``json``, ``xlsx``, ``spdx``, ``cyclonedx``, ``attribution``,
698+
``all_formats``, ``all_outputs``
698699

699700
``GET /api/projects/d4ed9405-5568-45ad-99f6-782a9b82d1d2/results_download/?output_format=cyclonedx``
700701

702+
.. note::
703+
Use ``all_formats`` to generate a zip file containing all output formats for a
704+
project, while ``all_outputs`` can be used to obtain a zip file of all existing
705+
output files for that project.
706+
701707
.. tip::
702708
Refer to :ref:`output_files` to learn more about the available output formats.
703709

scanpipe/api/views.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ def results_download(self, request, *args, **kwargs):
171171
output_file = output.to_attribution(project)
172172
elif format == "ort-package-list":
173173
output_file = output.to_ort_package_list_yml(project)
174+
elif format == "all_formats":
175+
output_file = output.to_all_formats(project)
176+
elif format == "all_outputs":
177+
output_file = output.to_all_outputs(project)
174178
else:
175179
message = {"status": f"Format {format} not supported."}
176180
return Response(message, status=status.HTTP_400_BAD_REQUEST)

scanpipe/tests/test_api.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,16 @@ def test_scanpipe_api_project_action_results_download_output_formats(self):
669669
# to prevent a "ResourceWarning: unclosed file"
670670
self.assertTrue(response.getvalue().startswith(b"PK"))
671671

672+
data = {"output_format": "all_formats"}
673+
response = self.csrf_client.get(url, data=data)
674+
expected = ["application/zip"]
675+
self.assertIn(response["Content-Type"], expected)
676+
677+
data = {"output_format": "all_outputs"}
678+
response = self.csrf_client.get(url, data=data)
679+
expected = ["application/zip"]
680+
self.assertIn(response["Content-Type"], expected)
681+
672682
def test_scanpipe_api_project_action_pipelines(self):
673683
url = reverse("project-pipelines")
674684
response = self.csrf_client.get(url)

0 commit comments

Comments
 (0)