Skip to content

Commit

Permalink
Handle non-JSON responses (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
andor44 authored and jhaals committed Aug 17, 2017
1 parent 23e4bc4 commit 5d67a77
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,12 @@ def run(self, terms, inject=None, variables=None, **kwargs):
if _use_vault_cache:
_vault_cache[key] = result

return [result['data'][field]] if field is not None else [result['data']]
if type(result) is dict:
if field is not None:
return [result['data'][field]]
elif 'data' in result:
return [result['data']]
return [result]

def _fetch_approle_token(self, cafile, capath, role_id, secret_id, approle_role_path, url, cahostverify):
request_url = urljoin(url, approle_role_path)
Expand Down Expand Up @@ -203,5 +208,7 @@ def _fetch_remotely(self, cafile, capath, data, key, vault_token, url, cahostver
raise AnsibleError('Unable to read %s from vault: %s' % (key, e))
except Exception as e:
raise AnsibleError('Unable to read %s from vault: %s' % (key, e))
result = json.loads(response.read())
return result
body = response.read()
if response.headers.get('Content-Type') == 'application/json':
body = json.loads(body)
return body

0 comments on commit 5d67a77

Please sign in to comment.