Merge "Add new error for invalid response"

This commit is contained in:
Jenkins 2014-04-24 01:57:12 +00:00 committed by Gerrit Code Review
commit 62be5cae98
4 changed files with 23 additions and 2 deletions

View File

@ -58,6 +58,7 @@ class BaseIdentityPlugin(base.BaseAuthPlugin):
when invoked. If you are looking to just retrieve the current auth when invoked. If you are looking to just retrieve the current auth
data then you should use get_access. data then you should use get_access.
:raises InvalidResponse: The response returned wasn't appropriate.
:raises HttpError: An error from an invalid HTTP response. :raises HttpError: An error from an invalid HTTP response.
:returns AccessInfo: Token access information. :returns AccessInfo: Token access information.

View File

@ -84,7 +84,13 @@ class Auth(base.BaseIdentityPlugin):
resp = session.post(url, json=params, headers=headers, resp = session.post(url, json=params, headers=headers,
authenticated=False) authenticated=False)
return access.AccessInfoV2(**resp.json()['access'])
try:
resp_data = resp.json()['access']
except (KeyError, ValueError):
raise exceptions.InvalidResponse(response=resp)
return access.AccessInfoV2(**resp_data)
@abc.abstractmethod @abc.abstractmethod
def get_auth_data(self, headers=None): def get_auth_data(self, headers=None):

View File

@ -108,8 +108,14 @@ class Auth(base.BaseIdentityPlugin):
resp = session.post(self.token_url, json=body, headers=headers, resp = session.post(self.token_url, json=body, headers=headers,
authenticated=False) authenticated=False)
try:
resp_data = resp.json()['token']
except (KeyError, ValueError):
raise exceptions.InvalidResponse(response=resp)
return access.AccessInfoV3(resp.headers['X-Subject-Token'], return access.AccessInfoV3(resp.headers['X-Subject-Token'],
**resp.json()['token']) **resp_data)
@staticmethod @staticmethod
def _factory(auth_url, **kwargs): def _factory(auth_url, **kwargs):

View File

@ -61,3 +61,11 @@ class MissingAuthPlugin(ClientException):
class NoMatchingPlugin(ClientException): class NoMatchingPlugin(ClientException):
"""There were no auth plugins that could be created from the parameters """There were no auth plugins that could be created from the parameters
provided.""" provided."""
class InvalidResponse(ClientException):
"""The response from the server is not valid for this request."""
def __init__(self, response):
super(InvalidResponse, self).__init__()
self.response = response