Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

Commit

Permalink
assess-vulnerabilities-risk.py gens JSON debug doc
Browse files Browse the repository at this point in the history
  • Loading branch information
simonsdave committed Sep 9, 2017
1 parent 2c20ba1 commit 7966de5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
8 changes: 2 additions & 6 deletions bin/assess-vulnerabilities-risk.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,9 @@ def parse_args(self, *args, **kwargs):
sys.exit(2)

#
# can be helpful for debugging
# can be super useful for debugging
#
for vulnerability in vulnerabilities:
_logger.debug('-' * 50)
_logger.debug(json.dumps(vulnerability.vulnerability, indent=2))
if vulnerabilities:
_logger.debug('-' * 50)
_logger.debug(json.dumps(vulnerabilities))

#
# this is what it's all been leading up to:-)
Expand Down
12 changes: 5 additions & 7 deletions clair_cicd/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def ignore_severties_at_or_below(self):
return Severity(self.whitelist.get('ignoreSevertiesAtOrBelow', 'Medium'))


class Vulnerability(object):
class Vulnerability(dict):

def __init__(self, vulnerability):
def __init__(self, *args, **kwargs):
"""'''vulnerability''' is expected to be a dictionary
of the form illustrated by the example below:
Expand All @@ -63,19 +63,17 @@ def __init__(self, vulnerability):
}
}
"""
object.__init__(self)

self.vulnerability = vulnerability
dict.__init__(self, *args, **kwargs)

def __str__(self):
return self.cve_id

@property
def cve_id(self):
return self.vulnerability['Name']
return self['Name']

@property
def severity(self):
# use Severity if it exists otherwise uses Score
# where low = 0.0-3.9, medium = 4.0-6.9 & high = 7.0-10.0
return Severity(self.vulnerability['Severity'])
return Severity(self['Severity'])
2 changes: 1 addition & 1 deletion clair_cicd/tests/models_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class VulnerabilityTestCase(unittest.TestCase):
def test_ctr(self):
vulnerability_dict = {}
vulnerability = Vulnerability(vulnerability_dict)
self.assertTrue(vulnerability_dict == vulnerability.vulnerability)
self.assertTrue(vulnerability_dict == vulnerability)

def test_cve_id(self):
cve_id = 'abc'
Expand Down

0 comments on commit 7966de5

Please sign in to comment.