3636 invoke_on_load = False ,
3737 propagate_map_exceptions = True ,
3838)
39- # TODO(dtroyer): add some method to list the plugins for the
40- # --os_auth_plugin option
4139
4240# Get the command line options so the help action has them available
4341OPTIONS_LIST = {}
5654
5755
5856def select_auth_plugin (options ):
59- """If no auth plugin was specified, pick one based on other options"""
57+ """Pick an auth plugin based on --os-auth-type or other options"""
58+
59+ auth_plugin_name = None
60+
61+ if options .os_auth_type in [plugin .name for plugin in PLUGIN_LIST ]:
62+ # A direct plugin name was given, use it
63+ return options .os_auth_type
6064
61- auth_plugin = None
6265 if options .os_url and options .os_token :
6366 # service token authentication
64- auth_plugin = 'token_endpoint'
67+ auth_plugin_name = 'token_endpoint'
6568 elif options .os_username :
6669 if options .os_identity_api_version == '3' :
67- auth_plugin = 'v3password'
70+ auth_plugin_name = 'v3password'
6871 elif options .os_identity_api_version == '2.0' :
69- auth_plugin = 'v2password'
72+ auth_plugin_name = 'v2password'
7073 else :
7174 # let keystoneclient figure it out itself
72- auth_plugin = 'password'
75+ auth_plugin_name = 'password'
7376 elif options .os_token :
7477 if options .os_identity_api_version == '3' :
75- auth_plugin = 'v3token'
78+ auth_plugin_name = 'v3token'
7679 elif options .os_identity_api_version == '2.0' :
77- auth_plugin = 'v2token'
80+ auth_plugin_name = 'v2token'
7881 else :
7982 # let keystoneclient figure it out itself
80- auth_plugin = 'token'
83+ auth_plugin_name = 'token'
8184 else :
8285 raise exc .CommandError (
83- "Could not figure out which authentication method "
84- "to use, please set --os-auth-plugin"
86+ "Authentication type must be selected with --os-auth-type"
8587 )
86- LOG .debug ("No auth plugin selected, picking %s from other "
87- "options" % auth_plugin )
88- return auth_plugin
88+ LOG .debug ("Auth plugin %s selected" % auth_plugin_name )
89+ return auth_plugin_name
8990
9091
91- def build_auth_params (cmd_options ):
92+ def build_auth_params (auth_plugin_name , cmd_options ):
9293 auth_params = {}
93- if cmd_options . os_auth_plugin :
94- LOG .debug ('auth_plugin : %s' , cmd_options . os_auth_plugin )
95- auth_plugin = base .get_plugin_class (cmd_options . os_auth_plugin )
96- plugin_options = auth_plugin .get_options ()
94+ if auth_plugin_name :
95+ LOG .debug ('auth_type : %s' , auth_plugin_name )
96+ auth_plugin_class = base .get_plugin_class (auth_plugin_name )
97+ plugin_options = auth_plugin_class .get_options ()
9798 for option in plugin_options :
9899 option_name = 'os_' + option .dest
99100 LOG .debug ('fetching option %s' % option_name )
100101 auth_params [option .dest ] = getattr (cmd_options , option_name , None )
101102 # grab tenant from project for v2.0 API compatibility
102- if cmd_options . os_auth_plugin .startswith ("v2" ):
103+ if auth_plugin_name .startswith ("v2" ):
103104 auth_params ['tenant_id' ] = getattr (
104105 cmd_options ,
105106 'os_project_id' ,
@@ -111,14 +112,14 @@ def build_auth_params(cmd_options):
111112 None ,
112113 )
113114 else :
114- LOG .debug ('no auth_plugin ' )
115+ LOG .debug ('no auth_type ' )
115116 # delay the plugin choice, grab every option
116117 plugin_options = set ([o .replace ('-' , '_' ) for o in OPTIONS_LIST ])
117118 for option in plugin_options :
118119 option_name = 'os_' + option
119120 LOG .debug ('fetching option %s' % option_name )
120121 auth_params [option ] = getattr (cmd_options , option_name , None )
121- return auth_params
122+ return ( auth_plugin_class , auth_params )
122123
123124
124125def build_auth_plugins_option_parser (parser ):
@@ -130,15 +131,12 @@ def build_auth_plugins_option_parser(parser):
130131 """
131132 available_plugins = [plugin .name for plugin in PLUGIN_LIST ]
132133 parser .add_argument (
133- '--os-auth-plugin' ,
134- metavar = '<OS_AUTH_PLUGIN>' ,
135- default = utils .env ('OS_AUTH_PLUGIN' ),
136- help = 'The authentication method to use. If this option is not set, '
137- 'openstackclient will attempt to guess the authentication method '
138- 'to use based on the other options. If this option is set, '
139- 'the --os-identity-api-version argument must be consistent '
140- 'with the version of the method.\n Available methods are ' +
141- ', ' .join (available_plugins ),
134+ '--os-auth-type' ,
135+ metavar = '<auth-type>' ,
136+ default = utils .env ('OS_AUTH_TYPE' ),
137+ help = 'Select an auhentication type. Available types: ' +
138+ ', ' .join (available_plugins ) +
139+ '. Default: selected based on --os-username/--os-token' ,
142140 choices = available_plugins
143141 )
144142 # make sur we catch old v2.0 env values
0 commit comments