Skip to content

Commit 1e3afdc

Browse files
authored
Merge pull request #1533 from aboutcode-org/917-ghost-remover
Add improver pipeline to flag ghost packages #644 #917 #1395
2 parents cf592ed + 0f41b18 commit 1e3afdc

File tree

15 files changed

+325
-3
lines changed

15 files changed

+325
-3
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
max-parallel: 4
1111
matrix:
12-
python-version: [3.8]
12+
python-version: [3.9]
1313

1414
steps:
1515
- name: Checkout code

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
strategy:
3030
max-parallel: 4
3131
matrix:
32-
python-version: ["3.8", "3.9", "3.10"]
32+
python-version: ["3.9", "3.10", "3.11"]
3333

3434
steps:
3535
- name: Checkout code

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Release notes
22
=============
33

4+
Version (next)
5+
-------------------
6+
7+
- Add Pipeline to flag ghost packages (#1533)
8+
- Add logging configuration (#1533)
9+
- Drop support for python 3.8 (#1533)
10+
11+
412
Version v34.0.0
513
-------------------
614

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
aboutcode.pipeline==0.1.0
12
aiosignal==1.2.0
23
alabaster==0.7.12
34
asgiref==3.5.2
@@ -10,6 +11,7 @@ bcrypt==3.2.0
1011
beautifulsoup4==4.10.0
1112
binaryornot==0.4.4
1213
black==22.3.0
14+
bleach==6.1.0
1315
boolean.py==3.8
1416
certifi==2024.7.4
1517
cffi==1.15.0
@@ -49,6 +51,7 @@ jsonschema==3.2.0
4951
license-expression==21.6.14
5052
lxml==4.9.1
5153
Markdown==3.3.4
54+
markdown-it-py==3.0.0
5255
MarkupSafe==2.1.1
5356
matplotlib-inline==0.1.3
5457
multidict==6.0.2

setup.cfg

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ license_files =
4848
README.rst
4949

5050
[options]
51-
python_requires = >=3.8
51+
python_requires = >=3.9
5252

5353
packages=find:
5454
include_package_data = true
@@ -92,6 +92,9 @@ install_requires =
9292
requests>=2.25.1
9393
fetchcode>=0.3.0
9494

95+
#pipeline
96+
aboutcode.pipeline>=0.1.0
97+
9598
#vulntotal
9699
python-dotenv
97100
texttable

vulnerabilities/improvers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from vulnerabilities.improvers import valid_versions
1111
from vulnerabilities.improvers import vulnerability_kev
1212
from vulnerabilities.improvers import vulnerability_status
13+
from vulnerabilities.pipelines import flag_ghost_packages
1314

1415
IMPROVERS_REGISTRY = [
1516
valid_versions.GitHubBasicImprover,
@@ -29,6 +30,7 @@
2930
valid_versions.GithubOSVImprover,
3031
vulnerability_status.VulnerabilityStatusImprover,
3132
vulnerability_kev.VulnerabilityKevImprover,
33+
flag_ghost_packages.FlagGhostPackagePipeline,
3234
]
3335

3436
IMPROVERS_REGISTRY = {x.qualified_name: x for x in IMPROVERS_REGISTRY}

vulnerabilities/management/commands/improve.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from vulnerabilities.improve_runner import ImproveRunner
1616
from vulnerabilities.improvers import IMPROVERS_REGISTRY
17+
from vulnerabilities.pipelines import VulnerableCodePipeline
1718

1819

1920
class Command(BaseCommand):
@@ -56,6 +57,13 @@ def improve_data(self, improvers):
5657

5758
for improver in improvers:
5859
self.stdout.write(f"Improving data using {improver.qualified_name}")
60+
if issubclass(improver, VulnerableCodePipeline):
61+
status, error = improver().execute()
62+
if status != 0:
63+
self.stdout.write(error)
64+
failed_improvers.append(improver.qualified_name)
65+
continue
66+
5967
try:
6068
ImproveRunner(improver_class=improver).run()
6169
self.stdout.write(
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Generated by Django 4.1.13 on 2024-08-23 12:47
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("vulnerabilities", "0061_alter_packagechangelog_software_version_and_more"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name="package",
15+
name="is_ghost",
16+
field=models.BooleanField(
17+
default=False,
18+
help_text="True if the package does not exist in the upstream package manager or its repository.",
19+
),
20+
),
21+
]

vulnerabilities/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,11 @@ class Package(PackageURLMixin):
610610
db_index=True,
611611
)
612612

613+
is_ghost = models.BooleanField(
614+
default=False,
615+
help_text="True if the package does not exist in the upstream package manager or its repository.",
616+
)
617+
613618
objects = PackageQuerySet.as_manager()
614619

615620
def save(self, *args, **kwargs):
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# VulnerableCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/nexB/vulnerablecode for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
8+
#
9+
import logging
10+
from datetime import datetime
11+
from datetime import timezone
12+
13+
from aboutcode.pipeline import BasePipeline
14+
15+
from vulnerabilities.utils import classproperty
16+
17+
module_logger = logging.getLogger(__name__)
18+
19+
20+
class VulnerableCodePipeline(BasePipeline):
21+
def log(self, message, level=logging.INFO):
22+
"""Log the given `message` to the current module logger and execution_log."""
23+
now_local = datetime.now(timezone.utc).astimezone()
24+
timestamp = now_local.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
25+
message = f"{timestamp} {message}"
26+
module_logger.log(level, message)
27+
self.append_to_log(message)
28+
29+
@classproperty
30+
def qualified_name(cls):
31+
"""
32+
Fully qualified name prefixed with the module name of the pipeline used in logging.
33+
"""
34+
return f"{cls.__module__}.{cls.__qualname__}"

0 commit comments

Comments
 (0)