Fixes compatibility with keystoneclient v0.2.

This commit is contained in:
Gabriel Hurley 2012-12-09 19:28:13 -08:00
parent f8b1be84bf
commit b95664d5ba
6 changed files with 26 additions and 8 deletions

View File

@ -1,2 +1,2 @@
# following PEP 386
__version__ = "1.0.5"
__version__ = "1.0.6"

View File

@ -97,6 +97,9 @@ class KeystoneBackend(object):
while tenants:
tenant = tenants.pop()
try:
client = keystone_client.Client(tenant_id=tenant.id,
token=unscoped_token.id,
auth_url=auth_url)
token = client.tokens.authenticate(username=username,
token=unscoped_token.id,
tenant_id=tenant.id)
@ -113,7 +116,9 @@ class KeystoneBackend(object):
self.check_auth_expiry(token)
# If we made it here we succeeded. Create our User!
user = create_user_from_token(request, token, client.management_url)
user = create_user_from_token(request,
token,
client.service_catalog.url_for())
if request is not None:
if is_ans1_token(unscoped_token.id):

View File

@ -41,6 +41,10 @@ class OpenStackAuthTests(test.TestCase):
username=user.name,
tenant_id=None).AndReturn(self.keystone_client)
self.keystone_client.tenants.list().AndReturn(tenants)
client.Client(auth_url=settings.OPENSTACK_KEYSTONE_URL,
tenant_id=self.data.tenant_two.id,
token=sc.get_token()['id']) \
.AndReturn(self.keystone_client)
self.keystone_client.tokens.authenticate(tenant_id=tenants[1].id,
token=sc.get_token()['id'],
username=user.name) \
@ -172,7 +176,12 @@ class OpenStackAuthTests(test.TestCase):
username=user.name) \
.AndReturn(scoped)
client.Client(endpoint=settings.OPENSTACK_KEYSTONE_URL) \
client.Client(auth_url=settings.OPENSTACK_KEYSTONE_URL,
tenant_id=self.data.tenant_two.id,
token=sc.get_token()['id']) \
.AndReturn(self.keystone_client)
client.Client(endpoint=sc.url_for()) \
.AndReturn(self.keystone_client)
self.keystone_client.tokens.authenticate(tenant_id=tenant.id,

View File

@ -1,4 +1,5 @@
import hashlib
import logging
from django.contrib.auth.models import AnonymousUser
@ -8,6 +9,9 @@ from keystoneclient import exceptions as keystone_exceptions
from .utils import check_token_expiration, is_ans1_token
LOG = logging.getLogger(__name__)
def set_session_from_user(request, user):
if is_ans1_token(user.token.id):
hashed_token = hashlib.md5(user.token.id).hexdigest()
@ -117,11 +121,10 @@ class User(AnonymousUser):
client = keystone_client.Client(username=self.username,
auth_url=endpoint,
token=token.id)
authd = client.tenants.list()
self._authorized_tenants = client.tenants.list()
except (keystone_exceptions.ClientException,
keystone_exceptions.AuthorizationFailure):
authd = []
self._authorized_tenants = authd
LOG.exception('Unable to retrieve tenant list.')
return self._authorized_tenants or []
@authorized_tenants.setter

View File

@ -55,8 +55,9 @@ def login(request):
# will erase it if we set it earlier.
if request.user.is_authenticated():
set_session_from_user(request, request.user)
regions = dict(Login.get_region_choices())
region = request.user.endpoint
region_name = dict(Login.get_region_choices()).get(region)
region_name = regions.get(region)
request.session['region_endpoint'] = region
request.session['region_name'] = region_name
return res

View File

@ -43,7 +43,7 @@ setup(
zip_safe=False,
install_requires=[
'django >= 1.4',
'python-keystoneclient'
'python-keystoneclient >= 0.2'
],
tests_require=[
'mox',