20
20
from bs4 import BeautifulSoup
21
21
from rich .progress import track
22
22
23
- from cve_bin_tool .async_utils import FileIO , GzipFile , run_coroutine
23
+ from cve_bin_tool .async_utils import FileIO , GzipFile , RateLimiter , run_coroutine
24
24
from cve_bin_tool .error_handler import (
25
25
AttemptedToWriteOutsideCachedir ,
26
26
CVEDataForCurlVersionNotInCache ,
@@ -103,7 +103,7 @@ def get_db_update_date(self):
103
103
return os .path .getmtime (self .dbpath )
104
104
105
105
async def getmeta (self , session , meta_url ):
106
- async with session .get (meta_url ) as response :
106
+ async with await session .get (meta_url ) as response :
107
107
response .raise_for_status ()
108
108
return (
109
109
meta_url .replace (".meta" , ".json.gz" ),
@@ -117,7 +117,7 @@ async def getmeta(self, session, meta_url):
117
117
)
118
118
119
119
async def nist_scrape (self , session ):
120
- async with session .get (self .feed ) as response :
120
+ async with await session .get (self .feed ) as response :
121
121
response .raise_for_status ()
122
122
page = await response .text ()
123
123
json_meta_links = self .META_REGEX .findall (page )
@@ -161,8 +161,7 @@ async def cache_update(self, session, url, sha, chunk_size=16 * 1024):
161
161
self .LOGGER .debug (f"Correct SHA for { filename } " )
162
162
return
163
163
self .LOGGER .debug (f"Updating CVE cache for { filename } " )
164
-
165
- async with session .get (url ) as response :
164
+ async with await session .get (url ) as response :
166
165
# Raise better error message on ratelimit by NVD
167
166
if response .status == 403 :
168
167
with ErrorHandler (mode = self .error_mode , logger = self .LOGGER ):
@@ -187,7 +186,7 @@ async def cache_update(self, session, url, sha, chunk_size=16 * 1024):
187
186
@staticmethod
188
187
async def get_curl_versions (session ):
189
188
regex = re .compile (r"vuln-(\d+.\d+.\d+)\.html" )
190
- async with session .get (
189
+ async with await session .get (
191
190
"https://curl.haxx.se/docs/vulnerabilities.html"
192
191
) as response :
193
192
response .raise_for_status ()
@@ -196,7 +195,7 @@ async def get_curl_versions(session):
196
195
return [match .group (1 ) for match in matches ]
197
196
198
197
async def download_curl_version (self , session , version ):
199
- async with session .get (
198
+ async with await session .get (
200
199
f"https://curl.haxx.se/docs/vuln-{ version } .html"
201
200
) as response :
202
201
response .raise_for_status ()
@@ -233,13 +232,16 @@ async def refresh(self):
233
232
check_latest_version ()
234
233
if not self .session :
235
234
connector = aiohttp .TCPConnector (limit_per_host = 19 )
236
- self .session = aiohttp .ClientSession (connector = connector , trust_env = True )
235
+ self .session = RateLimiter (
236
+ aiohttp .ClientSession (connector = connector , trust_env = True )
237
+ )
237
238
self .LOGGER .info ("Downloading CVE data..." )
238
239
nvd_metadata , curl_metadata = await asyncio .gather (
239
- self .nist_scrape (self .session ), self .get_curl_versions (self .session )
240
+ asyncio .ensure_future (self .nist_scrape (self .session )),
241
+ asyncio .ensure_future (self .get_curl_versions (self .session )),
240
242
)
241
243
tasks = [
242
- self .cache_update (self .session , url , meta ["sha256" ])
244
+ asyncio . ensure_future ( self .cache_update (self .session , url , meta ["sha256" ]) )
243
245
for url , meta in nvd_metadata .items ()
244
246
if meta is not None
245
247
]
@@ -251,7 +253,9 @@ async def refresh(self):
251
253
tasks .append (
252
254
asyncio .gather (
253
255
* (
254
- self .download_curl_version (self .session , version )
256
+ asyncio .ensure_future (
257
+ self .download_curl_version (self .session , version )
258
+ )
255
259
for version in curl_metadata
256
260
)
257
261
)
0 commit comments