Skip to content

Commit

Permalink
Merge "Add HEAD /tokens/{token_id} (bug 933587)"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Feb 27, 2012
2 parents 2812940 + 33a13b7 commit 679fd36
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
9 changes: 6 additions & 3 deletions keystone/common/wsgi.py
Expand Up @@ -182,7 +182,9 @@ def __call__(self, req):
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
Expand Down Expand Up @@ -458,13 +460,14 @@ def _factory(app):
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

Expand Down
35 changes: 31 additions & 4 deletions keystone/service.py
Expand Up @@ -44,6 +44,10 @@ def __init__(self):
controller=auth_controller,
action='validate_token',
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',
Expand Down Expand Up @@ -324,11 +328,10 @@ def authenticate(self, context, auth=None):
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
Expand All @@ -340,6 +343,30 @@ def validate_token(self, context, token_id, belongs_to=None):
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
Expand Down
5 changes: 2 additions & 3 deletions tests/test_content_types.py
Expand Up @@ -344,13 +344,12 @@ def test_validate_token_head(self):
sake of completely covering the core API.
"""
raise nose.exc.SkipTest('Blocked by bug 933587')

token = self.get_scoped_token()
self.admin_request(method='HEAD', path='/v2.0/tokens/%(token_id)s' % {
'token_id': token,
},
token=token)
token=token,
expected_status=204)

def test_endpoints(self):
raise nose.exc.SkipTest('Blocked by bug 933555')
Expand Down

0 comments on commit 679fd36

Please sign in to comment.