mirror of
https://git.yoctoproject.org/poky
synced 2026-06-02 01:19:52 +00:00
cve-update-db-native: clean up proxy handling
urllib handles adding proxy handlers if the proxies are set in the environment, so call bb.utils.export_proxies() to do that and remove the manual setup. (From OE-Core rev: 6b73004668b3b71c9c38814b79fbb58c893ed434) Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
bb9b44caf6
commit
fa8f6a236f
@@ -21,10 +21,12 @@ python do_populate_cve_db() {
|
|||||||
"""
|
"""
|
||||||
Update NVD database with json data feed
|
Update NVD database with json data feed
|
||||||
"""
|
"""
|
||||||
|
import bb.utils
|
||||||
import sqlite3, urllib, urllib.parse, shutil, gzip
|
import sqlite3, urllib, urllib.parse, shutil, gzip
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
|
bb.utils.export_proxies(d)
|
||||||
|
|
||||||
BASE_URL = "https://nvd.nist.gov/feeds/json/cve/1.0/nvdcve-1.0-"
|
BASE_URL = "https://nvd.nist.gov/feeds/json/cve/1.0/nvdcve-1.0-"
|
||||||
YEAR_START = 2002
|
YEAR_START = 2002
|
||||||
|
|
||||||
@@ -40,16 +42,6 @@ python do_populate_cve_db() {
|
|||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
proxy = d.getVar("https_proxy")
|
|
||||||
if proxy:
|
|
||||||
# instantiate an opener but do not install it as the global
|
|
||||||
# opener unless if we're really sure it's applicable for all
|
|
||||||
# urllib requests
|
|
||||||
proxy_handler = urllib.request.ProxyHandler({'https': proxy})
|
|
||||||
proxy_opener = urllib.request.build_opener(proxy_handler)
|
|
||||||
else:
|
|
||||||
proxy_opener = None
|
|
||||||
|
|
||||||
cve_f = open(os.path.join(d.getVar("TMPDIR"), 'cve_check'), 'a')
|
cve_f = open(os.path.join(d.getVar("TMPDIR"), 'cve_check'), 'a')
|
||||||
|
|
||||||
if not os.path.isdir(db_dir):
|
if not os.path.isdir(db_dir):
|
||||||
@@ -67,15 +59,7 @@ python do_populate_cve_db() {
|
|||||||
json_url = year_url + ".json.gz"
|
json_url = year_url + ".json.gz"
|
||||||
|
|
||||||
# Retrieve meta last modified date
|
# Retrieve meta last modified date
|
||||||
|
response = urllib.request.urlopen(meta_url)
|
||||||
response = None
|
|
||||||
|
|
||||||
if proxy_opener:
|
|
||||||
response = proxy_opener.open(meta_url)
|
|
||||||
else:
|
|
||||||
req = urllib.request.Request(meta_url)
|
|
||||||
response = urllib.request.urlopen(req)
|
|
||||||
|
|
||||||
if response:
|
if response:
|
||||||
for l in response.read().decode("utf-8").splitlines():
|
for l in response.read().decode("utf-8").splitlines():
|
||||||
key, value = l.split(":", 1)
|
key, value = l.split(":", 1)
|
||||||
@@ -95,12 +79,7 @@ python do_populate_cve_db() {
|
|||||||
|
|
||||||
# Update db with current year json file
|
# Update db with current year json file
|
||||||
try:
|
try:
|
||||||
if proxy_opener:
|
response = urllib.request.urlopen(json_url)
|
||||||
response = proxy_opener.open(json_url)
|
|
||||||
else:
|
|
||||||
req = urllib.request.Request(json_url)
|
|
||||||
response = urllib.request.urlopen(req)
|
|
||||||
|
|
||||||
if response:
|
if response:
|
||||||
update_db(c, gzip.decompress(response.read()).decode('utf-8'))
|
update_db(c, gzip.decompress(response.read()).decode('utf-8'))
|
||||||
c.execute("insert or replace into META values (?, ?)", [year, last_modified])
|
c.execute("insert or replace into META values (?, ?)", [year, last_modified])
|
||||||
|
|||||||
Reference in New Issue
Block a user