Skip to content

Commit 099a2c3

Browse files
committed
Refactor setting defaults for some scope parameters
The code is setting defaults for some scope parameters, cheking if the name ends with some specific substring (namely ending in "password") causing failures in some plugins that end with the same string, but do not allow those parameters (like "user_domain_id" in "v3oidcpassword"). Closes-Bug: #1582774 Change-Id: Id7036db3b783b135353d035dc4c1df7c808d6474
1 parent 78ae571 commit 099a2c3

4 files changed

Lines changed: 53 additions & 37 deletions

File tree

openstackclient/api/auth.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,12 @@ def select_auth_plugin(options):
105105

106106
def build_auth_params(auth_plugin_name, cmd_options):
107107

108-
auth_params = dict(cmd_options.auth)
109108
if auth_plugin_name:
110109
LOG.debug('auth_type: %s', auth_plugin_name)
111110
auth_plugin_loader = base.get_plugin_loader(auth_plugin_name)
111+
auth_params = {opt.dest: opt.default
112+
for opt in base.get_plugin_options(auth_plugin_name)}
113+
auth_params.update(dict(cmd_options.auth))
112114
# grab tenant from project for v2.0 API compatibility
113115
if auth_plugin_name.startswith("v2"):
114116
if 'project_id' in auth_params:
@@ -121,6 +123,7 @@ def build_auth_params(auth_plugin_name, cmd_options):
121123
LOG.debug('no auth_type')
122124
# delay the plugin choice, grab every option
123125
auth_plugin_loader = None
126+
auth_params = dict(cmd_options.auth)
124127
plugin_options = set([o.replace('-', '_') for o in get_options_list()])
125128
for option in plugin_options:
126129
LOG.debug('fetching option %s', option)

openstackclient/api/auth_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class TokenEndpoint(token_endpoint.AdminToken):
3838
is for bootstrapping the Keystone database.
3939
"""
4040

41-
def load_from_options(self, url, token):
41+
def load_from_options(self, url, token, **kwargs):
4242
"""A plugin for static authentication with an existing token
4343
4444
:param string url: Service endpoint

openstackclient/common/clientmanager.py

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,49 @@ def __init__(
140140
# prior to dereferrencing auth_ref.
141141
self._auth_setup_completed = False
142142

143+
def _set_default_scope_options(self):
144+
# TODO(mordred): This is a usability improvement that's broadly useful
145+
# We should port it back up into os-client-config.
146+
default_domain = self._cli_options.default_domain
147+
148+
# NOTE(hieulq): If USER_DOMAIN_NAME, USER_DOMAIN_ID, PROJECT_DOMAIN_ID
149+
# or PROJECT_DOMAIN_NAME is present and API_VERSION is 2.0, then
150+
# ignore all domain related configs.
151+
if (self._api_version.get('identity') == '2.0' and
152+
self.auth_plugin_name.endswith('password')):
153+
domain_props = ['project_domain_name', 'project_domain_id',
154+
'user_domain_name', 'user_domain_id']
155+
for prop in domain_props:
156+
if self._auth_params.pop(prop, None) is not None:
157+
LOG.warning("Ignoring domain related configs " +
158+
prop + " because identity API version is 2.0")
159+
return
160+
161+
# NOTE(aloga): The scope parameters below only apply to v3 and v3
162+
# related auth plugins, so we stop the parameter checking if v2 is
163+
# being used.
164+
if (self._api_version.get('identity') != '3' or
165+
self.auth_plugin_name.startswith('v2')):
166+
return
167+
168+
# NOTE(stevemar): If PROJECT_DOMAIN_ID or PROJECT_DOMAIN_NAME is
169+
# present, then do not change the behaviour. Otherwise, set the
170+
# PROJECT_DOMAIN_ID to 'OS_DEFAULT_DOMAIN' for better usability.
171+
if ('project_domain_id' in self._auth_params and
172+
not self._auth_params.get('project_domain_id') and
173+
not self._auth_params.get('project_domain_name')):
174+
self._auth_params['project_domain_id'] = default_domain
175+
176+
# NOTE(stevemar): If USER_DOMAIN_ID or USER_DOMAIN_NAME is present,
177+
# then do not change the behaviour. Otherwise, set the
178+
# USER_DOMAIN_ID to 'OS_DEFAULT_DOMAIN' for better usability.
179+
if ('user_domain_id' in self._auth_params and
180+
not self._auth_params.get('user_domain_id') and
181+
not self._auth_params.get('user_domain_name')):
182+
self._auth_params['user_domain_id'] = default_domain
183+
143184
def setup_auth(self):
144-
"""Set up authentication.
185+
"""Set up authentication
145186
146187
This is deferred until authentication is actually attempted because
147188
it gets in the way of things that do not require auth.
@@ -169,40 +210,7 @@ def setup_auth(self):
169210
self._cli_options,
170211
)
171212

172-
# TODO(mordred): This is a usability improvement that's broadly useful
173-
# We should port it back up into os-client-config.
174-
default_domain = self._cli_options.default_domain
175-
# NOTE(stevemar): If PROJECT_DOMAIN_ID or PROJECT_DOMAIN_NAME is
176-
# present, then do not change the behaviour. Otherwise, set the
177-
# PROJECT_DOMAIN_ID to 'OS_DEFAULT_DOMAIN' for better usability.
178-
if (self._api_version.get('identity') == '3' and
179-
self.auth_plugin_name.endswith('password') and
180-
not self._auth_params.get('project_domain_id') and
181-
not self.auth_plugin_name.startswith('v2') and
182-
not self._auth_params.get('project_domain_name')):
183-
self._auth_params['project_domain_id'] = default_domain
184-
185-
# NOTE(stevemar): If USER_DOMAIN_ID or USER_DOMAIN_NAME is present,
186-
# then do not change the behaviour. Otherwise, set the USER_DOMAIN_ID
187-
# to 'OS_DEFAULT_DOMAIN' for better usability.
188-
if (self._api_version.get('identity') == '3' and
189-
self.auth_plugin_name.endswith('password') and
190-
not self.auth_plugin_name.startswith('v2') and
191-
not self._auth_params.get('user_domain_id') and
192-
not self._auth_params.get('user_domain_name')):
193-
self._auth_params['user_domain_id'] = default_domain
194-
195-
# NOTE(hieulq): If USER_DOMAIN_NAME, USER_DOMAIN_ID, PROJECT_DOMAIN_ID
196-
# or PROJECT_DOMAIN_NAME is present and API_VERSION is 2.0, then
197-
# ignore all domain related configs.
198-
if (self._api_version.get('identity') == '2.0' and
199-
self.auth_plugin_name.endswith('password')):
200-
domain_props = ['project_domain_name', 'project_domain_id',
201-
'user_domain_name', 'user_domain_id']
202-
for prop in domain_props:
203-
if self._auth_params.pop(prop, None) is not None:
204-
LOG.warning("Ignoring domain related configs " +
205-
prop + " because identity API version is 2.0")
213+
self._set_default_scope_options()
206214

207215
# For compatibility until all clients can be updated
208216
if 'project_name' in self._auth_params:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- Fix setting defaults for some scope parameters, that were putting invalid
4+
scope parameters for some auth plugins.
5+
[Bug `1582774 <https://bugs.launchpad.net/bugs/1582774>`_]

0 commit comments

Comments
 (0)