Merge "Support older token formats for projects in accessinfo"
This commit is contained in:
@@ -222,7 +222,7 @@ class AccessInfo(dict):
|
|||||||
request, or None if the authentication request wasn't scoped to a
|
request, or None if the authentication request wasn't scoped to a
|
||||||
project.
|
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()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@@ -327,9 +327,24 @@ class AccessInfoV2(AccessInfo):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def project_name(self):
|
def project_name(self):
|
||||||
tenant_dict = self['token'].get('tenant', None)
|
try:
|
||||||
if tenant_dict:
|
tenant_dict = self['token']['tenant']
|
||||||
return tenant_dict.get('name', None)
|
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
|
@property
|
||||||
def scoped(self):
|
def scoped(self):
|
||||||
@@ -357,10 +372,24 @@ class AccessInfoV2(AccessInfo):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def project_id(self):
|
def project_id(self):
|
||||||
tenant_dict = self['token'].get('tenant', None)
|
try:
|
||||||
if tenant_dict:
|
tenant_dict = self['token']['tenant']
|
||||||
return tenant_dict.get('id', None)
|
except KeyError:
|
||||||
return None
|
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
|
@property
|
||||||
def project_domain_id(self):
|
def project_domain_id(self):
|
||||||
|
@@ -2,11 +2,14 @@ import datetime
|
|||||||
|
|
||||||
from keystoneclient import access
|
from keystoneclient import access
|
||||||
from keystoneclient.openstack.common import timeutils
|
from keystoneclient.openstack.common import timeutils
|
||||||
|
from tests import client_fixtures as token_data
|
||||||
from tests import utils
|
from tests import utils
|
||||||
from tests.v2_0 import client_fixtures
|
from tests.v2_0 import client_fixtures
|
||||||
|
|
||||||
UNSCOPED_TOKEN = client_fixtures.UNSCOPED_TOKEN
|
UNSCOPED_TOKEN = client_fixtures.UNSCOPED_TOKEN
|
||||||
PROJECT_SCOPED_TOKEN = client_fixtures.PROJECT_SCOPED_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):
|
class AccessInfoTest(utils.TestCase):
|
||||||
@@ -73,3 +76,18 @@ class AccessInfoTest(utils.TestCase):
|
|||||||
self.assertTrue(auth_ref.scoped)
|
self.assertTrue(auth_ref.scoped)
|
||||||
self.assertTrue(auth_ref.project_scoped)
|
self.assertTrue(auth_ref.project_scoped)
|
||||||
self.assertFalse(auth_ref.domain_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')
|
||||||
|
Reference in New Issue
Block a user