def list_blind_credentials(self):
"""Get a list of blind credentials."""
# Return a dict, always with an attribute that specifies whether or not
# the function was able to successfully get a result.
ret = {'result': False}
try:
# Make a request to confidant with the provided url, to fetch the
# service providing the service name and base64 encoded
# token for authentication.
response = self.request_session.get(
'{0}/v1/blind_credentials'.format(self.config['url']),
auth=(self._get_username(), self._get_token()),
allow_redirects=False,
timeout=2
)
except requests.ConnectionError:
logging.error('Failed to connect to confidant.')
return ret
except requests.Timeout:
logging.error('Confidant request timed out.')
return ret
if not self._check_response_code(response, expected=[200]):
return ret
try:
data = response.json()
except ValueError:
logging.error('Received badly formatted json data from confidant.')
return ret
ret['blind_credentials'] = data['blind_credentials']
ret['result'] = True
return ret
评论列表
文章目录