remove more usages of requests lib
This commit is contained in:
+17
-20
@@ -1,6 +1,5 @@
|
||||
#!/usr/bin/env vpython3
|
||||
# pylint: disable=line-too-long
|
||||
|
||||
"""This script runs `npm audit' and `cargo audit' on relevant paths in the
|
||||
repo."""
|
||||
|
||||
@@ -24,14 +23,15 @@ def get_remote_audit_config(
|
||||
|
||||
|
||||
REMOTE_AUDIT_CONFIG = get_remote_audit_config()
|
||||
IGNORED_CARGO_ADVISORIES = [e["advisory"] for e in REMOTE_AUDIT_CONFIG["ignore"]["cargo"]]
|
||||
IGNORED_NPM_ADVISORIES = [e["advisory"] for e in REMOTE_AUDIT_CONFIG["ignore"]["npm"]]
|
||||
IGNORED_CARGO_ADVISORIES = [
|
||||
e["advisory"] for e in REMOTE_AUDIT_CONFIG["ignore"]["cargo"]
|
||||
]
|
||||
IGNORED_NPM_ADVISORIES = [
|
||||
e["advisory"] for e in REMOTE_AUDIT_CONFIG["ignore"]["npm"]
|
||||
]
|
||||
|
||||
# Use all (sub)paths except these for npm audit.
|
||||
NPM_EXCLUDE_PATHS = [
|
||||
'build',
|
||||
os.path.join('node_modules')
|
||||
]
|
||||
NPM_EXCLUDE_PATHS = ['build', os.path.join('node_modules')]
|
||||
|
||||
# Only check Cargo.lock for this path.
|
||||
CARGO_INCLUDE_PATH = os.path.join('third_party', 'rust')
|
||||
@@ -41,15 +41,11 @@ def main():
|
||||
"""Audit a specified path, or the whole project."""
|
||||
|
||||
if len(IGNORED_NPM_ADVISORIES) > 0:
|
||||
print(
|
||||
f"Ignoring NPM advisories "
|
||||
f"{', '.join(map(str, IGNORED_NPM_ADVISORIES))}"
|
||||
)
|
||||
print(f"Ignoring NPM advisories "
|
||||
f"{', '.join(map(str, IGNORED_NPM_ADVISORIES))}")
|
||||
if len(IGNORED_CARGO_ADVISORIES) > 0:
|
||||
print(
|
||||
f"Ignoring Cargo advisories "
|
||||
f"{', '.join(map(str, IGNORED_CARGO_ADVISORIES))}"
|
||||
)
|
||||
print(f"Ignoring Cargo advisories "
|
||||
f"{', '.join(map(str, IGNORED_CARGO_ADVISORIES))}")
|
||||
|
||||
args = parse_args()
|
||||
errors = 0
|
||||
@@ -57,8 +53,9 @@ def main():
|
||||
if args.input_dir:
|
||||
return audit_path(os.path.abspath(args.input_dir), args)
|
||||
|
||||
for path in [os.path.dirname(os.path.dirname(args.source_root)),
|
||||
args.source_root]:
|
||||
for path in [
|
||||
os.path.dirname(os.path.dirname(args.source_root)), args.source_root
|
||||
]:
|
||||
errors += audit_path(path, args)
|
||||
|
||||
for dir_path, dirs, _ in os.walk(args.source_root):
|
||||
@@ -99,8 +96,7 @@ def npm_audit_deps(path, args):
|
||||
# Don't support npm audit --production until dev dependencies are
|
||||
# correctly identified in package.json
|
||||
print('npm audit --production not supported; auditing dev dependencies')
|
||||
audit_process = subprocess.Popen(
|
||||
npm_args, stdout=subprocess.PIPE, cwd=path)
|
||||
audit_process = subprocess.Popen(npm_args, stdout=subprocess.PIPE, cwd=path)
|
||||
output, _ = audit_process.communicate()
|
||||
|
||||
try:
|
||||
@@ -170,7 +166,8 @@ def parse_args():
|
||||
|
||||
parser = argparse.ArgumentParser(description='Audit brave-core npm deps')
|
||||
parser.add_argument('input_dir', nargs='?', help='Directory to check')
|
||||
parser.add_argument('--source_root', required=True,
|
||||
parser.add_argument('--source_root',
|
||||
required=True,
|
||||
help='Full path of the src/brave directory')
|
||||
parser.add_argument('--cargo_audit_exe', required=True)
|
||||
parser.add_argument('--audit_dev_deps',
|
||||
|
||||
@@ -7,11 +7,8 @@ from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
from builtins import str
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import requests
|
||||
import sys
|
||||
import base64
|
||||
import urllib.request
|
||||
try:
|
||||
from .util import execute, scoped_cwd
|
||||
except ImportError:
|
||||
@@ -50,7 +47,8 @@ class GitHub():
|
||||
kw['data'] = json.dumps(kw['data'])
|
||||
|
||||
try:
|
||||
r = getattr(requests, method)(url, **kw).json()
|
||||
kw['method'] = method
|
||||
r = json.loads(urllib.request.urlopen(url, **kw).read())
|
||||
except ValueError:
|
||||
# Returned response may be empty in some cases
|
||||
r = {}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
from __future__ import print_function
|
||||
from builtins import range
|
||||
import os
|
||||
import requests
|
||||
import urllib.request
|
||||
from .config import get_raw_version, get_env_var
|
||||
|
||||
BRAVE_REPO = "brave/brave-browser"
|
||||
@@ -26,8 +26,8 @@ def get_channel_display_name():
|
||||
|
||||
def call_github_api(url, headers):
|
||||
try:
|
||||
r = requests.get(url, headers=headers)
|
||||
except requests.exceptions.ConnectionError:
|
||||
r = urllib.request(url, headers=headers)
|
||||
except urllib.error.URLError:
|
||||
print("Error: Received requests.exceptions.ConnectionError, Exiting...")
|
||||
exit(1)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user