diff options
author | 2021-07-03 19:13:42 -0500 | |
---|---|---|
committer | 2021-07-03 19:13:42 -0500 | |
commit | 8a6a4c4f49255b04fc9b0b64e569abc58794100b (patch) | |
tree | dd3cb945849b82d18e21f485810f2528fbdb8cc5 | |
parent | cvetool: miscellaneous trivial linter fixes (diff) | |
download | security-8a6a4c4f49255b04fc9b0b64e569abc58794100b.tar.gz security-8a6a4c4f49255b04fc9b0b64e569abc58794100b.tar.bz2 security-8a6a4c4f49255b04fc9b0b64e569abc58794100b.zip |
cvetool: httplib2 -> requests
Signed-off-by: John Helmert III <ajak@gentoo.org>
-rwxr-xr-x | bin/cvetool | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/bin/cvetool b/bin/cvetool index 2ce6a34..dc9c35d 100755 --- a/bin/cvetool +++ b/bin/cvetool @@ -2,13 +2,12 @@ # Copyright 2016 Alex Legler # Distributed under the terms of the GNU General Public License v3 -import json import re import sys import os from urllib.parse import urlencode from base64 import b64encode -import httplib2 +import requests URI_BASE = 'https://glsamaker.gentoo.org' @@ -168,7 +167,7 @@ class CVETool: return self.json_request('/cve/info/' + cve + '.json')['id'] def json_request(self, uri, method='GET'): - return json.loads(self.request(uri, method)) + return self.request(uri, method, jsondata=True) def cleanup_cve(self, string): regex = re.compile('^(CVE-)?\d{4}-\d{4,}$') @@ -180,20 +179,26 @@ class CVETool: else: return string - def request(self, uri, method='GET'): - client = httplib2.Http('.cache') + def request(self, uri, method='GET', jsondata=False): full_uri = URI_BASE + uri - response, content = \ - client.request(full_uri, method, - headers={'Authorization': 'Basic ' + self.auth}) - - status = response['status'] - if status == '404': - raise self.NotFoundError(full_uri + ': ' + status) - elif (status[0] != '2' and status != '304'): - raise RuntimeError(full_uri + ': ' + status) - - return content.decode('utf-8') + if method == 'GET': + response = \ + requests.get(full_uri, + headers={'Authorization': 'Basic ' + self.auth}) + elif method == 'POST': + response = \ + requests.post(full_uri, + headers={'Authorization': 'Basic ' + self.auth}) + + status = response.status_code + if status == 404: + raise self.NotFoundError(full_uri + ': ' + str(status)) + if not response.ok: + raise RuntimeError(full_uri + ': ' + str(status)) + + if jsondata: + return response.json() + return response.text def main(): |