summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/recipes-core/meta/cve-update-db.bb10
1 files changed, 4 insertions, 6 deletions
diff --git a/meta/recipes-core/meta/cve-update-db.bb b/meta/recipes-core/meta/cve-update-db.bb
index 522fd23807..1f48820cc6 100644
--- a/meta/recipes-core/meta/cve-update-db.bb
+++ b/meta/recipes-core/meta/cve-update-db.bb
@@ -19,7 +19,7 @@ python do_populate_cve_db() {
19 Update NVD database with json data feed 19 Update NVD database with json data feed
20 """ 20 """
21 21
22 import sqlite3, urllib3, shutil, gzip, re 22 import sqlite3, urllib, shutil, gzip, re
23 from datetime import date 23 from datetime import date
24 24
25 BASE_URL = "https://nvd.nist.gov/feeds/json/cve/1.0/nvdcve-1.0-" 25 BASE_URL = "https://nvd.nist.gov/feeds/json/cve/1.0/nvdcve-1.0-"
@@ -33,16 +33,14 @@ python do_populate_cve_db() {
33 33
34 initialize_db(c) 34 initialize_db(c)
35 35
36 http = urllib3.PoolManager()
37
38 for year in range(YEAR_START, date.today().year + 1): 36 for year in range(YEAR_START, date.today().year + 1):
39 year_url = BASE_URL + str(year) 37 year_url = BASE_URL + str(year)
40 meta_url = year_url + ".meta" 38 meta_url = year_url + ".meta"
41 json_url = year_url + ".json.gz" 39 json_url = year_url + ".json.gz"
42 40
43 # Retrieve meta last modified date 41 # Retrieve meta last modified date
44 with http.request('GET', meta_url, preload_content=False) as r: 42 with urllib.request.urlopen(meta_url) as r:
45 date_line = str(r.data.splitlines()[0]) 43 date_line = str(r.read().splitlines()[0])
46 last_modified = re.search('lastModifiedDate:(.*)', date_line).group(1) 44 last_modified = re.search('lastModifiedDate:(.*)', date_line).group(1)
47 45
48 # Compare with current db last modified date 46 # Compare with current db last modified date
@@ -50,7 +48,7 @@ python do_populate_cve_db() {
50 meta = c.fetchone() 48 meta = c.fetchone()
51 if not meta or meta[0] != last_modified: 49 if not meta or meta[0] != last_modified:
52 # Update db with current year json file 50 # Update db with current year json file
53 with http.request('GET', json_url, preload_content=False) as r, open(JSON_TMPFILE, 'wb') as tmpfile: 51 with urllib.request.urlopen(json_url) as r, open(JSON_TMPFILE, 'wb') as tmpfile:
54 shutil.copyfileobj(r, tmpfile) 52 shutil.copyfileobj(r, tmpfile)
55 with gzip.open(JSON_TMPFILE, 'rt') as jsonfile: 53 with gzip.open(JSON_TMPFILE, 'rt') as jsonfile:
56 update_db(c, jsonfile) 54 update_db(c, jsonfile)