Skip to content

Commit 2f5215e

Browse files
committed
Resolve merge conflict
Signed-off-by: ziadhany <ziadhany2016@gmail.com>
1 parent 7df7227 commit 2f5215e

17 files changed

Lines changed: 266 additions & 28 deletions

vulnerabilities/importers/github_osv.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@
88
#
99
import json
1010
import logging
11-
from io import BytesIO
1211
from pathlib import Path
1312
from typing import Iterable
14-
from zipfile import ZipFile
15-
16-
import requests
1713

1814
from vulnerabilities.importer import AdvisoryData
1915
from vulnerabilities.importer import Importer
2016
from vulnerabilities.importers.osv import parse_advisory_data
17+
from vulnerabilities.utils import get_advisory_url
2118

2219
logger = logging.getLogger(__name__)
2320

@@ -26,6 +23,7 @@ class GithubOSVImporter(Importer):
2623
license_url = "https://github.com/github/advisory-database/blob/main/LICENSE.md"
2724
spdx_license_expression = "CC-BY-4.0"
2825
repo_url = "git+https://github.com/github/advisory-database/"
26+
importer_name = "GithubOSV Importer"
2927

3028
def advisory_data(self) -> Iterable[AdvisoryData]:
3129
supported_ecosystems = [
@@ -41,13 +39,19 @@ def advisory_data(self) -> Iterable[AdvisoryData]:
4139
]
4240
try:
4341
self.clone(repo_url=self.repo_url)
44-
path = Path(self.vcs_response.dest_dir)
42+
base_path = Path(self.vcs_response.dest_dir)
4543
# filter out non-github-reviewed files and only keep the files end-with .json
46-
advisory_dirs = path / "advisories/github-reviewed"
44+
advisory_dirs = base_path / "advisories/github-reviewed"
4745
for file in advisory_dirs.glob("**/*.json"):
46+
advisory_url = get_advisory_url(
47+
file=file,
48+
base_path=base_path,
49+
url="https://github.com/github/advisory-database/blob/main/",
50+
)
4851
with open(file) as f:
4952
raw_data = json.load(f)
50-
yield parse_advisory_data(raw_data, supported_ecosystems)
53+
print(advisory_url)
54+
yield parse_advisory_data(raw_data, supported_ecosystems, advisory_url)
5155
finally:
5256
if self.vcs_response:
5357
self.vcs_response.delete()

vulnerabilities/importers/oss_fuzz.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def advisory_data(self) -> Iterable[AdvisoryData]:
4040
url="https://github.com/pypa/advisory-database/blob/main/",
4141
)
4242
yield parse_advisory_data(
43-
yaml_data, supported_ecosystem="oss-fuzz", advisory_url=advisory_url
43+
yaml_data, supported_ecosystems=["oss-fuzz"], advisory_url=advisory_url
4444
)
4545
finally:
4646
if self.vcs_response:

vulnerabilities/importers/osv.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@
4343
"cargo": "cargo",
4444
}
4545

46+
4647
def parse_advisory_data(
47-
raw_data: dict, supported_ecosystems, advisory_url: str
48+
raw_data: dict, supported_ecosystems, advisory_url: str
4849
) -> Optional[AdvisoryData]:
4950
"""
5051
Return an AdvisoryData build from a ``raw_data`` mapping of OSV advisory and

vulnerabilities/importers/pypa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def advisory_data(self) -> Iterable[AdvisoryData]:
3434
for advisory_url, raw_data in fork_and_get_files(base_path=path):
3535
yield parse_advisory_data(
3636
raw_data=raw_data,
37-
supported_ecosystem=["pypi"],
37+
supported_ecosystems=["pypi"],
3838
advisory_url=advisory_url,
3939
)
4040
finally:

vulnerabilities/importers/pysec.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ def advisory_data(self) -> Iterable[AdvisoryData]:
3939
continue
4040
with zip_file.open(file_name) as f:
4141
vul_info = json.load(f)
42-
yield parse_advisory_data(raw_data=vul_info, supported_ecosystems=["pypi"], advisory_url=url)
42+
yield parse_advisory_data(
43+
raw_data=vul_info, supported_ecosystems=["pypi"], advisory_url=url
44+
)

vulnerabilities/tests/test_data/github_osv/github_osv_expected_1.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,6 @@
117117
}
118118
],
119119
"date_published": "2017-10-24T18:33:36+00:00",
120-
"weaknesses": [400]
120+
"weaknesses": [400],
121+
"url": "https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/github_osv_test_1.json"
121122
}

vulnerabilities/tests/test_data/github_osv/github_osv_expected_2.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,6 @@
7474
}
7575
],
7676
"date_published": "2022-03-23T00:00:23+00:00",
77-
"weaknesses": [190]
77+
"weaknesses": [190],
78+
"url": "https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/github_osv_test_2.json"
7879
}

vulnerabilities/tests/test_data/github_osv/github_osv_expected_3.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,6 @@
137137
}
138138
],
139139
"date_published": "2021-06-15T16:05:22+00:00",
140-
"weaknesses": [79]
140+
"weaknesses": [79],
141+
"url": "https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/github_osv_test_3.json"
141142
}

vulnerabilities/tests/test_data/github_osv/github_osv_expected_4.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,5 +189,6 @@
189189
"date_published": "2017-10-24T18:33:38+00:00",
190190
"weaknesses": [
191191
352
192-
]
192+
],
193+
"url": "https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/github_osv_test_4.json"
193194
}

vulnerabilities/tests/test_data/github_osv/github_osv_expected_5.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,5 +219,6 @@
219219
"date_published": "2023-07-03T21:30:57+00:00",
220220
"weaknesses": [
221221
20
222-
]
222+
],
223+
"url": "https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/github_osv_test_5.json"
223224
}

0 commit comments

Comments
 (0)