Skip to content

Commit 1d75edb

Browse files
author
Steve Martinelli
committed
Default user domain id and project domain id
If either of OS_USER_DOMAIN_ID or OS_USER_DOMAIN_NAME are present then we don't tinker with anything. Otherwise, we should set the USER_DOMAIN_ID to 'OS_DEFAULT_DOMAIN', as this provides a better UX, since the end user doesn't have to specify these arguments. Same logic applies for OS_PROJECT_DOMAIN_ID. Closes-Bug: #1385338 Change-Id: I8a4034c16a1dd50d269f809abab8e960d5de20f7
1 parent 9057ced commit 1d75edb

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

examples/common.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ def base_parser(parser):
102102
default=env('OS_CACERT'),
103103
help='CA certificate bundle file (Env: OS_CACERT)',
104104
)
105+
parser.add_argument(
106+
'--os-default-domain',
107+
metavar='<auth-domain>',
108+
default='default',
109+
help='Default domain ID, default=default (Env: OS_DEFAULT_DOMAIN)',
110+
)
105111
verify_group = parser.add_mutually_exclusive_group()
106112
verify_group.add_argument(
107113
'--verify',

openstackclient/common/clientmanager.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,23 @@ def __init__(
9898
self._auth_ref = None
9999
self.timing = auth_options.timing
100100

101+
default_domain = auth_options.os_default_domain
102+
# NOTE(stevemar): If PROJECT_DOMAIN_ID or PROJECT_DOMAIN_NAME is
103+
# present, then do not change the behaviour. Otherwise, set the
104+
# PROJECT_DOMAIN_ID to 'OS_DEFAULT_DOMAIN' for better usability.
105+
if (self._api_version.get('identity') == '3' and
106+
not self._auth_params.get('project_domain_id') and
107+
not self._auth_params.get('project_domain_name')):
108+
self._auth_params['project_domain_id'] = default_domain
109+
110+
# NOTE(stevemar): If USER_DOMAIN_ID or USER_DOMAIN_NAME is present,
111+
# then do not change the behaviour. Otherwise, set the USER_DOMAIN_ID
112+
# to 'OS_DEFAULT_DOMAIN' for better usability.
113+
if (self._api_version.get('identity') == '3' and
114+
not self._auth_params.get('user_domain_id') and
115+
not self._auth_params.get('user_domain_name')):
116+
self._auth_params['user_domain_id'] = default_domain
117+
101118
# For compatibility until all clients can be updated
102119
if 'project_name' in self._auth_params:
103120
self._project_name = self._auth_params['project_name']

openstackclient/tests/common/test_clientmanager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def __init__(self, **kwargs):
4949
self.timing = None
5050
self.os_region_name = None
5151
self.os_url = None
52+
self.os_default_domain = 'default'
5253
self.__dict__.update(kwargs)
5354

5455

0 commit comments

Comments
 (0)