Skip to content

Commit 9dbdf69

Browse files
committed
Fetch Photon CVE data sources dynamically from index
Signed-off-by: Sampurna Pyne <sampurnapyne1710@gmail.com>
1 parent 0f72d7d commit 9dbdf69

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

vulnerabilities/pipelines/v2_importers/vmware_photon_importer_v2.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@
2121
from vulnerabilities.severity_systems import CVSSV3
2222
from vulnerabilities.utils import fetch_response
2323

24-
PHOTON_URLS = [
25-
"https://packages.vmware.com/photon/photon_cve_metadata/cve_data_photon1.0.json",
26-
"https://packages.vmware.com/photon/photon_cve_metadata/cve_data_photon2.0.json",
27-
"https://packages.vmware.com/photon/photon_cve_metadata/cve_data_photon3.0.json",
28-
"https://packages.vmware.com/photon/photon_cve_metadata/cve_data_photon4.0.json",
29-
"https://packages.vmware.com/photon/photon_cve_metadata/cve_data_photon5.0.json",
30-
]
31-
3224

3325
class VmwarePhotonImporterPipeline(VulnerableCodeBaseImporterPipelineV2):
3426
"""Collect advisories from Vmware Photon Advisory.
@@ -60,12 +52,18 @@ def steps(cls):
6052

6153
def fetch(self):
6254
self.records = []
63-
for url in PHOTON_URLS:
55+
base_url = self.repo_url
56+
57+
response = fetch_response(base_url)
58+
photon_files = re.findall(r'href="(cve_data_photon[0-9.]+\.json)"', response.text)
59+
60+
for file_name in photon_files:
61+
url = base_url + file_name
6462
self.log(f"Fetching `{url}`")
6563
response = fetch_response(url)
6664
if response:
6765
self.records.extend(response.json())
68-
self.log(f"Fetched {len(self.records):,d} total records from {len(PHOTON_URLS)} sources")
66+
self.log(f"Fetched {len(self.records):,d} total records from {len(photon_files)} sources")
6967

7068
def group_records_by_cve(self):
7169
"""

vulnerabilities/tests/pipelines/v2_importers/test_vmware_photon_importer_v2.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ def test_collect_advisories(self, mock_fetch):
2727
sample_path = TEST_DATA / "data.json"
2828
sample_data = json.loads(sample_path.read_text(encoding="utf-8"))
2929

30+
index_html = """
31+
<a href="cve_data_photon4.0.json">cve_data_photon4.0.json</a>
32+
"""
33+
3034
def side_effect(url):
31-
if "photon4.0" in url:
35+
if url == "https://packages.vmware.com/photon/photon_cve_metadata/":
36+
return Mock(text=index_html)
37+
if "cve_data_photon4.0.json" in url:
3238
return Mock(json=lambda: sample_data)
3339
return None
3440

0 commit comments

Comments
 (0)