Support switching project by name
This adds support to the switch_tenant url to switch project using project name. Change-Id: I2e8aecd9bf3151fb42a326d5b9aa28b98a2472d5
This commit is contained in:
parent
116bd8ccdf
commit
2e03e5d06f
|
@ -296,7 +296,8 @@ def clean_up_auth_url(auth_url):
|
|||
|
||||
|
||||
def get_token_auth_plugin(auth_url, token, project_id=None, domain_name=None,
|
||||
system_scope=None):
|
||||
system_scope=None, project_name=None,
|
||||
project_domain_id=None):
|
||||
if system_scope:
|
||||
return v3_auth.Token(auth_url=auth_url,
|
||||
token=token,
|
||||
|
@ -307,6 +308,12 @@ def get_token_auth_plugin(auth_url, token, project_id=None, domain_name=None,
|
|||
token=token,
|
||||
domain_name=domain_name,
|
||||
reauthenticate=False)
|
||||
if project_name and project_domain_id:
|
||||
return v3_auth.Token(auth_url=auth_url,
|
||||
token=token,
|
||||
project_name=project_name,
|
||||
project_domain_id=project_domain_id,
|
||||
reauthenticate=False)
|
||||
return v3_auth.Token(auth_url=auth_url,
|
||||
token=token,
|
||||
project_id=project_id,
|
||||
|
|
|
@ -37,6 +37,7 @@ from openstack_auth import forms
|
|||
from openstack_auth import plugin
|
||||
from openstack_auth import user as auth_user
|
||||
from openstack_auth import utils
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -282,9 +283,16 @@ def switch(request, tenant_id, redirect_field_name=auth.REDIRECT_FIELD_NAME):
|
|||
# another token. Always use the unscoped token for requesting a
|
||||
# scoped token.
|
||||
unscoped_token = request.user.unscoped_token
|
||||
auth = utils.get_token_auth_plugin(auth_url=endpoint,
|
||||
token=unscoped_token,
|
||||
project_id=tenant_id)
|
||||
if uuidutils.is_uuid_like(tenant_id):
|
||||
auth = utils.get_token_auth_plugin(auth_url=endpoint,
|
||||
token=unscoped_token,
|
||||
project_id=tenant_id)
|
||||
else:
|
||||
domain = request.user.token.project['domain_id']
|
||||
auth = utils.get_token_auth_plugin(auth_url=endpoint,
|
||||
token=unscoped_token,
|
||||
project_name=tenant_id,
|
||||
project_domain_id=domain)
|
||||
|
||||
try:
|
||||
auth_ref = auth.get_access(session)
|
||||
|
|
Loading…
Reference in New Issue