failover: store result in FailoverException
This commit is contained in:
parent
8a1b48dd8c
commit
d2909c0e4d
3 changed files with 11 additions and 9 deletions
|
@ -334,7 +334,7 @@ class SecurityScannerAPI(object):
|
|||
if self._config is None:
|
||||
raise Exception('Cannot call unconfigured security system')
|
||||
|
||||
timeout = self._config['SECURITY_SCANNER_API_TIMEOUT_SECONDS']
|
||||
timeout = self._config.get('SECURITY_SCANNER_API_TIMEOUT_SECONDS', 1)
|
||||
endpoint = self._config['SECURITY_SCANNER_ENDPOINT']
|
||||
|
||||
with CloseForLongOperation(self._config):
|
||||
|
@ -346,12 +346,12 @@ class SecurityScannerAPI(object):
|
|||
return self._request(method, endpoint, path, body, params, timeout)
|
||||
|
||||
# The request is read-only and can failover.
|
||||
all_endpoints = [endpoint] + self._config['SECURITY_SCANNER_READONLY_FAILOVER_ENDPOINTS']
|
||||
all_endpoints = [endpoint] + self._config.get('SECURITY_SCANNER_READONLY_FAILOVER_ENDPOINTS', [])
|
||||
try:
|
||||
return _failover_read_request(*[((self._request, endpoint, path, body, params, timeout), {})
|
||||
return _failover_read_request(*[((self._request, endpoint, path, body, params, timeout), {})
|
||||
for endpoint in all_endpoints])
|
||||
except FailoverException:
|
||||
raise APIRequestFailure()
|
||||
except FailoverException as ex:
|
||||
return ex.return_value
|
||||
|
||||
|
||||
def _join_api_url(endpoint, api_version, path):
|
||||
|
@ -364,5 +364,5 @@ def _failover_read_request(request_fn, endpoint, path, body, params, timeout):
|
|||
""" This function auto-retries read-only requests until they return a 2xx status code. """
|
||||
resp = request_fn('GET', endpoint, path, body, params, timeout)
|
||||
if resp.status_code / 100 != 2:
|
||||
raise FailoverException('status code was not 2xx')
|
||||
raise FailoverException(resp, 'status code was not 2xx')
|
||||
return resp
|
||||
|
|
Reference in a new issue