summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimur Sufiev <tsufiev@mirantis.com>2015-10-15 13:33:25 +0300
committerJiří Suchomel <jiri.suchomel@suse.com>2017-07-10 16:27:20 +0200
commit3227365bc66fdb2d8dbcdd8ccdee7a27aa058525 (patch)
treec752c05279dadf536b9ac77a6dd499ce78605d09
parentc15dfe5acd58efa0c5c27dd19de5d4ef2a880c36 (diff)
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
Notes
Notes (review): Code-Review+1: Itxaka Serrano Garcia <igarcia@suse.com> Code-Review+2: Rob Cresswell <robert.cresswell@outlook.com> Workflow+1: Rob Cresswell <robert.cresswell@outlook.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Thu, 20 Jul 2017 11:48:37 +0000 Reviewed-on: https://review.openstack.org/478397 Project: openstack/django_openstack_auth Branch: refs/heads/master
-rw-r--r--doc/source/configuration/index.rst22
-rw-r--r--openstack_auth/user.py5
-rw-r--r--openstack_auth/utils.py6
3 files changed, 29 insertions, 4 deletions
diff --git a/doc/source/configuration/index.rst b/doc/source/configuration/index.rst
index 26c272b..5b581b0 100644
--- a/doc/source/configuration/index.rst
+++ b/doc/source/configuration/index.rst
@@ -37,6 +37,28 @@ the site header when logged in.
37You should also define ``OPENSTACK_KEYSTONE_URL`` to indicate which of 37You should also define ``OPENSTACK_KEYSTONE_URL`` to indicate which of
38the regions is the default one. 38the regions is the default one.
39 39
40
41``DEFAULT_SERVICE_REGIONS``
42---------------------------
43
44Default: ``{}``
45
46The default service region is set on a per-endpoint basis, meaning that once
47the user logs into some Keystone endpoint, if a default service region is
48defined for it in this setting and exists within Keystone catalog, it will be
49set as the initial service region in this endpoint. By default it is an empty
50dictionary because upstream can neither predict service region names in a
51specific deployment, nor tell whether this behavior is desired. The key of the
52dictionary is a full url of a Keystone endpoint with version suffix, the value
53is a region name.
54
55Example::
56
57 DEFAULT_SERVICE_REGIONS = {
58 OPENSTACK_KEYSTONE_URL: 'RegionOne'
59 }
60
61
40``OPENSTACK_API_VERSIONS`` 62``OPENSTACK_API_VERSIONS``
41-------------------------- 63--------------------------
42 64
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):
43 43
44def create_user_from_token(request, token, endpoint, services_region=None): 44def create_user_from_token(request, token, endpoint, services_region=None):
45 # if the region is provided, use that, otherwise use the preferred region 45 # if the region is provided, use that, otherwise use the preferred region
46 default_service_regions = getattr(settings, 'DEFAULT_SERVICE_REGIONS', {})
47 default_service_region = default_service_regions.get(endpoint)
46 svc_region = services_region or \ 48 svc_region = services_region or \
47 utils.default_services_region(token.serviceCatalog, request) 49 utils.default_services_region(token.serviceCatalog, request,
50 selected_region=default_service_region)
48 return User(id=token.user['id'], 51 return User(id=token.user['id'],
49 token=token, 52 token=token,
50 user=token.user['name'], 53 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):
372 return projects 372 return projects
373 373
374 374
375def default_services_region(service_catalog, request=None): 375def default_services_region(service_catalog, request=None,
376 selected_region=None):
376 """Returns the first endpoint region for first non-identity service. 377 """Returns the first endpoint region for first non-identity service.
377 378
378 Extracted from the service catalog. 379 Extracted from the service catalog.
@@ -396,8 +397,7 @@ def default_services_region(service_catalog, request=None):
396 LOG.error('No regions can be found in the service catalog.') 397 LOG.error('No regions can be found in the service catalog.')
397 return None 398 return None
398 399
399 selected_region = None 400 if request and selected_region is None:
400 if request:
401 selected_region = request.COOKIES.get('services_region', 401 selected_region = request.COOKIES.get('services_region',
402 available_regions[0]) 402 available_regions[0])
403 if selected_region not in available_regions: 403 if selected_region not in available_regions: