summaryrefslogtreecommitdiffstats
path: root/keystone
diff options
context:
space:
mode:
authorDolph Mathews <dolph.mathews@gmail.com>2012-02-21 16:38:40 -0600
committerDolph Mathews <dolph.mathews@gmail.com>2012-02-27 10:03:24 -0600
commit33a13b7dcd82ee926a707bf1cc7f87ae2b90c98e (patch)
treeeee1cf7093aaa37d9b03a7e536be0718ead1ec0b /keystone
parent212489084fac8de20718bfccad2f77cbfa7ea3e2 (diff)
downloadkeystone-33a13b7dcd82ee926a707bf1cc7f87ae2b90c98e.tar.gz
keystone-33a13b7dcd82ee926a707bf1cc7f87ae2b90c98e.tar.xz
keystone-33a13b7dcd82ee926a707bf1cc7f87ae2b90c98e.zip
Add HEAD /tokens/{token_id} (bug 933587)
Also addresses bug 928045 by returning 204 No Content for null content bodies. Change-Id: Icd4b8b5f6c29c074cb014c301fe86cd917f6663e
Diffstat (limited to 'keystone')
-rw-r--r--keystone/common/wsgi.py9
-rw-r--r--keystone/service.py35
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 b0bfd10c..359ba8e4 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',
@@ -316,11 +320,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
@@ -332,6 +335,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