Skip to content

Commit c6647c9

Browse files
committed
Create almalinux importer pipeline
Signed-off-by: ambuj <kulshreshthaak.12@gmail.com>
1 parent 6f9c21b commit c6647c9

File tree

7 files changed

+93
-254
lines changed

7 files changed

+93
-254
lines changed

vulnerabilities/importers/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# See https://aboutcode.org for more information about nexB OSS projects.
88
#
99

10-
from vulnerabilities.importers import almalinux
1110
from vulnerabilities.importers import alpine_linux
1211
from vulnerabilities.importers import apache_httpd
1312
from vulnerabilities.importers import apache_kafka
@@ -36,6 +35,7 @@
3635
from vulnerabilities.importers import vulnrichment
3736
from vulnerabilities.importers import xen
3837
from vulnerabilities.pipelines import VulnerableCodeBaseImporterPipeline
38+
from vulnerabilities.pipelines import almalinux_importer
3939
from vulnerabilities.pipelines import github_importer
4040
from vulnerabilities.pipelines import gitlab_importer
4141
from vulnerabilities.pipelines import nginx_importer
@@ -69,7 +69,6 @@
6969
oss_fuzz.OSSFuzzImporter,
7070
ruby.RubyImporter,
7171
github_osv.GithubOSVImporter,
72-
almalinux.AlmaImporter,
7372
curl.CurlImporter,
7473
epss.EPSSImporter,
7574
vulnrichment.VulnrichImporter,
@@ -80,6 +79,7 @@
8079
github_importer.GitHubAPIImporterPipeline,
8180
nvd_importer.NVDImporterPipeline,
8281
pysec_importer.PyPIImporterPipeline,
82+
almalinux_importer.AlmalinuxImporterPipeline,
8383
]
8484

8585
IMPORTERS_REGISTRY = {

vulnerabilities/importers/almalinux.py

Lines changed: 0 additions & 237 deletions
This file was deleted.

vulnerabilities/importers/osv.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
"go": "golang",
4242
"hex": "hex",
4343
"cargo": "cargo",
44+
"almalinux:8": "rpm",
45+
"almalinux:9": "rpm",
4446
}
4547

4648

@@ -213,6 +215,8 @@ def get_affected_purl(affected_pkg, raw_id):
213215
namespace = ""
214216
if purl_type == "maven":
215217
namespace, _, name = name.partition(":")
218+
if ecosys == "almalinux:8" or ecosys == "almalinux:9":
219+
namespace = "almalinux"
216220

217221
purl = PackageURL(type=purl_type, namespace=namespace, name=name)
218222
else:

vulnerabilities/improvers/valid_versions.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from vulnerabilities.importer import AffectedPackage
2525
from vulnerabilities.importer import Importer
2626
from vulnerabilities.importer import UnMergeablePackageError
27-
from vulnerabilities.importers.almalinux import AlmaImporter
2827
from vulnerabilities.importers.apache_httpd import ApacheHTTPDImporter
2928
from vulnerabilities.importers.apache_kafka import ApacheKafkaImporter
3029
from vulnerabilities.importers.apache_tomcat import ApacheTomcatImporter
@@ -42,6 +41,7 @@
4241
from vulnerabilities.improver import Inference
4342
from vulnerabilities.models import Advisory
4443
from vulnerabilities.pipelines import VulnerableCodeBaseImporterPipeline
44+
from vulnerabilities.pipelines.almalinux_importer import AlmalinuxImporterPipeline
4545
from vulnerabilities.pipelines.github_importer import GitHubAPIImporterPipeline
4646
from vulnerabilities.pipelines.gitlab_importer import GitLabImporterPipeline
4747
from vulnerabilities.pipelines.nginx_importer import NginxImporterPipeline
@@ -477,10 +477,13 @@ class RubyImprover(ValidVersionImprover):
477477
class GithubOSVImprover(ValidVersionImprover):
478478
importer = GithubOSVImporter
479479
ignorable_versions = []
480-
480+
481+
481482
class AlmaImprover(ValidVersionImprover):
482-
importer = AlmaImporter
483-
483+
importer = AlmalinuxImporterPipeline
484+
ignorable_versions = []
485+
486+
484487
class CurlImprover(ValidVersionImprover):
485488
importer = CurlImporter
486489
ignorable_versions = []
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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/aboutcode-org/vulnerablecode for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
8+
#
9+
import json
10+
import logging
11+
from pathlib import Path
12+
from typing import Iterable
13+
14+
from fetchcode.vcs import fetch_via_vcs
15+
16+
from vulnerabilities.importer import AdvisoryData
17+
from vulnerabilities.importers.osv import parse_advisory_data
18+
from vulnerabilities.pipelines import VulnerableCodeBaseImporterPipeline
19+
from vulnerabilities.utils import get_advisory_url
20+
21+
logger = logging.getLogger(__name__)
22+
23+
24+
class AlmalinuxImporterPipeline(VulnerableCodeBaseImporterPipeline):
25+
"""Collect Almalinux advisories."""
26+
27+
pipeline_id = "almalinux_importer"
28+
spdx_license_expression = "MIT"
29+
license_url = "https://github.com/AlmaLinux/osv-database/blob/master/LICENSE"
30+
importer_name = "Almalinux Importer"
31+
repo_url = "https://github.com/AlmaLinux/osv-database"
32+
33+
@classmethod
34+
def steps(cls):
35+
return (
36+
cls.clone,
37+
cls.collect_and_store_advisories,
38+
cls.import_new_advisories,
39+
cls.clean_downloads,
40+
)
41+
42+
def clone(self):
43+
self.log(f"Cloning `{self.repo_url}")
44+
self.vcs_response = fetch_via_vcs(self.repo_url)
45+
46+
def advisories_count(self):
47+
vuln_directory = Path(self.vcs_response.dest_dir) / "tree" / "master" / "advisories"
48+
return sum(1 for _ in vuln_directory.rglob("*.json"))
49+
50+
def collect_advisories(self) -> Iterable[AdvisoryData]:
51+
base_path = Path(self.vcs_response.dest_dir)
52+
vuln_directory = base_path / "tree" / "master" / "advisories"
53+
for file in vuln_directory.rglob("*.json"):
54+
advisory_url = get_advisory_url(
55+
file=file,
56+
base_path=base_path,
57+
url="https://github.com/AlmaLinux/osv-database/blob/master",
58+
)
59+
with open(file) as f:
60+
raw_data = json.load(f)
61+
yield parse_advisory_data(
62+
raw_data=raw_data, supported_ecosystems="rpm", advisory_url=advisory_url
63+
)
64+
65+
def clean_downloads(self):
66+
if self.vcs_response:
67+
self.log(f"Removing cloned repository")
68+
self.vcs_response.delete()

0 commit comments

Comments
 (0)