Skip to content

Commit 0c54f35

Browse files
committed
Refactor to PURL qualifier
Signed-off-by: Sampurna Pyne <sampurnapyne1710@gmail.com>
1 parent 84c3f40 commit 0c54f35

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

vulnerabilities/pipelines/v2_importers/tuxcare_importer.py

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

65
from dateutil.parser import parse
76
from packageurl import PackageURL
@@ -39,6 +38,35 @@ def fetch(self) -> Iterable[Mapping]:
3938
def advisories_count(self) -> int:
4039
return len(self.response)
4140

41+
def _create_purl(self, project_name: str, os_name: str) -> PackageURL:
42+
os_mapping = {
43+
"ubuntu": ("deb", "ubuntu"),
44+
"debian": ("deb", "debian"),
45+
"centos": ("rpm", "centos"),
46+
"almalinux": ("rpm", "almalinux"),
47+
"rhel": ("rpm", "redhat"),
48+
"red hat": ("rpm", "redhat"),
49+
"oracle": ("rpm", "oracle"),
50+
"cloudlinux": ("rpm", "cloudlinux"),
51+
"alpine": ("apk", "alpine"),
52+
}
53+
54+
qualifiers = {}
55+
if os_name:
56+
qualifiers["os"] = os_name
57+
58+
if not os_name:
59+
return PackageURL(type="generic", name=project_name)
60+
61+
os_lower = os_name.lower()
62+
for keyword, (pkg_type, namespace) in os_mapping.items():
63+
if keyword in os_lower:
64+
return PackageURL(
65+
type=pkg_type, namespace=namespace, name=project_name, qualifiers=qualifiers
66+
)
67+
68+
return PackageURL(type="generic", name=project_name, qualifiers=qualifiers)
69+
4270
def collect_advisories(self) -> Iterable[AdvisoryData]:
4371
for record in self.response:
4472
cve_id = record.get("cve", "").strip()
@@ -62,7 +90,7 @@ def collect_advisories(self) -> Iterable[AdvisoryData]:
6290

6391
affected_packages = []
6492
if project_name:
65-
purl = PackageURL(type="generic", name=project_name)
93+
purl = self._create_purl(project_name, os_name)
6694

6795
affected_version_range = None
6896
if version:

vulnerabilities/tests/test_data/tuxcare/expected.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"summary": "TuxCare advisory for CVE-2023-52922 in squid on CloudLinux 7 ELS",
66
"affected_packages": [
77
{
8-
"package": {"type": "generic", "namespace": "", "name": "squid", "version": "", "qualifiers": "", "subpath": ""},
8+
"package": {"type": "rpm", "namespace": "cloudlinux", "name": "squid", "version": "", "qualifiers": "os=CloudLinux%207%20ELS", "subpath": ""},
99
"affected_version_range": "vers:generic/3.5.20",
1010
"fixed_version_range": null,
1111
"introduced_by_commit_patches": [],
@@ -25,7 +25,7 @@
2525
"summary": "TuxCare advisory for CVE-2023-52922 in squid on Oracle Linux 7 ELS",
2626
"affected_packages": [
2727
{
28-
"package": {"type": "generic", "namespace": "", "name": "squid", "version": "", "qualifiers": "", "subpath": ""},
28+
"package": {"type": "rpm", "namespace": "oracle", "name": "squid", "version": "", "qualifiers": "os=Oracle%20Linux%207%20ELS", "subpath": ""},
2929
"affected_version_range": "vers:generic/3.5.20",
3030
"fixed_version_range": null,
3131
"introduced_by_commit_patches": [],
@@ -45,7 +45,7 @@
4545
"summary": "TuxCare advisory for CVE-2023-48161 in java-11-openjdk on RHEL 7 ELS",
4646
"affected_packages": [
4747
{
48-
"package": {"type": "generic", "namespace": "", "name": "java-11-openjdk", "version": "", "qualifiers": "", "subpath": ""},
48+
"package": {"type": "rpm", "namespace": "redhat", "name": "java-11-openjdk", "version": "", "qualifiers": "os=RHEL%207%20ELS", "subpath": ""},
4949
"affected_version_range": "vers:generic/11.0.23",
5050
"fixed_version_range": null,
5151
"introduced_by_commit_patches": [],
@@ -65,7 +65,7 @@
6565
"summary": "TuxCare advisory for CVE-2024-21147 in java-11-openjdk on RHEL 7 ELS",
6666
"affected_packages": [
6767
{
68-
"package": {"type": "generic", "namespace": "", "name": "java-11-openjdk", "version": "", "qualifiers": "", "subpath": ""},
68+
"package": {"type": "rpm", "namespace": "redhat", "name": "java-11-openjdk", "version": "", "qualifiers": "os=RHEL%207%20ELS", "subpath": ""},
6969
"affected_version_range": "vers:generic/11.0.23",
7070
"fixed_version_range": null,
7171
"introduced_by_commit_patches": [],
@@ -85,7 +85,7 @@
8585
"summary": "TuxCare advisory for CVE-2025-21587 in java-11-openjdk on RHEL 7 ELS",
8686
"affected_packages": [
8787
{
88-
"package": {"type": "generic", "namespace": "", "name": "java-11-openjdk", "version": "", "qualifiers": "", "subpath": ""},
88+
"package": {"type": "rpm", "namespace": "redhat", "name": "java-11-openjdk", "version": "", "qualifiers": "os=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)