Skip to content

Commit 80eb6a6

Browse files
committed
Refcator and add docstring to fetch method
Signed-off-by: Sampurna Pyne <sampurnapyne1710@gmail.com>
1 parent 4f6d2c7 commit 80eb6a6

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

vulnerabilities/pipelines/v2_importers/vmware_photon_importer_v2.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,20 @@ def steps(cls):
5353
)
5454

5555
def fetch(self):
56+
"""
57+
Fetches all JSON files from the repository index and extracts records. Each record is enriched with the source URL(contains the photon version) for traceability.
58+
"""
5659
self.records = []
57-
base_url = self.repo_url
58-
59-
response = fetch_response(base_url)
60+
response = fetch_response(self.repo_url)
6061
photon_files = re.findall(r'href="(cve_data_photon[0-9.]+\.json)"', response.text)
6162

6263
for file_name in photon_files:
63-
url = base_url + file_name
64-
self.log(f"Fetching `{url}`")
65-
response = fetch_response(url)
66-
if response:
67-
for record in response.json():
68-
record["source_url"] = url
69-
self.records.append(record)
64+
source_url = self.repo_url + file_name
65+
self.log(f"Fetching `{source_url}`")
66+
response = fetch_response(source_url)
67+
for record in response.json():
68+
record["source_url"] = source_url
69+
self.records.append(record)
7070
self.log(f"Fetched {len(self.records):,d} total records from {len(photon_files)} sources")
7171

7272
def group_records_by_cve(self):
@@ -113,11 +113,16 @@ def collect_advisories(self) -> Iterable[AdvisoryDataV2]:
113113

114114
ver_match = re.match(r"all versions before (.+) are vulnerable", aff_ver)
115115

116+
if not ver_match:
117+
self.log(f"Could not extract affected version from aff_ver: {aff_ver!r}")
118+
continue
119+
120+
aff_ver = ver_match.group(1)
116121
affected_version_range = RpmVersionRange(
117122
constraints=[
118123
VersionConstraint(
119124
comparator="<",
120-
version=RpmVersion(ver_match.group(1)),
125+
version=RpmVersion(aff_ver),
121126
)
122127
]
123128
)

0 commit comments

Comments
 (0)