Skip to content

Commit

Permalink
Handle IQ warning (#39)
Browse files Browse the repository at this point in the history
* handle 'Warning' from IQ policy
  • Loading branch information
bhamail committed Sep 22, 2020
1 parent 4a2d196 commit cdfd806
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
8 changes: 8 additions & 0 deletions jake/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,14 @@ def __iq_control_flow(args: dict, bom_str: bytes):
print(Fore.YELLOW +
"Your IQ Server Report is available here: {}".format(iq_requests.get_report_url()))
_exit(1)
elif iq_requests.get_policy_action() == 'Warning':
spinner.ok("🧨 ")
__toggle_stdout(on=True)
print(Fore.GREEN +
"Something slithers around your ankle! There are policy warnings from Sonatype IQ.")
print(Fore.GREEN +
"Your IQ Server Report is available here: {}".format(iq_requests.get_report_url()))
_exit(0)
elif iq_requests.get_policy_action() == 'None':
spinner.ok("🐍 ")
__toggle_stdout(on=True)
Expand Down
16 changes: 16 additions & 0 deletions jake/test/iqpolicywarningresponse.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"policyAction": "Warning",
"reportHtmlUrl": "http://localhost:8070/ui/links/application/my-app/report/95c4c14e",
"isError": false,
"componentsAffected": {
"critical": 1,
"severe": 0,
"moderate": 0
},
"openPolicyViolations": {
"critical": 2,
"severe": 1,
"moderate": 0
},
"grandfatheredPolicyViolations": 0
}
16 changes: 16 additions & 0 deletions jake/test/test_iq.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,19 @@ def test_call_poll_report_failure_policy_action(self):

self.func.poll_report(self.status_url)
self.assertEqual(self.func.get_policy_action(), 'Failure')

@responses.activate
def test_call_poll_report_warning_policy_action(self):
"""test_call_poll_report_warning_policy_action mocks a call to IQ
and ensures that that calls to IQ asking for a poll
response on a status URL, return as expected, and sets policy action
to Warning"""
file = Path(__file__).parent / "iqpolicywarningresponse.txt"
with open(file, "r") as stdin:
mock_json = json.loads(stdin.read())
responses.add(responses.GET,
self.full_status_url,
json=mock_json, status=200)

self.func.poll_report(self.status_url)
self.assertEqual(self.func.get_policy_action(), 'Warning')

0 comments on commit cdfd806

Please sign in to comment.