Skip to content

Commit 3ae247f

Browse files
author
Jamie Lennox
committed
Set tenant options on parsed namespace
Because of the way OSC registers all plugins together we end up with os-tenant-X parameters being saved to the project-X attribute after parsing. If you are using the v2 plugins directly then they and os-client-config expect the tenant_X values and will assuming no scoping information if they are not present. Validating options for scope will also fail in this situation, not just because the resultant auth dictionary is missing the tenant-X attributes, but because OSC validates that either project or domain scope information is present. Fix this by just always setting the v2 parameters if the v3 parameters are present. This will have no effect on the generic or v3 case but fix the v2 case. Expand validation to include the tenant options so it knows that v2 plugins are scoped. Change-Id: I8cab3e423663f801cbf2d83106c671bddc58d7e6 Closes-Bug: #1460369
1 parent 211c14c commit 3ae247f

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

openstackclient/api/auth.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ def check_valid_auth_options(options, auth_plugin_name):
149149
if (not options.auth.get('project_id', None) and not
150150
options.auth.get('domain_id', None) and not
151151
options.auth.get('domain_name', None) and not
152-
options.auth.get('project_name', None)):
152+
options.auth.get('project_name', None) and not
153+
options.auth.get('tenant_id', None) and not
154+
options.auth.get('tenant_name', None)):
153155
msg += _('Set a scope, such as a project or domain, with '
154156
'--os-project-name, OS_PROJECT_NAME or auth.project_name')
155157
elif auth_plugin_name.endswith('token'):

openstackclient/common/clientmanager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def setup_auth(self):
139139
# PROJECT_DOMAIN_ID to 'OS_DEFAULT_DOMAIN' for better usability.
140140
if (self._api_version.get('identity') == '3' and
141141
not self._auth_params.get('project_domain_id', None) and
142+
not self.auth_plugin_name.startswith('v2') and
142143
not self._auth_params.get('project_domain_name', None)):
143144
self._auth_params['project_domain_id'] = default_domain
144145

@@ -147,6 +148,7 @@ def setup_auth(self):
147148
# to 'OS_DEFAULT_DOMAIN' for better usability.
148149
if (self._api_version.get('identity') == '3' and
149150
self.auth_plugin_name.endswith('password') and
151+
not self.auth_plugin_name.startswith('v2') and
150152
not self._auth_params.get('user_domain_id', None) and
151153
not self._auth_params.get('user_domain_name', None)):
152154
self._auth_params['user_domain_id'] = default_domain

openstackclient/shell.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,23 @@ def initialize_app(self, argv):
234234
cloud_config.set_default('auth_type', 'osc_password')
235235
self.log.debug("options: %s", self.options)
236236

237+
project_id = getattr(self.options, 'project_id', None)
238+
project_name = getattr(self.options, 'project_name', None)
239+
tenant_id = getattr(self.options, 'tenant_id', None)
240+
tenant_name = getattr(self.options, 'tenant_name', None)
241+
242+
# handle some v2/v3 authentication inconsistencies by just acting like
243+
# both the project and tenant information are both present. This can
244+
# go away if we stop registering all the argparse options together.
245+
if project_id and not tenant_id:
246+
self.options.tenant_id = project_id
247+
if project_name and not tenant_name:
248+
self.options.tenant_name = project_name
249+
if tenant_id and not project_id:
250+
self.options.project_id = tenant_id
251+
if tenant_name and not project_name:
252+
self.options.project_name = tenant_name
253+
237254
# Do configuration file handling
238255
cc = cloud_config.OpenStackConfig()
239256
self.log.debug("defaults: %s", cc.defaults)

0 commit comments

Comments
 (0)