Skip to content

Commit aca7787

Browse files
committed
Refactor the "Import manifest" feature as "Load SBOMs" #61
The process is now using the new specialized "load_sbom" pipeline. Signed-off-by: tdruez <tdruez@nexb.com>
1 parent 12aceef commit aca7787

13 files changed

Lines changed: 125 additions & 83 deletions

File tree

dejacode_toolkit/scancodeio.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ def submit_scan(self, uri, user_uuid, dataspace_uuid):
7676
logger.debug(f'{self.label}: submit scan uri="{uri}" webhook_url="{webhook_url}"')
7777
return self.request_post(url=self.project_api_url, json=data)
7878

79-
def submit_manifest_inspection(self, project_name, file_location, user_uuid, execute_now=False):
79+
def submit_load_sbom(self, project_name, file_location, user_uuid, execute_now=False):
8080
data = {
8181
"name": project_name,
82-
"pipeline": "inspect_packages",
82+
"pipeline": "load_sbom",
8383
"execute_now": execute_now,
8484
}
8585
files = {
@@ -92,7 +92,7 @@ def submit_manifest_inspection(self, project_name, file_location, user_uuid, exe
9292
data["webhook_url"] = webhook_url
9393

9494
logger.debug(
95-
f"{self.label}: submit manifest inspection "
95+
f"{self.label}: submit load sbom "
9696
f'project_name="{project_name}" webhook_url="{webhook_url}"'
9797
)
9898
return self.request_post(url=self.project_api_url, data=data, files=files)

dje/tasks.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,12 @@ def scancodeio_submit_scan(uris, user_uuid, dataspace_uuid):
115115

116116

117117
@job
118-
def scancodeio_submit_manifest_inspection(scancodeproject_uuid, user_uuid):
119-
"""
120-
Submit the provided `uris` to ScanCode.io as an asynchronous task.
121-
Only publicly available URLs are sent to ScanCode.io.
122-
"""
118+
def scancodeio_submit_load_sbom(scancodeproject_uuid, user_uuid):
119+
"""Submit the provided SBOM file to ScanCode.io as an asynchronous task."""
123120
from dje.models import DejacodeUser
124121

125122
logger.info(
126-
f"Entering scancodeio_submit_manifest_inspection task with "
123+
f"Entering scancodeio_submit_load_sbom task with "
127124
f"scancodeproject_uuid={scancodeproject_uuid} user_uuid={user_uuid}"
128125
)
129126

@@ -140,24 +137,24 @@ def scancodeio_submit_manifest_inspection(scancodeproject_uuid, user_uuid):
140137
# Create a Project instance on ScanCode.io without immediate execution of the
141138
# pipeline. This allows to get instant feedback from ScanCode.io about the Project
142139
# creation status and its related data, even in SYNC mode.
143-
response = scancodeio.submit_manifest_inspection(
140+
response = scancodeio.submit_load_sbom(
144141
project_name=scancodeproject_uuid,
145142
file_location=scancode_project.input_file.path,
146143
user_uuid=user_uuid,
147144
execute_now=False,
148145
)
149146

150147
if not response:
151-
logger.info("Error submitting the manifest to ScanCode.io server")
148+
logger.info("Error submitting the SBOM file to ScanCode.io server")
152149
scancode_project.status = ScanCodeProject.Status.FAILURE
153-
msg = "- Error: Manifest could not be submitted to ScanCode.io"
150+
msg = "- Error: SBOM could not be submitted to ScanCode.io"
154151
scancode_project.append_to_log(msg, save=True)
155152
return
156153

157154
logger.info("Update the ScanCodeProject instance")
158155
scancode_project.status = ScanCodeProject.Status.SUBMITTED
159156
scancode_project.project_uuid = response.get("uuid")
160-
msg = "- Manifest submitted to ScanCode.io for inspection"
157+
msg = "- SBOM file submitted to ScanCode.io for inspection"
161158
scancode_project.append_to_log(msg, save=True)
162159

163160
# Delay the execution of the pipeline after the ScancodeProject instance was
@@ -192,8 +189,8 @@ def pull_project_data_from_scancodeio(scancodeproject_uuid):
192189
status=ScanCodeProject.Status.IMPORT_STARTED
193190
)
194191

195-
if scancode_project.type == scancode_project.ProjectType.IMPORT_FROM_MANIFEST:
196-
notification_verb = "Import packages from manifest"
192+
if scancode_project.type == scancode_project.ProjectType.LOAD_SBOMS:
193+
notification_verb = "Load Packages from SBOMs"
197194
else:
198195
notification_verb = "Import packages from ScanCode.io"
199196

docs/tutorial-1.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ you can refer to :ref:`data_model_product` for details about each fields.
1919

2020
.. note:: You are ready to assign Inventory objects to your Product!
2121

22-
Import a Software Bill of Materials (SBOM) to your Product
23-
==========================================================
22+
Load a Software Bill of Materials (SBOM) to your Product
23+
========================================================
2424

25-
You have the flexibility to employ either your CycloneDX or SPDX
25+
You have the flexibility to employ either your CycloneDX, SPDX, or AboutFile
2626
Software Bill of Materials (SBOMs).
2727

2828
Alternatively, you can conveniently download one of the provided examples from
2929
the following
3030
`GitHub repository <https://github.com/nexB/dejacode/tree/main/docs/sboms/>`_.
3131

3232
On the Product details page, from the :guilabel:`Scan` dropdown, select
33-
:guilabel:`Import Packages from manifest`:
33+
:guilabel:`Load Packages from SBOMs`:
3434

35-
* Click the :guilabel:`Choose file/Browse` button on the **Manifest file** field.
35+
* Click the :guilabel:`Choose File` button on the **SBOM file or zip archive** field.
3636
* Select your SBOM (.cdx.json or .spdx.json) and click the :guilabel:`Open` button.
3737
* Check the :guilabel:`Update existing packages with discovered packages data` option.
38-
* Click the :guilabel:`Import Packages` button.
38+
* Click the :guilabel:`Load Packages` button.
3939

4040
DejaCode presents the :guilabel:`Imports` tab. Refresh your screen from the browser
4141
to see the status of your import.

product_portfolio/forms.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,9 @@ def helper(self):
561561
return helper
562562

563563

564-
class ImportManifestForm(forms.Form):
564+
class LoadSBOMsForm(forms.Form):
565565
input_file = SmartFileField(
566-
label=_("Manifest file"),
566+
label=_("SBOM file or zip archive"),
567567
required=True,
568568
)
569569
update_existing_packages = forms.BooleanField(
@@ -594,7 +594,7 @@ def helper(self):
594594
helper.form_method = "post"
595595
helper.form_id = "import-manifest-form"
596596
helper.attrs = {"autocomplete": "off"}
597-
helper.add_input(Submit("submit", "Import Packages"))
597+
helper.add_input(Submit("submit", "Load Packages", css_class="btn-success"))
598598
return helper
599599

600600

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Generated by Django 4.2.8 on 2024-02-28 07:28
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("product_portfolio", "0003_alter_scancodeproject_status"),
9+
]
10+
11+
operations = [
12+
migrations.AlterField(
13+
model_name="scancodeproject",
14+
name="type",
15+
field=models.CharField(
16+
choices=[
17+
("IMPORT_FROM_MANIFEST", "Import from Manifest"),
18+
("LOAD_SBOMS", "Load SBOMs"),
19+
("PULL_FROM_SCANCODEIO", "Pull from ScanCode.io"),
20+
],
21+
db_index=True,
22+
help_text="The type of import, for the ProjectType choices.",
23+
max_length=50,
24+
),
25+
),
26+
]

product_portfolio/models.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ def get_license_summary_url(self):
251251
def get_check_package_version_url(self):
252252
return self.get_url("check_package_version")
253253

254-
def get_import_manifest_url(self):
255-
return self.get_url("import_manifest")
254+
def get_load_sboms_url(self):
255+
return self.get_url("load_sboms")
256256

257257
def get_pull_project_data_url(self):
258258
return self.get_url("pull_project_data")
@@ -1119,7 +1119,9 @@ class ScanCodeProject(HistoryFieldsMixin, DataspacedModel):
11191119
"""Wrap a ScanCode.io Project."""
11201120

11211121
class ProjectType(models.TextChoices):
1122+
# This type was replaced by LOAD_SBOMS but is kept for backward compatibility
11221123
IMPORT_FROM_MANIFEST = "IMPORT_FROM_MANIFEST", _("Import from Manifest")
1124+
LOAD_SBOMS = "LOAD_SBOMS", _("Load SBOMs")
11231125
PULL_FROM_SCANCODEIO = "PULL_FROM_SCANCODEIO", _("Pull from ScanCode.io")
11241126

11251127
class Status(models.TextChoices):

product_portfolio/templates/product_portfolio/import_manifest_form.html renamed to product_portfolio/templates/product_portfolio/load_sboms_form.html

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{% load i18n static crispy_forms_tags %}
33
{% load inject_preserved_filters from dje_tags %}
44

5-
{% block page_title %}{% trans "Import Packages from manifest" %}{% endblock %}
5+
{% block page_title %}{% trans "Load Packages from SBOMs" %}{% endblock %}
66

77
{% block content %}
88
<div class="header">
@@ -14,38 +14,50 @@
1414
/ {{ object.get_absolute_link }}
1515
</div>
1616
<h1 class="header-title">
17-
{% trans "Import Packages from manifest" %}
17+
{% trans "Load Packages from SBOMs" %}
1818
</h1>
1919
</div>
2020
</div>
2121
</div>
2222
</div>
2323

24-
<p class="lead">
25-
Import and create Packages from a package manifest, lockfile, and SBOM (SPDX document).
26-
</p>
27-
2824
{% include 'includes/messages_alert.html' %}
2925

30-
<div class="alert alert-primary" role="alert">
31-
When you upload your <strong>Manifest file</strong>, DejaCode will:
32-
<ul class="mb-0 mt-2">
33-
<li><strong>Submit the manifest to ScanCode.io</strong> for scan inspection.</li>
34-
<li><strong>Retrieve discovered packages</strong> identified by ScanCode.io and import those packages in DejaCode.</li>
35-
<li><strong>Assign the packages</strong> to this product.</li>
36-
</ul>
37-
</div>
38-
39-
<div class="alert alert-warning">
26+
<div class="alert alert-success">
4027
<div>
41-
The following manifest types are supported:
42-
<ul class="mb-0 mt-2">
43-
<li>Python <strong>requirements.txt</strong></li>
28+
DejaCode supports the following SBOM formats:
29+
<ul class="mt-2">
4430
<li>CycloneDX BOM as JSON <strong>bom.json</strong> and <strong>.cdx.json</strong></li>
4531
<li>SPDX document as JSON <strong>.spdx.json</strong></li>
4632
<li>AboutCode <strong>.ABOUT</strong> files</li>
4733
</ul>
4834
</div>
35+
<strong>Multiple SBOMs:</strong>
36+
You can provide multiple SBOMs by packaging them into a <strong>zip archive</strong>.
37+
DejaCode will handle and process them accordingly.
38+
</div>
39+
40+
<div class="alert alert-primary" role="alert">
41+
When you upload your <strong>Software Bill of Materials (SBOM) file to DejaCode</strong>,
42+
the following process will occur:
43+
<ul class="mb-0 mt-2">
44+
<li>
45+
<strong>Submission to ScanCode.io</strong>
46+
Your SBOM file will be submitted to ScanCode.io for thorough scan inspection.
47+
</li>
48+
<li>
49+
<strong>Package Discovery</strong>
50+
ScanCode.io will identify and discover packages within your SBOM.
51+
</li>
52+
<li>
53+
<strong>Package Importation</strong>
54+
DejaCode will retrieve the discovered packages from ScanCode.io and import them into its system.
55+
</li>
56+
<li>
57+
<strong>Package Assignment</strong>
58+
The imported packages will be assigned to the corresponding product within DejaCode.
59+
</li>
60+
</ul>
4961
</div>
5062

5163
<div class="row">
@@ -60,7 +72,7 @@ <h1 class="header-title">
6072
<script>
6173
$(document).ready(function () {
6274
$('form#import-manifest-form').on('submit', function () {
63-
NEXB.displayOverlay("Importing Packages from manifest...");
75+
NEXB.displayOverlay("Load Packages from SBOM...");
6476
})
6577
});
6678
</script>

product_portfolio/templates/product_portfolio/product_details.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
{% if has_change_permission %}
3939
<a class="dropdown-item" href="{{ object.get_import_from_scan_url }}"><i class="fas fa-file-upload"></i> {% trans 'Import data from Scan' %}</a>
4040
{% if request.user.dataspace.enable_package_scanning %}
41-
<a class="dropdown-item" href="{{ object.get_import_manifest_url }}"><i class="fas fa-file-upload"></i> {% trans 'Import Packages from manifest' %}</a>
41+
<a class="dropdown-item" href="{{ object.get_load_sboms_url }}"><i class="fas fa-file-upload"></i> {% trans 'Load Packages from SBOMs' %}</a>
4242
{% endif %}
4343
{% if pull_project_data_form %}
4444
<a class="dropdown-item" style="margin-left: -3px;" href="#" data-bs-toggle="modal" data-bs-target="#pull-project-data-modal"><i class="fas fa-cloud-download-alt"></i> {% trans 'Pull ScanCode.io Project data' %}</a>

product_portfolio/templates/product_portfolio/scancodeio_project_status.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<ul class="list-unstyled">
2+
<li><strong>Package count:</strong> {{ scan_data.package_count }}</li>
3+
<li><strong>Resource count:</strong> {{ scan_data.resource_count }}</li>
4+
</ul>
15
{% for run in scan_data.runs %}
26
<ul class="list-unstyled mb-1">
37
<li><strong>Pipeline name:</strong> {{ run.pipeline_name }}</li>

product_portfolio/tests/test_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ def test_product_portfolio_scancode_project_model_can_start_import(self):
731731
scancode_project = ScanCodeProject.objects.create(
732732
product=self.product1,
733733
dataspace=self.product1.dataspace,
734-
type=ScanCodeProject.ProjectType.IMPORT_FROM_MANIFEST,
734+
type=ScanCodeProject.ProjectType.LOAD_SBOMS,
735735
)
736736
self.assertTrue(scancode_project.can_start_import)
737737

0 commit comments

Comments
 (0)