|
21 | 21 | # VulnerableCode is a free software code scanning tool from nexB Inc. and others. |
22 | 22 | # Visit https://github.com/nexB/vulnerablecode/ for support and download. |
23 | 23 |
|
24 | | -from urllib.request import urlopen |
25 | 24 | import json |
| 25 | +from urllib.request import urlopen |
26 | 26 |
|
27 | | -DEBIAN_ROOT_URL = "https://security-tracker.debian.org/tracker/data/json" |
28 | 27 |
|
| 28 | +DEBIAN_TRACKER_URL = 'https://security-tracker.debian.org/tracker/data/json' |
29 | 29 |
|
30 | | -def json_data(): |
| 30 | + |
| 31 | +def json_data(url=DEBIAN_TRACKER_URL): |
31 | 32 | """ |
32 | | - Return JSON of Debian vulnerability data. |
| 33 | + Return Debian vulnerabilities data fetched from `url`. |
33 | 34 | """ |
34 | | - debian_data = urlopen(DEBIAN_ROOT_URL).read() |
35 | | - json_data = json.loads(debian_data) |
36 | | - |
37 | | - return json_data |
| 35 | + debian_data = urlopen(url).read() |
| 36 | + return json.loads(debian_data) |
38 | 37 |
|
39 | 38 |
|
40 | | -def extract_data(data): |
| 39 | +def extract_data(debian_data, base_release='jessie'): |
41 | 40 | """ |
42 | | - Return a dictionary of package names and vulnerability details. |
43 | | - Accepts `JSON` as input. |
| 41 | + Return a sequence of mappings for each existing combination of |
| 42 | + package and vulnerability from a mapping of Debian vulnerabilities |
| 43 | + data. |
44 | 44 | """ |
45 | | - final_data = [] |
| 45 | + package_vulns = [] |
46 | 46 |
|
47 | | - for package_name, vulnerabilities in data.items(): |
48 | | - for vulnerability, details in vulnerabilities.items(): |
49 | | - release_data = details.get('releases').get('jessie') |
| 47 | + for package_name, vulnerabilities in debian_data.items(): |
| 48 | + if not vulnerabilities or not package_name: |
| 49 | + continue |
50 | 50 |
|
51 | | - if release_data is None: |
| 51 | + for vulnerability, details in vulnerabilities.items(): |
| 52 | + releases = details.get('releases') |
| 53 | + if not releases: |
52 | 54 | continue |
53 | 55 |
|
54 | | - final_data.append({ |
55 | | - "package_name": package_name, |
56 | | - "vulnerability_id": vulnerability, |
57 | | - "status": release_data.get("status"), |
58 | | - "urgency": release_data.get("urgency"), |
59 | | - "fixed_version": release_data.get("fixed_version") |
60 | | - } |
61 | | - ) |
| 56 | + release = releases.get(base_release) |
| 57 | + if not release: |
| 58 | + continue |
62 | 59 |
|
63 | | - return final_data |
| 60 | + package_vulns.append({ |
| 61 | + 'package_name': package_name, |
| 62 | + 'vulnerability_id': vulnerability, |
| 63 | + 'status': release.get('status'), |
| 64 | + 'urgency': release.get('urgency'), |
| 65 | + 'fixed_version': release.get('fixed_version') |
| 66 | + }) |
| 67 | + return package_vulns |
0 commit comments