def get_service(self, service, decrypt_blind=False):
"""Get a service's metadata and secrets."""
# 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/services/{1}'.format(self.config['url'], service),
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, 404]):
return ret
if response.status_code == 404:
logging.debug('Service not found in confidant.')
ret['result'] = True
return ret
try:
data = response.json()
if decrypt_blind:
data['blind_credentials'] = self._decrypt_blind_credentials(
data['blind_credentials']
)
except ValueError:
logging.exception(
'Received badly formatted json data from confidant.'
)
return ret
ret['service'] = data
ret['result'] = True
return ret
评论列表
文章目录