77# See https://aboutcode.org for more information about nexB OSS projects.
88#
99
10- import asyncio
11-
12- # to test json print
13- import json
1410
1511import requests
1612from bs4 import BeautifulSoup
1713from packageurl import PackageURL
18-
19- # import VersionConstraint to experiment
2014from univers .version_constraint import VersionConstraint
2115from univers .version_range import MavenVersionRange
2216from univers .versions import MavenVersion
2519from vulnerabilities .importer import AffectedPackage
2620from vulnerabilities .importer import Importer
2721from vulnerabilities .importer import Reference
28- from vulnerabilities .package_managers import GitHubTagsAPI
2922
23+ # The entries below with `"action": "omit"` have no useful/reportable fixed or affected version data.
24+ # See https://kafka.apache.org/cve-list
3025affected_version_range_mapping = {
3126 "CVE-2022-34917" : {
3227 "action" : "include" ,
@@ -97,15 +92,8 @@ def fetch_advisory_page(self):
9792 page = requests .get (self .GH_PAGE_URL )
9893 return page .content
9994
100- # For now, don't use the GH API
101- # def set_api(self):
102- # self.version_api = GitHubTagsAPI()
103- # asyncio.run(self.version_api.load_api(["apache/kafka"]))
104-
10595 def updated_advisories (self ):
10696 advisory_page = self .fetch_advisory_page ()
107- # For now, don't use the GH API
108- # self.set_api()
10997
11098 parsed_data = self .to_advisory (advisory_page )
11199 return self .batch_advisories (parsed_data )
@@ -155,8 +143,6 @@ def to_advisory(self, advisory_page):
155143 # hard-coded affected_version_range_mapping dictionary.
156144 if affected_version_range_mapping [cve_id ]["action" ] == "include" :
157145
158- # print("\ncve_id = {}".format(cve_id))
159-
160146 # These 2 variables (not used elsewhere) trigger the KeyError for changed/missing data.
161147 check_affected_versions_key = affected_version_range_mapping [cve_id ][
162148 affected_versions_string
@@ -165,15 +151,6 @@ def to_advisory(self, advisory_page):
165151 fixed_versions_string
166152 ]
167153
168- # This calculates/prints the correct univers version value, which we can then use in the mapping dictionary.
169- # We'll delete this and to_version_ranges_test() when no longer needed.
170- affected_version_ranges_TEST = self .to_version_ranges_test (
171- affected_versions_string_split_SPLIT , fixed_versions_string_split_SPLIT
172- )
173- # print("\naffected_version_ranges_TEST = {}".format(affected_version_ranges_TEST))
174- # print("\naffected_versions_string = {}".format(affected_versions_string))
175- # print("\nfixed_versions_string = {}".format(fixed_versions_string))
176-
177154 references = [
178155 Reference (url = self .ASF_PAGE_URL ),
179156 Reference (
@@ -203,127 +180,4 @@ def to_advisory(self, advisory_page):
203180 )
204181 )
205182
206- # print("\nadvisories[-1] = {}".format(advisories[-1]))
207- # print("\nadvisories[-1].to_dict() = {}".format(advisories[-1].to_dict()))
208-
209- # print("\n========================================")
210-
211- # Print a dict of the advisories.
212- # result = [data.to_dict() for data in advisories]
213- # print("result = \n")
214- # print(json.dumps(result, indent=4, sort_keys=False))
215-
216183 return advisories
217-
218- # We use this to calculate the ranges for the hard-coded affected_version_range_mapping.
219- # We'' delete this when no longer needed.
220- def to_version_ranges_test (self , versions_data , fixed_versions ):
221- constraints = []
222-
223- for version_item in versions_data :
224- if "to" in version_item :
225- version_item_split = version_item .split (" " )
226-
227- constraints .append (
228- VersionConstraint (
229- comparator = ">=" ,
230- version = MavenVersion (version_item_split [0 ]),
231- )
232- )
233- constraints .append (
234- VersionConstraint (
235- comparator = "<=" ,
236- version = MavenVersion (version_item_split [- 1 ]),
237- )
238- )
239-
240- elif "-" in version_item :
241- version_item_split = version_item .split (" " )
242-
243- constraints .append (
244- VersionConstraint (
245- comparator = ">=" ,
246- version = MavenVersion (version_item_split [0 ]),
247- )
248- )
249- constraints .append (
250- VersionConstraint (
251- comparator = "<=" ,
252- version = MavenVersion (version_item_split [- 1 ]),
253- )
254- )
255-
256- elif "and later" in version_item :
257- version_item_split = version_item .split (" " )
258-
259- constraints .append (
260- VersionConstraint (
261- comparator = ">=" ,
262- version = MavenVersion (version_item_split [0 ]),
263- )
264- )
265-
266- else :
267- version_item_split = version_item .split (" " )
268-
269- constraints .append (
270- VersionConstraint (
271- comparator = "=" ,
272- version = MavenVersion (version_item_split [0 ]),
273- )
274- )
275-
276- for fixed_item in fixed_versions :
277- if "to" in fixed_item :
278- fixed_item_split = fixed_item .split (" " )
279-
280- constraints .append (
281- VersionConstraint (
282- comparator = ">=" ,
283- version = MavenVersion (fixed_item_split [0 ]),
284- ).invert ()
285- )
286- constraints .append (
287- VersionConstraint (
288- comparator = "<=" ,
289- version = MavenVersion (fixed_item_split [- 1 ]),
290- ).invert ()
291- )
292-
293- elif "-" in fixed_item :
294- fixed_item_split = fixed_item .split (" " )
295-
296- constraints .append (
297- VersionConstraint (
298- comparator = ">=" ,
299- version = MavenVersion (fixed_item_split [0 ]),
300- ).invert ()
301- )
302- constraints .append (
303- VersionConstraint (
304- comparator = "<=" ,
305- version = MavenVersion (fixed_item_split [- 1 ]),
306- ).invert ()
307- )
308-
309- elif "and later" in fixed_item :
310- fixed_item_split = fixed_item .split (" " )
311-
312- constraints .append (
313- VersionConstraint (
314- comparator = ">=" ,
315- version = MavenVersion (fixed_item_split [0 ]),
316- ).invert ()
317- )
318-
319- else :
320- fixed_item_split = fixed_item .split (" " )
321-
322- constraints .append (
323- VersionConstraint (
324- comparator = "=" ,
325- version = MavenVersion (fixed_item_split [0 ]),
326- ).invert ()
327- )
328-
329- return MavenVersionRange (constraints = constraints )
0 commit comments