@@ -59,6 +59,8 @@ def __init__(
5959 self ._interface = self .interface
6060 self ._cacert = self .cacert
6161 self ._insecure = not self .verify
62+ # store original auth_type
63+ self ._original_auth_type = cli_options .auth_type
6264
6365 def setup_auth (self ):
6466 """Set up authentication"""
@@ -73,12 +75,33 @@ def setup_auth(self):
7375 if self ._cli_options ._openstack_config is not None :
7476 self ._cli_options ._openstack_config ._pw_callback = \
7577 shell .prompt_for_password
78+ try :
79+ self ._cli_options ._auth = \
80+ self ._cli_options ._openstack_config .load_auth_plugin (
81+ self ._cli_options .config ,
82+ )
83+ except TypeError as e :
84+ self ._fallback_load_auth_plugin (e )
85+
86+ return super (ClientManager , self ).setup_auth ()
87+
88+ def _fallback_load_auth_plugin (self , e ):
89+ # NOTES(RuiChen): Hack to avoid auth plugins choking on data they don't
90+ # expect, delete fake token and endpoint, then try to
91+ # load auth plugin again with user specified options.
92+ # We know it looks ugly, but it's necessary.
93+ if self ._cli_options .config ['auth' ]['token' ] == 'x' :
94+ # restore original auth_type
95+ self ._cli_options .config ['auth_type' ] = \
96+ self ._original_auth_type
97+ del self ._cli_options .config ['auth' ]['token' ]
98+ del self ._cli_options .config ['auth' ]['endpoint' ]
7699 self ._cli_options ._auth = \
77100 self ._cli_options ._openstack_config .load_auth_plugin (
78101 self ._cli_options .config ,
79102 )
80-
81- return super ( ClientManager , self ). setup_auth ()
103+ else :
104+ raise e
82105
83106 def is_network_endpoint_enabled (self ):
84107 """Check if the network endpoint is enabled"""
0 commit comments