diff options
author | Jenkins <jenkins@review.openstack.org> | 2017-07-20 11:48:37 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2017-07-20 11:48:37 +0000 |
commit | acd690ae6c3c2e242c0c200ebac96c615a355d69 (patch) | |
tree | 22cf0efc31d62fc76468c4aad0844e29b340b314 | |
parent | c6c8982fc1c65eb174ed72a548eb2a5691a91db4 (diff) | |
parent | 3227365bc66fdb2d8dbcdd8ccdee7a27aa058525 (diff) |
Merge "Allow for manual setting of default service region in config"
-rw-r--r-- | doc/source/configuration/index.rst | 22 | ||||
-rw-r--r-- | openstack_auth/user.py | 5 | ||||
-rw-r--r-- | openstack_auth/utils.py | 6 |
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. | |||
37 | You should also define ``OPENSTACK_KEYSTONE_URL`` to indicate which of | 37 | You should also define ``OPENSTACK_KEYSTONE_URL`` to indicate which of |
38 | the regions is the default one. | 38 | the regions is the default one. |
39 | 39 | ||
40 | |||
41 | ``DEFAULT_SERVICE_REGIONS`` | ||
42 | --------------------------- | ||
43 | |||
44 | Default: ``{}`` | ||
45 | |||
46 | The default service region is set on a per-endpoint basis, meaning that once | ||
47 | the user logs into some Keystone endpoint, if a default service region is | ||
48 | defined for it in this setting and exists within Keystone catalog, it will be | ||
49 | set as the initial service region in this endpoint. By default it is an empty | ||
50 | dictionary because upstream can neither predict service region names in a | ||
51 | specific deployment, nor tell whether this behavior is desired. The key of the | ||
52 | dictionary is a full url of a Keystone endpoint with version suffix, the value | ||
53 | is a region name. | ||
54 | |||
55 | Example:: | ||
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 | ||
44 | def create_user_from_token(request, token, endpoint, services_region=None): | 44 | def 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 d38d513..cac0d7a 100644 --- a/openstack_auth/utils.py +++ b/openstack_auth/utils.py | |||
@@ -375,7 +375,8 @@ def get_project_list(*args, **kwargs): | |||
375 | return projects | 375 | return projects |
376 | 376 | ||
377 | 377 | ||
378 | def default_services_region(service_catalog, request=None): | 378 | def default_services_region(service_catalog, request=None, |
379 | selected_region=None): | ||
379 | """Returns the first endpoint region for first non-identity service. | 380 | """Returns the first endpoint region for first non-identity service. |
380 | 381 | ||
381 | Extracted from the service catalog. | 382 | Extracted from the service catalog. |
@@ -399,8 +400,7 @@ def default_services_region(service_catalog, request=None): | |||
399 | LOG.error('No regions can be found in the service catalog.') | 400 | LOG.error('No regions can be found in the service catalog.') |
400 | return None | 401 | return None |
401 | 402 | ||
402 | selected_region = None | 403 | if request and selected_region is None: |
403 | if request: | ||
404 | selected_region = request.COOKIES.get('services_region', | 404 | selected_region = request.COOKIES.get('services_region', |
405 | available_regions[0]) | 405 | available_regions[0]) |
406 | if selected_region not in available_regions: | 406 | if selected_region not in available_regions: |