Skip to content

Commit 663d5fd

Browse files
committed
Refactor PURL and fix type-hinting
Signed-off-by: Sampurna Pyne <sampurnapyne1710@gmail.com>
1 parent 0a8456a commit 663d5fd

File tree

2 files changed

+15
-43
lines changed

2 files changed

+15
-43
lines changed

vulnerabilities/pipelines/v2_importers/tuxcare_importer.py

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
22
import logging
33
from typing import Iterable
4-
from typing import Mapping
54

65
from dateutil.parser import parse
76
from packageurl import PackageURL
@@ -30,7 +29,7 @@ def steps(cls):
3029
cls.collect_and_store_advisories,
3130
)
3231

33-
def fetch(self) -> Iterable[Mapping]:
32+
def fetch(self) -> None:
3433
url = "https://cve.tuxcare.com/els/download-json?orderBy=updated-desc"
3534
self.log(f"Fetching `{url}`")
3635
response = fetch_response(url)
@@ -40,33 +39,13 @@ def advisories_count(self) -> int:
4039
return len(self.response)
4140

4241
def _create_purl(self, project_name: str, os_name: str) -> PackageURL:
43-
os_mapping = {
44-
"ubuntu": ("deb", "ubuntu"),
45-
"debian": ("deb", "debian"),
46-
"centos": ("rpm", "centos"),
47-
"almalinux": ("rpm", "almalinux"),
48-
"rhel": ("rpm", "redhat"),
49-
"red hat": ("rpm", "redhat"),
50-
"oracle": ("rpm", "oracle"),
51-
"cloudlinux": ("rpm", "cloudlinux"),
52-
"alpine": ("apk", "alpine"),
53-
}
54-
5542
qualifiers = {}
5643
if os_name:
57-
qualifiers["os"] = os_name
58-
59-
if not os_name:
60-
return PackageURL(type="generic", name=project_name)
61-
62-
os_lower = os_name.lower()
63-
for keyword, (pkg_type, namespace) in os_mapping.items():
64-
if keyword in os_lower:
65-
return PackageURL(
66-
type=pkg_type, namespace=namespace, name=project_name, qualifiers=qualifiers
67-
)
44+
qualifiers["distro"] = os_name
6845

69-
return PackageURL(type="generic", name=project_name, qualifiers=qualifiers)
46+
return PackageURL(
47+
type="generic", namespace="tuxcare", name=project_name, qualifiers=qualifiers
48+
)
7049

7150
def collect_advisories(self) -> Iterable[AdvisoryData]:
7251
for record in self.response:
@@ -83,12 +62,6 @@ def collect_advisories(self) -> Iterable[AdvisoryData]:
8362

8463
advisory_id = cve_id
8564

86-
summary = f"TuxCare advisory for {cve_id}"
87-
if project_name:
88-
summary += f" in {project_name}"
89-
if os_name:
90-
summary += f" on {os_name}"
91-
9265
affected_packages = []
9366
if project_name:
9467
purl = self._create_purl(project_name, os_name)
@@ -126,7 +99,6 @@ def collect_advisories(self) -> Iterable[AdvisoryData]:
12699

127100
yield AdvisoryData(
128101
advisory_id=advisory_id,
129-
summary=summary,
130102
affected_packages=affected_packages,
131103
severities=severities,
132104
date_published=date_published,

vulnerabilities/tests/test_data/tuxcare/expected.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
{
33
"advisory_id": "CVE-2023-52922",
44
"aliases": [],
5-
"summary": "TuxCare advisory for CVE-2023-52922 in squid on CloudLinux 7 ELS",
5+
"summary": "",
66
"affected_packages": [
77
{
8-
"package": {"type": "rpm", "namespace": "cloudlinux", "name": "squid", "version": "", "qualifiers": "os=CloudLinux%207%20ELS", "subpath": ""},
8+
"package": {"type": "generic", "namespace": "tuxcare", "name": "squid", "version": "", "qualifiers": "distro=CloudLinux%207%20ELS", "subpath": ""},
99
"affected_version_range": "vers:generic/3.5.20",
1010
"fixed_version_range": null,
1111
"introduced_by_commit_patches": [],
@@ -22,10 +22,10 @@
2222
{
2323
"advisory_id": "CVE-2023-52922",
2424
"aliases": [],
25-
"summary": "TuxCare advisory for CVE-2023-52922 in squid on Oracle Linux 7 ELS",
25+
"summary": "",
2626
"affected_packages": [
2727
{
28-
"package": {"type": "rpm", "namespace": "oracle", "name": "squid", "version": "", "qualifiers": "os=Oracle%20Linux%207%20ELS", "subpath": ""},
28+
"package": {"type": "generic", "namespace": "tuxcare", "name": "squid", "version": "", "qualifiers": "distro=Oracle%20Linux%207%20ELS", "subpath": ""},
2929
"affected_version_range": "vers:generic/3.5.20",
3030
"fixed_version_range": null,
3131
"introduced_by_commit_patches": [],
@@ -42,10 +42,10 @@
4242
{
4343
"advisory_id": "CVE-2023-48161",
4444
"aliases": [],
45-
"summary": "TuxCare advisory for CVE-2023-48161 in java-11-openjdk on RHEL 7 ELS",
45+
"summary": "",
4646
"affected_packages": [
4747
{
48-
"package": {"type": "rpm", "namespace": "redhat", "name": "java-11-openjdk", "version": "", "qualifiers": "os=RHEL%207%20ELS", "subpath": ""},
48+
"package": {"type": "generic", "namespace": "tuxcare", "name": "java-11-openjdk", "version": "", "qualifiers": "distro=RHEL%207%20ELS", "subpath": ""},
4949
"affected_version_range": "vers:generic/11.0.23",
5050
"fixed_version_range": null,
5151
"introduced_by_commit_patches": [],
@@ -62,10 +62,10 @@
6262
{
6363
"advisory_id": "CVE-2024-21147",
6464
"aliases": [],
65-
"summary": "TuxCare advisory for CVE-2024-21147 in java-11-openjdk on RHEL 7 ELS",
65+
"summary": "",
6666
"affected_packages": [
6767
{
68-
"package": {"type": "rpm", "namespace": "redhat", "name": "java-11-openjdk", "version": "", "qualifiers": "os=RHEL%207%20ELS", "subpath": ""},
68+
"package": {"type": "generic", "namespace": "tuxcare", "name": "java-11-openjdk", "version": "", "qualifiers": "distro=RHEL%207%20ELS", "subpath": ""},
6969
"affected_version_range": "vers:generic/11.0.23",
7070
"fixed_version_range": null,
7171
"introduced_by_commit_patches": [],
@@ -82,10 +82,10 @@
8282
{
8383
"advisory_id": "CVE-2025-21587",
8484
"aliases": [],
85-
"summary": "TuxCare advisory for CVE-2025-21587 in java-11-openjdk on RHEL 7 ELS",
85+
"summary": "",
8686
"affected_packages": [
8787
{
88-
"package": {"type": "rpm", "namespace": "redhat", "name": "java-11-openjdk", "version": "", "qualifiers": "os=RHEL%207%20ELS", "subpath": ""},
88+
"package": {"type": "generic", "namespace": "tuxcare", "name": "java-11-openjdk", "version": "", "qualifiers": "distro=RHEL%207%20ELS", "subpath": ""},
8989
"affected_version_range": "vers:generic/11.0.23",
9090
"fixed_version_range": null,
9191
"introduced_by_commit_patches": [],

0 commit comments

Comments
 (0)