@@ -77,25 +77,27 @@ def select_auth_plugin(options):
7777
7878 auth_plugin_name = None
7979
80- if options .os_auth_type in [plugin .name for plugin in get_plugin_list ()]:
81- # A direct plugin name was given, use it
82- return options .os_auth_type
83-
84- if options .os_url and options .os_token :
80+ # Do the token/url check first as this must override the default
81+ # 'password' set by os-client-config
82+ # Also, url and token are not copied into o-c-c's auth dict (yet?)
83+ if options .auth .get ('url' , None ) and options .auth .get ('token' , None ):
8584 # service token authentication
8685 auth_plugin_name = 'token_endpoint'
87- elif options .os_username :
88- if options .os_identity_api_version == '3' :
86+ elif options .auth_type in [plugin .name for plugin in PLUGIN_LIST ]:
87+ # A direct plugin name was given, use it
88+ auth_plugin_name = options .auth_type
89+ elif options .auth .get ('username' , None ):
90+ if options .identity_api_version == '3' :
8991 auth_plugin_name = 'v3password'
90- elif options .os_identity_api_version == '2.0' :
92+ elif options .identity_api_version . startswith ( '2' ) :
9193 auth_plugin_name = 'v2password'
9294 else :
9395 # let keystoneclient figure it out itself
9496 auth_plugin_name = 'osc_password'
95- elif options .os_token :
96- if options .os_identity_api_version == '3' :
97+ elif options .auth . get ( 'token' , None ) :
98+ if options .identity_api_version == '3' :
9799 auth_plugin_name = 'v3token'
98- elif options .os_identity_api_version == '2.0' :
100+ elif options .identity_api_version . startswith ( '2' ) :
99101 auth_plugin_name = 'v2token'
100102 else :
101103 # let keystoneclient figure it out itself
@@ -109,35 +111,27 @@ def select_auth_plugin(options):
109111
110112
111113def build_auth_params (auth_plugin_name , cmd_options ):
112- auth_params = {}
114+
115+ auth_params = dict (cmd_options .auth )
113116 if auth_plugin_name :
114117 LOG .debug ('auth_type: %s' , auth_plugin_name )
115118 auth_plugin_class = base .get_plugin_class (auth_plugin_name )
116- plugin_options = auth_plugin_class .get_options ()
117- for option in plugin_options :
118- option_name = 'os_' + option .dest
119- LOG .debug ('fetching option %s' % option_name )
120- auth_params [option .dest ] = getattr (cmd_options , option_name , None )
121119 # grab tenant from project for v2.0 API compatibility
122120 if auth_plugin_name .startswith ("v2" ):
123- auth_params ['tenant_id' ] = getattr (
124- cmd_options ,
125- 'os_project_id' ,
126- None ,
127- )
128- auth_params ['tenant_name' ] = getattr (
129- cmd_options ,
130- 'os_project_name' ,
131- None ,
132- )
121+ if 'project_id' in auth_params :
122+ auth_params ['tenant_id' ] = auth_params ['project_id' ]
123+ del auth_params ['project_id' ]
124+ if 'project_name' in auth_params :
125+ auth_params ['tenant_name' ] = auth_params ['project_name' ]
126+ del auth_params ['project_name' ]
133127 else :
134128 LOG .debug ('no auth_type' )
135129 # delay the plugin choice, grab every option
130+ auth_plugin_class = None
136131 plugin_options = set ([o .replace ('-' , '_' ) for o in get_options_list ()])
137132 for option in plugin_options :
138- option_name = 'os_' + option
139- LOG .debug ('fetching option %s' % option_name )
140- auth_params [option ] = getattr (cmd_options , option_name , None )
133+ LOG .debug ('fetching option %s' % option )
134+ auth_params [option ] = getattr (cmd_options .auth , option , None )
141135 return (auth_plugin_class , auth_params )
142136
143137
@@ -146,15 +140,29 @@ def check_valid_auth_options(options, auth_plugin_name):
146140
147141 msg = ''
148142 if auth_plugin_name .endswith ('password' ):
149- if not options .os_username :
150- msg += _ ('Set a username with --os-username or OS_USERNAME\n ' )
151- if not options .os_auth_url :
152- msg += _ ('Set an authentication URL, with --os-auth-url or'
153- ' OS_AUTH_URL\n ' )
154- if (not options .os_project_id and not options .os_domain_id and not
155- options .os_domain_name and not options .os_project_name ):
143+ if not options .auth .get ('username' , None ):
144+ msg += _ ('Set a username with --os-username, OS_USERNAME,'
145+ ' or auth.username\n ' )
146+ if not options .auth .get ('auth_url' , None ):
147+ msg += _ ('Set an authentication URL, with --os-auth-url,'
148+ ' OS_AUTH_URL or auth.auth_url\n ' )
149+ if (not options .auth .get ('project_id' , None ) and not
150+ options .auth .get ('domain_id' , None ) and not
151+ options .auth .get ('domain_name' , None ) and not
152+ options .auth .get ('project_name' , None )):
156153 msg += _ ('Set a scope, such as a project or domain, with '
157- '--os-project-name or OS_PROJECT_NAME' )
154+ '--os-project-name, OS_PROJECT_NAME or auth.project_name' )
155+ elif auth_plugin_name .endswith ('token' ):
156+ if not options .auth .get ('token' , None ):
157+ msg += _ ('Set a token with --os-token, OS_TOKEN or auth.token\n ' )
158+ if not options .auth .get ('auth_url' , None ):
159+ msg += _ ('Set a service AUTH_URL, with --os-auth-url, '
160+ 'OS_AUTH_URL or auth.auth_url\n ' )
161+ elif auth_plugin_name == 'token_endpoint' :
162+ if not options .auth .get ('token' , None ):
163+ msg += _ ('Set a token with --os-token, OS_TOKEN or auth.token\n ' )
164+ if not options .auth .get ('url' , None ):
165+ msg += _ ('Set a service URL, with --os-url, OS_URL or auth.url\n ' )
158166
159167 if msg :
160168 raise exc .CommandError ('Missing parameter(s): \n %s' % msg )
@@ -171,14 +179,15 @@ def build_auth_plugins_option_parser(parser):
171179 parser .add_argument (
172180 '--os-auth-type' ,
173181 metavar = '<auth-type>' ,
182+ dest = 'auth_type' ,
174183 default = utils .env ('OS_AUTH_TYPE' ),
175184 help = 'Select an auhentication type. Available types: ' +
176185 ', ' .join (available_plugins ) +
177186 '. Default: selected based on --os-username/--os-token' +
178187 ' (Env: OS_AUTH_TYPE)' ,
179188 choices = available_plugins
180189 )
181- # make sure we catch old v2.0 env values
190+ # Maintain compatibility with old tenant env vars
182191 envs = {
183192 'OS_PROJECT_NAME' : utils .env (
184193 'OS_PROJECT_NAME' ,
@@ -190,30 +199,33 @@ def build_auth_plugins_option_parser(parser):
190199 ),
191200 }
192201 for o in get_options_list ():
193- # remove allusion to tenants from v2.0 API
202+ # Remove tenant options from KSC plugins and replace them below
194203 if 'tenant' not in o :
195204 parser .add_argument (
196205 '--os-' + o ,
197206 metavar = '<auth-%s>' % o ,
198- default = envs .get (OPTIONS_LIST [o ]['env' ],
199- utils .env (OPTIONS_LIST [o ]['env' ])),
200- help = '%s\n (Env: %s)' % (OPTIONS_LIST [o ]['help' ],
201- OPTIONS_LIST [o ]['env' ]),
207+ dest = o .replace ('-' , '_' ),
208+ default = envs .get (
209+ OPTIONS_LIST [o ]['env' ],
210+ utils .env (OPTIONS_LIST [o ]['env' ]),
211+ ),
212+ help = '%s\n (Env: %s)' % (
213+ OPTIONS_LIST [o ]['help' ],
214+ OPTIONS_LIST [o ]['env' ],
215+ ),
202216 )
203217 # add tenant-related options for compatibility
204218 # this is deprecated but still used in some tempest tests...
205219 parser .add_argument (
206220 '--os-tenant-name' ,
207221 metavar = '<auth-tenant-name>' ,
208222 dest = 'os_project_name' ,
209- default = utils .env ('OS_TENANT_NAME' ),
210223 help = argparse .SUPPRESS ,
211224 )
212225 parser .add_argument (
213226 '--os-tenant-id' ,
214227 metavar = '<auth-tenant-id>' ,
215228 dest = 'os_project_id' ,
216- default = utils .env ('OS_TENANT_ID' ),
217229 help = argparse .SUPPRESS ,
218230 )
219231 return parser
0 commit comments