Merge "Support older token formats for projects in accessinfo"

This commit is contained in:
Jenkins
2013-08-26 19:59:54 +00:00
committed by Gerrit Code Review
2 changed files with 55 additions and 8 deletions

View File

@@ -222,7 +222,7 @@ class AccessInfo(dict):
request, or None if the authentication request wasn't scoped to a
project.
:returns: str or None ((if no project associated with the token)
:returns: str or None (if no project associated with the token)
"""
raise NotImplementedError()
@@ -327,9 +327,24 @@ class AccessInfoV2(AccessInfo):
@property
def project_name(self):
tenant_dict = self['token'].get('tenant', None)
if tenant_dict:
return tenant_dict.get('name', None)
try:
tenant_dict = self['token']['tenant']
except KeyError:
pass
else:
return tenant_dict.get('name')
# pre grizzly
try:
return self['user']['tenantName']
except KeyError:
pass
# pre diablo, keystone only provided a tenantId
try:
return self['token']['tenantId']
except KeyError:
pass
@property
def scoped(self):
@@ -357,10 +372,24 @@ class AccessInfoV2(AccessInfo):
@property
def project_id(self):
tenant_dict = self['token'].get('tenant', None)
if tenant_dict:
return tenant_dict.get('id', None)
return None
try:
tenant_dict = self['token']['tenant']
except KeyError:
pass
else:
return tenant_dict.get('id')
# pre grizzly
try:
return self['user']['tenantId']
except KeyError:
pass
# pre diablo
try:
return self['token']['tenantId']
except KeyError:
pass
@property
def project_domain_id(self):

View File

@@ -2,11 +2,14 @@ import datetime
from keystoneclient import access
from keystoneclient.openstack.common import timeutils
from tests import client_fixtures as token_data
from tests import utils
from tests.v2_0 import client_fixtures
UNSCOPED_TOKEN = client_fixtures.UNSCOPED_TOKEN
PROJECT_SCOPED_TOKEN = client_fixtures.PROJECT_SCOPED_TOKEN
DIABLO_TOKEN = token_data.TOKEN_RESPONSES[token_data.VALID_DIABLO_TOKEN]
GRIZZLY_TOKEN = token_data.TOKEN_RESPONSES[token_data.SIGNED_TOKEN_SCOPED_KEY]
class AccessInfoTest(utils.TestCase):
@@ -73,3 +76,18 @@ class AccessInfoTest(utils.TestCase):
self.assertTrue(auth_ref.scoped)
self.assertTrue(auth_ref.project_scoped)
self.assertFalse(auth_ref.domain_scoped)
def test_diablo_token(self):
auth_ref = access.AccessInfo.factory(body=DIABLO_TOKEN)
self.assertTrue(auth_ref)
self.assertEquals(auth_ref.username, 'user_name1')
self.assertEquals(auth_ref.project_id, 'tenant_id1')
self.assertEquals(auth_ref.project_name, 'tenant_id1')
self.assertFalse(auth_ref.scoped)
def test_grizzly_token(self):
auth_ref = access.AccessInfo.factory(body=GRIZZLY_TOKEN)
self.assertEquals(auth_ref.project_id, 'tenant_id1')
self.assertEquals(auth_ref.project_name, 'tenant_name1')