From 653070f4eb98e3e0b0e0ea803dbf349383f7e672 Mon Sep 17 00:00:00 2001 From: Ryan Sawhill Aroha Date: Tue, 27 Jun 2017 16:44:21 +0530 Subject: [PATCH] fix #66 --- rhsda.py | 34 ++++++++++++++++++---------------- rhsecapi.py | 6 +++--- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/rhsda.py b/rhsda.py index 5064857..60c0ea8 100644 --- a/rhsda.py +++ b/rhsda.py @@ -384,7 +384,7 @@ def __stripjoin(self, input, oneLineEach=False): def __check_field(self, field, jsoninput): """Return True if field is desired and exists in jsoninput.""" - if field in self.cfg.desiredFields and jsoninput.has_key(field): + if field in self.cfg.desiredFields and field in jsoninput: return True return False @@ -460,7 +460,7 @@ def _get_and_parse_cve(self, cve): out.append(" CVSS3 : {0} ({1})".format(J['cvss3']['cvss3_base_score'], vector)) # BUGZILLA if 'bugzilla' in self.cfg.desiredFields: - if J.has_key('bugzilla'): + if 'bugzilla' in J: if self.cfg.urls: bug = J['bugzilla']['url'] else: @@ -506,7 +506,7 @@ def _get_and_parse_cve(self, cve): # If product doesn't match spotlight, go to next continue pkg = "" - if release.has_key('package'): + if 'package' in release: pkg = " [{0}]".format(release['package']) advisory = release['advisory'] if self.cfg.urls: @@ -534,7 +534,7 @@ def _get_and_parse_cve(self, cve): # If product doesn't match spotlight, go to next continue pkg = "" - if state.has_key('package_name'): + if 'package_name' in state: pkg = " [{0}]".format(state['package_name']) out.append(" {0}: {1}{2}".format(state['fix_state'], state['product_name'], pkg)) if self.cfg.product and not foundProduct_package_state: @@ -889,30 +889,32 @@ def cve_search_query(self, params, outFormat='list', urls=False): rows.append(["CVE ID", "PUB DATE", "BUGZILLA", "SEVERITY", "CVSS2", "CVSS3", "RHSAS", "PKGS"]) for i in result: date = "" - if i.has_key('public_date'): + if 'public_date' in i and i['public_date'] is not None: date = i['public_date'].split("T")[0] bz = "" if urls: cve = "https://access.redhat.com/security/cve/{0}".format(i['CVE']) - if i.has_key('bugzilla'): + if 'bugzilla' in i and i['bugzilla'] is not None: bz = "https://bugzilla.redhat.com/show_bug.cgi?id={0}".format(i['bugzilla']) else: cve = i['CVE'] - if i.has_key('bugzilla'): + if 'bugzilla' in i and i['bugzilla'] is not None: bz = i['bugzilla'] - severity = i['severity'] - rhsas = "" - if i.has_key('advisories'): - rhsas = "{0: >2}".format(len(i['advisories'])) - pkgs = "" - if i.has_key('affected_packages'): - pkgs = "{0: >2}".format(len(i['affected_packages'])) + severity = "" + if 'severity' in i and i['severity'] is not None: + severity = i['severity'] cvss2 = "" - if i.has_key('cvss_score'): + if 'cvss_score' in i and i['cvss_score'] is not None: cvss2 = str(i['cvss_score']) cvss3 = "" - if i.has_key('cvss3_score'): + if 'cvss3_score' in i and i['cvss3_score'] is not None: cvss3 = str(i['cvss3_score']) + rhsas = "" + if 'advisories' in i and i['advisories'] is not None: + rhsas = "{0: >2}".format(len(i['advisories'])) + pkgs = "" + if 'affected_packages' in i and i['affected_packages'] is not None: + pkgs = "{0: >2}".format(len(i['affected_packages'])) line = [cve, date, bz, severity, cvss2, cvss3, rhsas, pkgs] rows.append(line) return self._columnize(rows, sep=" ") diff --git a/rhsecapi.py b/rhsecapi.py index e396a28..03a463b 100755 --- a/rhsecapi.py +++ b/rhsecapi.py @@ -46,8 +46,8 @@ # Globals prog = 'rhsecapi' vers = {} -vers['version'] = '1.0.0_rc10' -vers['date'] = '2017/01/05' +vers['version'] = '1.0.1' +vers['date'] = '2017/06/27' # Logging @@ -179,7 +179,7 @@ def parse_args(): help="Narrow down results by severity rating (specify one of 'low', 'moderate', 'important', or 'critical')") g_listByAttr.add_argument( '--q-product', metavar="PRODUCT", - help="Narrow down results by product name via case-insensitive regex (e.g.: 'linux 7' or openstack platform [89]'); the API checks this against the 'FIXED_RELEASES' field so will only match CVEs where PRODUCT matches the 'product_name' of some released errata") + help="Narrow down results by product name via case-insensitive regex (e.g.: 'linux 7' or 'openstack platform [89]'); the API checks this against the 'FIXED_RELEASES' field so will only match CVEs where PRODUCT matches the 'product_name' of some released errata") g_listByAttr.add_argument( '--q-package', metavar="PKG", help="Narrow down results by package name (e.g.: 'samba' or 'thunderbird')")