@@ -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 :
0 commit comments