From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id B2FDE139086 for ; Fri, 13 Jan 2017 10:45:21 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 56726E0C47; Fri, 13 Jan 2017 10:45:20 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 37DEDE0C47 for ; Fri, 13 Jan 2017 10:45:20 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id DEAE5341753 for ; Fri, 13 Jan 2017 10:45:18 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 753F32624 for ; Fri, 13 Jan 2017 10:45:17 +0000 (UTC) From: "Thomas Deutschmann" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Thomas Deutschmann" Message-ID: <1483976167.f4f55c3a59583336b249e098abffbe75400f2df5.whissi@gentoo> Subject: [gentoo-commits] proj/security:master commit in: bin/ X-VCS-Repository: proj/security X-VCS-Files: bin/cvetool X-VCS-Directories: bin/ X-VCS-Committer: whissi X-VCS-Committer-Name: Thomas Deutschmann X-VCS-Revision: f4f55c3a59583336b249e098abffbe75400f2df5 X-VCS-Branch: master Date: Fri, 13 Jan 2017 10:45:17 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 26029b7c-c595-4a87-a668-8cf487d2cf3a X-Archives-Hash: 9d52b6e424e1bf22b69e9b170421af3a commit: f4f55c3a59583336b249e098abffbe75400f2df5 Author: Thomas Deutschmann gentoo org> AuthorDate: Mon Jan 9 15:36:07 2017 +0000 Commit: Thomas Deutschmann gentoo org> CommitDate: Mon Jan 9 15:36:07 2017 +0000 URL: https://gitweb.gentoo.org/proj/security.git/commit/?id=f4f55c3a 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')