diff options
author | Jenkins <jenkins@review.openstack.org> | 2012-02-27 23:00:47 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2012-02-27 23:00:47 +0000 |
commit | 679fd363d8a44098cdf4fa2044b068e51016c02d (patch) | |
tree | 4aba336c78df9651db9282402a24ef0cbb546ad9 /keystone | |
parent | 28129406ba2bbec2dc60b9e8733c4270d7e5d15b (diff) | |
parent | 33a13b7dcd82ee926a707bf1cc7f87ae2b90c98e (diff) | |
download | keystone-679fd363d8a44098cdf4fa2044b068e51016c02d.tar.gz keystone-679fd363d8a44098cdf4fa2044b068e51016c02d.tar.xz keystone-679fd363d8a44098cdf4fa2044b068e51016c02d.zip |
Merge "Add HEAD /tokens/{token_id} (bug 933587)"
Diffstat (limited to 'keystone')
-rw-r--r-- | keystone/common/wsgi.py | 9 | ||||
-rw-r--r-- | keystone/service.py | 35 |
2 files changed, 37 insertions, 7 deletions
diff --git a/keystone/common/wsgi.py b/keystone/common/wsgi.py index 496288e5..d5976339 100644 --- a/keystone/common/wsgi.py +++ b/keystone/common/wsgi.py @@ -182,7 +182,9 @@ class Application(BaseApplication): logging.warning(e) return render_exception(e) - if result is None or type(result) is str or type(result) is unicode: + if result is None: + return render_response(status=(204, 'No Content')) + elif isinstance(result, basestring): return result elif isinstance(result, webob.Response): return result @@ -458,13 +460,14 @@ class ExtensionRouter(Router): return _factory -def render_response(body, status=(200, 'OK'), headers=None): +def render_response(body=None, status=(200, 'OK'), headers=None): """Forms a WSGI response""" resp = webob.Response() resp.status = '%s %s' % status resp.headerlist = headers or [('Content-Type', 'application/json')] - resp.body = json.dumps(body) + if body is not None: + resp.body = json.dumps(body) return resp diff --git a/keystone/service.py b/keystone/service.py index c16e83bb..4f934ec2 100644 --- a/keystone/service.py +++ b/keystone/service.py @@ -46,6 +46,10 @@ class AdminRouter(wsgi.ComposingRouter): conditions=dict(method=['GET'])) mapper.connect('/tokens/{token_id}', controller=auth_controller, + action='validate_token_head', + conditions=dict(method=['HEAD'])) + mapper.connect('/tokens/{token_id}', + controller=auth_controller, action='delete_token', conditions=dict(method=['DELETE'])) mapper.connect('/tokens/{token_id}/endpoints', @@ -324,11 +328,10 @@ class TokenController(wsgi.Application): logging.debug('TOKEN_REF %s', token_ref) return self._format_authenticate(token_ref, roles_ref, catalog_ref) - # admin only - def validate_token(self, context, token_id, belongs_to=None): - """Check that a token is valid. + def _get_token_ref(self, context, token_id, belongs_to=None): + """Returns a token if a valid one exists. - Optionally, also ensure that it is owned by a specific tenant. + Optionally, limited to a token owned by a specific tenant. """ # TODO(termie): this stuff should probably be moved to middleware @@ -340,6 +343,30 @@ class TokenController(wsgi.Application): if belongs_to: assert token_ref['tenant']['id'] == belongs_to + return token_ref + + # admin only + def validate_token_head(self, context, token_id, belongs_to=None): + """Check that a token is valid. + + Optionally, also ensure that it is owned by a specific tenant. + + Identical to ``validate_token``, except does not return a response. + + """ + assert self._get_token_ref(context, token_id, belongs_to) + + # admin only + def validate_token(self, context, token_id, belongs_to=None): + """Check that a token is valid. + + Optionally, also ensure that it is owned by a specific tenant. + + Returns metadata about the token along any associated roles. + + """ + token_ref = self._get_token_ref(context, token_id, belongs_to) + # TODO(termie): optimize this call at some point and put it into the # the return for metadata # fill out the roles in the metadata |