Skip to content

Commit 4c1483a

Browse files
committed
Merge branch 'main' of nexB/scancode.io into lf32-licensetext-devel
2 parents d5c4018 + 2d342fa commit 4c1483a

16 files changed

+163
-82
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 4.0.5 on 2022-06-17 06:58
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('scanpipe', '0016_discoveredpackage_package_uid'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='discoveredpackage',
15+
name='package_uid',
16+
field=models.CharField(blank=True, db_index=True, help_text='Unique identifier for this package.', max_length=1024),
17+
),
18+
migrations.AddConstraint(
19+
model_name='discoveredpackage',
20+
constraint=models.UniqueConstraint(condition=models.Q(('package_uid', ''), _negated=True), fields=('project', 'package_uid'), name='scanpipe_discoveredpackage_unique_package_uid_within_project'),
21+
),
22+
]

scanpipe/models.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,7 @@ class DiscoveredPackage(
17291729
package_uid = models.CharField(
17301730
max_length=1024,
17311731
blank=True,
1732+
db_index=True,
17321733
help_text=_("Unique identifier for this package."),
17331734
)
17341735

@@ -1740,6 +1741,13 @@ class DiscoveredPackage(
17401741

17411742
class Meta:
17421743
ordering = ["uuid"]
1744+
constraints = [
1745+
models.UniqueConstraint(
1746+
fields=["project", "package_uid"],
1747+
condition=~Q(package_uid=""),
1748+
name="%(app_label)s_%(class)s_unique_package_uid_within_project",
1749+
),
1750+
]
17431751

17441752
def __str__(self):
17451753
return self.package_url or str(self.uuid)
@@ -1807,7 +1815,7 @@ def create_from_data(cls, project, package_data):
18071815
discovered_package.save(save_error=False, capture_exception=False)
18081816
return discovered_package
18091817

1810-
def update_from_data(self, package_data):
1818+
def update_from_data(self, package_data, override=False):
18111819
"""
18121820
Update this discovered package instance with the provided `package_data`.
18131821
The `save()` is called only if at least one field was modified.
@@ -1825,11 +1833,9 @@ def update_from_data(self, package_data):
18251833
continue
18261834

18271835
current_value = getattr(self, field_name, None)
1828-
if not current_value:
1836+
if not current_value or (current_value != value and override):
18291837
setattr(self, field_name, value)
18301838
updated_fields.append(field_name)
1831-
elif current_value != value:
1832-
pass # TODO: handle this case
18331839

18341840
if updated_fields:
18351841
self.save()

scanpipe/pipes/__init__.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,18 @@ def update_or_create_package(project, package_data, codebase_resource=None):
7474
DiscoveredPackage using its Package URL and package_uid as a unique key.
7575
"""
7676
purl_data = DiscoveredPackage.extract_purl_data(package_data)
77-
package_uid = package_data.get("package_uid")
78-
purl_data_and_package_uid = {
79-
**purl_data,
80-
"package_uid": package_uid,
81-
}
8277

8378
try:
8479
package = DiscoveredPackage.objects.get(
85-
project=project, **purl_data_and_package_uid
80+
project=project,
81+
package_uid=package_data.get("package_uid"),
82+
**purl_data,
8683
)
8784
except DiscoveredPackage.DoesNotExist:
8885
package = None
8986

9087
if package:
9188
package.update_from_data(package_data)
92-
9389
else:
9490
if codebase_resource:
9591
package = codebase_resource.create_and_add_package(package_data)

scanpipe/pipes/docker.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
from pathlib import Path
2626

2727
from container_inspector.image import Image
28+
from container_inspector.utils import extract_tar
2829

2930
from scanpipe import pipes
3031
from scanpipe.pipes import rootfs
31-
from scanpipe.pipes.scancode import extract_archive
3232

3333
logger = logging.getLogger(__name__)
3434

@@ -62,7 +62,7 @@ def extract_image_from_tarball(input_tarball, extract_target, verify=True):
6262
Returns the `images` and an `errors` list of error messages that may have
6363
happen during the extraction.
6464
"""
65-
errors = list(extract_archive(location=input_tarball, target=extract_target))
65+
errors = extract_tar(location=input_tarball, target_dir=extract_target)
6666
images = Image.get_images_from_dir(
6767
extracted_location=str(extract_target),
6868
verify=verify,
@@ -101,9 +101,9 @@ def extract_layers_from_images_to_base_path(base_path, images):
101101

102102
for layer in image.layers:
103103
extract_target = target_path / layer.layer_id
104-
extract_errors = extract_archive(
104+
extract_errors = extract_tar(
105105
location=layer.archive_location,
106-
target=extract_target,
106+
target_dir=extract_target,
107107
)
108108
errors.extend(extract_errors)
109109
layer.extracted_location = str(extract_target)

scanpipe/pipes/scancode.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343

4444
from scanpipe import pipes
4545
from scanpipe.models import CodebaseResource
46-
from scanpipe.models import DiscoveredPackage
4746

4847
logger = logging.getLogger("scanpipe.pipes")
4948

@@ -392,13 +391,14 @@ def create_codebase_resources(project, scanned_codebase):
392391
defaults=resource_data,
393392
)
394393

395-
# Associate DiscoveredPackage to CodebaseResource, if applicable
396-
if hasattr(scanned_resource, "for_packages"):
397-
for package_uid in scanned_resource.for_packages:
398-
package = DiscoveredPackage.objects.get(package_uid=package_uid)
399-
set_codebase_resource_for_package(
400-
codebase_resource=codebase_resource, discovered_package=package
401-
)
394+
for_packages = getattr(scanned_resource, "for_packages", [])
395+
for package_uid in for_packages:
396+
logger.debug(f"Assign {package_uid} to {codebase_resource}")
397+
package = project.discoveredpackages.get(package_uid=package_uid)
398+
set_codebase_resource_for_package(
399+
codebase_resource=codebase_resource,
400+
discovered_package=package,
401+
)
402402

403403

404404
def create_discovered_packages(project, scanned_codebase):

scanpipe/templates/scanpipe/package_list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<tbody>
2828
{% for package in object_list %}
2929
<tr class="break-word">
30-
<td style="min-width: 500px;">
30+
<td style="min-width: 500px;" title="{{ package.package_uid }}">
3131
{{ package.package_url }}
3232
</td>
3333
<td style="min-width: 300px; max-width: 400px;">

scanpipe/tests/data/debian_scan_codebase.json

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,41 @@
123123
"manifest_path": "",
124124
"contains_source_code": null,
125125
"extra_data": {
126-
"multi_arch": "same"
126+
"multi_arch": "same",
127+
"missing_file_references": [
128+
{
129+
"md5": "23c8a935fa4fc7290d55cc5df3ef56b1",
130+
"path": "lib/x86_64-linux-gnu/libncurses.so.5.9",
131+
"sha1": null,
132+
"sha256": null,
133+
"sha512": null,
134+
"extra_data": {}
135+
},
136+
{
137+
"md5": "98b70f283324e89db5787a018a54adf4",
138+
"path": "usr/lib/x86_64-linux-gnu/libform.so.5.9",
139+
"sha1": null,
140+
"sha256": null,
141+
"sha512": null,
142+
"extra_data": {}
143+
},
144+
{
145+
"md5": "e3a0f5154928da2da234920343ac14b2",
146+
"path": "usr/lib/x86_64-linux-gnu/libmenu.so.5.9",
147+
"sha1": null,
148+
"sha256": null,
149+
"sha512": null,
150+
"extra_data": {}
151+
},
152+
{
153+
"md5": "a927e7d76753bb85f5a784b653d337d2",
154+
"path": "usr/lib/x86_64-linux-gnu/libpanel.so.5.9",
155+
"sha1": null,
156+
"sha256": null,
157+
"sha512": null,
158+
"extra_data": {}
159+
}
160+
]
127161
},
128162
"missing_resources": [],
129163
"modified_resources": [],
@@ -161,7 +195,25 @@
161195
"manifest_path": "",
162196
"contains_source_code": null,
163197
"extra_data": {
164-
"multi_arch": "same"
198+
"multi_arch": "same",
199+
"missing_file_references": [
200+
{
201+
"md5": "5d26434efecc08048ab72357af804ef7",
202+
"path": "usr/lib/x86_64-linux-gnu/libndp.so.0.0.2",
203+
"sha1": null,
204+
"sha256": null,
205+
"sha512": null,
206+
"extra_data": {}
207+
},
208+
{
209+
"md5": "60d977e0c9a9fb07c1f8ae3090ea6f48",
210+
"path": "usr/share/doc/libndp0/changelog.Debian.gz",
211+
"sha1": null,
212+
"sha256": null,
213+
"sha512": null,
214+
"extra_data": {}
215+
}
216+
]
165217
},
166218
"missing_resources": [],
167219
"modified_resources": [],
@@ -195,7 +247,6 @@
195247
"extension": "",
196248
"programming_language": "",
197249
"mime_type": "text/plain",
198-
"file_type": "ASCII text",
199250
"is_binary": false,
200251
"is_text": true,
201252
"is_archive": false,
@@ -223,7 +274,6 @@
223274
"extension": "",
224275
"programming_language": "",
225276
"mime_type": "text/plain",
226-
"file_type": "UTF-8 Unicode text",
227277
"is_binary": false,
228278
"is_text": true,
229279
"is_archive": false,
@@ -251,16 +301,17 @@
251301
"extension": "",
252302
"programming_language": "Haxe",
253303
"mime_type": "text/plain",
254-
"file_type": "ASCII text",
255304
"is_binary": false,
256305
"is_text": true,
257306
"is_archive": false,
258307
"is_key_file": false,
259308
"is_media": false
260309
},
261310
{
262-
"for_packages": [],
263-
"path": "debian.tar.gz-extract/8a63761caf6d45e65b8e6cdc2e0c03c55625fd142ec3356b80a9ea4a34b11b66/var/lib/dpkg/info/libncurses5_amd64.md5sums",
311+
"for_packages": [
312+
"pkg:deb/libncurses5@6.1-1ubuntu1.18.04?architecture=amd64&uuid=fixed-uid-done-for-testing-5642512d1758"
313+
],
314+
"path": "debian.tar.gz-extract/8a63761caf6d45e65b8e6cdc2e0c03c55625fd142ec3356b80a9ea4a34b11b66/var/lib/dpkg/info/libncurses5:amd64.md5sums",
264315
"sha1": "e5ff875218d4f909576575b0471feb0e5230a861",
265316
"md5": "9d18792b91935a5849328cb368005ec9",
266317
"extra_data": {},
@@ -271,22 +322,23 @@
271322
"license_expressions": [],
272323
"emails": [],
273324
"urls": [],
274-
"status": "no-licenses",
325+
"status": "system-package",
275326
"type": "file",
276-
"name": "libncurses5_amd64",
327+
"name": "libncurses5:amd64",
277328
"extension": ".md5sums",
278329
"programming_language": "",
279330
"mime_type": "text/plain",
280-
"file_type": "ASCII text",
281331
"is_binary": false,
282332
"is_text": true,
283333
"is_archive": false,
284334
"is_key_file": false,
285335
"is_media": false
286336
},
287337
{
288-
"for_packages": [],
289-
"path": "debian.tar.gz-extract/8a63761caf6d45e65b8e6cdc2e0c03c55625fd142ec3356b80a9ea4a34b11b66/var/lib/dpkg/info/libndp0_amd64.md5sums",
338+
"for_packages": [
339+
"pkg:deb/libndp0@1.4-2ubuntu0.16.04.1?architecture=amd64&uuid=fixed-uid-done-for-testing-5642512d1758"
340+
],
341+
"path": "debian.tar.gz-extract/8a63761caf6d45e65b8e6cdc2e0c03c55625fd142ec3356b80a9ea4a34b11b66/var/lib/dpkg/info/libndp0:amd64.md5sums",
290342
"sha1": "c212d44c6649df5ff13ec447f4fa30faf81fc490",
291343
"md5": "7cb818062922c437df1902c18862455a",
292344
"extra_data": {},
@@ -297,13 +349,12 @@
297349
"license_expressions": [],
298350
"emails": [],
299351
"urls": [],
300-
"status": "no-licenses",
352+
"status": "system-package",
301353
"type": "file",
302-
"name": "libndp0_amd64",
354+
"name": "libndp0:amd64",
303355
"extension": ".md5sums",
304356
"programming_language": "",
305357
"mime_type": "text/plain",
306-
"file_type": "ASCII text",
307358
"is_binary": false,
308359
"is_text": true,
309360
"is_archive": false,
@@ -356,7 +407,6 @@
356407
"extension": "",
357408
"programming_language": "Haxe",
358409
"mime_type": "text/plain",
359-
"file_type": "ASCII text",
360410
"is_binary": false,
361411
"is_text": true,
362412
"is_archive": false,
796 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)