summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDhairya Nagodra <dnagodra@cisco.com>2023-12-11 02:04:59 -0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-12-13 11:34:27 +0000
commitef371d1cb3b777d64b73d819b745f8ae8814017c (patch)
tree50fdb6bd966f6ed9d769d0c1e119f9c84b995914
parentbebebac37d3a525125818872361bd71f6d37b1f6 (diff)
downloadpoky-ef371d1cb3b777d64b73d819b745f8ae8814017c.tar.gz
cve-update-nvd2-native: faster requests with API keys
As per NVD, the public rate limit is 5 requests in 30s (6s delay). Using an API key increases the limit to 50 requests in 30s (0.6s delay). However, NVD still recommends sleeping for several seconds so that the other legitimate requests are serviced without denial or interruption. Keeping the default sleep at 6 seconds and 2 seconds with an API key. For failures, the wait time is unchanged (6 seconds). Reference: https://nvd.nist.gov/developers/start-here#RateLimits (From OE-Core rev: 5c32e2941d1dc3d04a799a1b7cbd275c1ccc9e79) Signed-off-by: Dhairya Nagodra <dnagodra@cisco.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-core/meta/cve-update-nvd2-native.bb7
1 files changed, 6 insertions, 1 deletions
diff --git a/meta/recipes-core/meta/cve-update-nvd2-native.bb b/meta/recipes-core/meta/cve-update-nvd2-native.bb
index 9ab8dc6050..941fca34c6 100644
--- a/meta/recipes-core/meta/cve-update-nvd2-native.bb
+++ b/meta/recipes-core/meta/cve-update-nvd2-native.bb
@@ -188,6 +188,11 @@ def update_db_file(db_tmp_file, d, database_time):
188 api_key = d.getVar("NVDCVE_API_KEY") or None 188 api_key = d.getVar("NVDCVE_API_KEY") or None
189 attempts = int(d.getVar("CVE_DB_UPDATE_ATTEMPTS")) 189 attempts = int(d.getVar("CVE_DB_UPDATE_ATTEMPTS"))
190 190
191 # Recommended by NVD
192 wait_time = 6
193 if api_key:
194 wait_time = 2
195
191 while True: 196 while True:
192 req_args['startIndex'] = index 197 req_args['startIndex'] = index
193 raw_data = nvd_request_next(url, attempts, api_key, req_args) 198 raw_data = nvd_request_next(url, attempts, api_key, req_args)
@@ -210,7 +215,7 @@ def update_db_file(db_tmp_file, d, database_time):
210 break 215 break
211 216
212 # Recommended by NVD 217 # Recommended by NVD
213 time.sleep(6) 218 time.sleep(wait_time)
214 219
215 # Update success, set the date to cve_check file. 220 # Update success, set the date to cve_check file.
216 cve_f.write('CVE database update : %s\n\n' % datetime.date.today()) 221 cve_f.write('CVE database update : %s\n\n' % datetime.date.today())