From 3227365bc66fdb2d8dbcdd8ccdee7a27aa058525 Mon Sep 17 00:00:00 2001 From: Timur Sufiev Date: Thu, 15 Oct 2015 13:33:25 +0300 Subject: Allow for manual setting of default service region in config In case DEFAULT_SERVICE_REGIONS setting in Horizon config is specified (on a per-endpoint basis), use it instead of a value stored in cookies. This value is still checked for sanity, i.e. it should be present in Keystone service catalog. Change-Id: Ia4787b56db7ce7787bd8aac21b5c0ec8a95a6f09 Related-Bug: #1506825 Closes-Bug: #1703390 --- openstack_auth/user.py | 5 ++++- openstack_auth/utils.py | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'openstack_auth') diff --git a/openstack_auth/user.py b/openstack_auth/user.py index 3edb204..063648b 100644 --- a/openstack_auth/user.py +++ b/openstack_auth/user.py @@ -43,8 +43,11 @@ def set_session_from_user(request, user): def create_user_from_token(request, token, endpoint, services_region=None): # if the region is provided, use that, otherwise use the preferred region + default_service_regions = getattr(settings, 'DEFAULT_SERVICE_REGIONS', {}) + default_service_region = default_service_regions.get(endpoint) svc_region = services_region or \ - utils.default_services_region(token.serviceCatalog, request) + utils.default_services_region(token.serviceCatalog, request, + selected_region=default_service_region) return User(id=token.user['id'], token=token, user=token.user['name'], diff --git a/openstack_auth/utils.py b/openstack_auth/utils.py index 3d49b7a..39ced4a 100644 --- a/openstack_auth/utils.py +++ b/openstack_auth/utils.py @@ -372,7 +372,8 @@ def get_project_list(*args, **kwargs): return projects -def default_services_region(service_catalog, request=None): +def default_services_region(service_catalog, request=None, + selected_region=None): """Returns the first endpoint region for first non-identity service. Extracted from the service catalog. @@ -396,8 +397,7 @@ def default_services_region(service_catalog, request=None): LOG.error('No regions can be found in the service catalog.') return None - selected_region = None - if request: + if request and selected_region is None: selected_region = request.COOKIES.get('services_region', available_regions[0]) if selected_region not in available_regions: -- cgit v1.2.1