From f4f55c3a59583336b249e098abffbe75400f2df5 Mon Sep 17 00:00:00 2001 From: Thomas Deutschmann Date: Mon, 9 Jan 2017 16:36:07 +0100 Subject: cvetool: Detect missing CVE and catch exception when requesting CVE info --- bin/cvetool | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bin/cvetool b/bin/cvetool index d6c2f6d..b8aa5ca 100755 --- a/bin/cvetool +++ b/bin/cvetool @@ -15,6 +15,9 @@ URI_BASE = 'https://glsamaker.gentoo.org' class CVETool: """ Interface to GLSAMaker's CVETool """ + class NotFoundError(RuntimeError): + pass + def __init__(self, auth, command, args): self.auth = auth @@ -46,7 +49,11 @@ class CVETool: sys.exit(1) def info(self, cve): - data = self.json_request('/cve/info/' + cve + '.json') + try: + data = self.json_request('/cve/info/' + cve + '.json') + except self.NotFoundError as e: + print('{} not found in Gentoo\'s CVE database!'.format(cve)) + sys.exit(0) print(' CVE ID: ' + data['cve_id']) print(' Summary: ' + data['summary']) @@ -107,7 +114,9 @@ class CVETool: response, content = client.request(full_uri, method, headers = { 'Authorization': 'Basic ' + self.auth }) status = response['status'] - if (status[0] != '2' and status != '304'): + 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') -- cgit v1.2.3-18-g5258