@@ -328,6 +328,10 @@ def build_option_parser(self, description, version):
328328 help = 'Trust ID to use when authenticating. '
329329 'This can only be used with Keystone v3 API '
330330 '(Env: OS_TRUST_ID)' )
331+ parser .add_argument ('--federated' , '-F' ,
332+ dest = "federated" ,
333+ action = 'store_true' ,
334+ help = "Login via Federated Authentication" )
331335
332336 return parser
333337
@@ -348,13 +352,34 @@ def authenticate_user(self):
348352 " either --os-url or env[OS_URL]" )
349353
350354 else :
351- # Validate password flow auth
352- if not self .options .os_username :
353- raise exc .CommandError (
354- "You must provide a username via"
355- " either --os-username or env[OS_USERNAME]" )
355+ if self .options .federated :
356+ #check for an environment variable and a valid v3 auth_url
357+ if "OS_IDENTITY_API_VERSION" in os .environ :
358+ if os .environ .get ('OS_IDENTITY_API_VERSION' ) != '3' \
359+ or 'v2' in self .options .os_auth_url \
360+ or 'V2' in self .options .os_auth_url :
361+ raise exc .CommandError (
362+ "Federated authentication has only been, "
363+ "configured to work with the v3 API "
364+ "you must set env[OS_IDENTITY_API_VERSION]=3 "
365+ "and target a v3 Keystone endpoint." )
366+ else :
367+ raise exc .CommandError (
368+ "If using Federated authentication,"
369+ " you must set env[OS_IDENTITY_API_VERSION]=3 " )
370+ if not self .options .os_auth_url :
371+ raise exc .CommandError (
372+ "If using Federated authentication,"
373+ " you must specify an endpoint with "
374+ "--os-auth-url" )
375+ else :
376+ # Validate password flow auth
377+ if not self .options .os_username :
378+ raise exc .CommandError (
379+ "You must provide a username via"
380+ " either --os-username or env[OS_USERNAME]" )
356381
357- if not self .options .os_password :
382+ if not self .options .os_password and not self . options . federated :
358383 # No password, if we've got a tty, try prompting for it
359384 if hasattr (sys .stdin , 'isatty' ) and sys .stdin .isatty ():
360385 # Check for Ctl-D
@@ -365,23 +390,38 @@ def authenticate_user(self):
365390 # No password because we did't have a tty or the
366391 # user Ctl-D when prompted?
367392 if not self .options .os_password :
393+ # No password, if we've got a tty, try prompting for it
394+ if hasattr (sys .stdin , 'isatty' ) and sys .stdin .isatty ():
395+ # Check for Ctl-D
396+ try :
397+ self .options .os_password = getpass .getpass ()
398+ except EOFError :
399+ pass
400+ # No password because we did't have a tty or the
401+ # user Ctl-D when prompted?
402+ if not self .options .os_password :
403+ raise exc .CommandError (
404+ "You must provide a password via"
405+ " either --os-password, or env[OS_PASSWORD], "
406+ " or prompted response" )
407+
408+ if not ((self .options .os_project_id
409+ or self .options .os_project_name ) or
410+ (self .options .os_domain_id
411+ or self .options .os_domain_name ) or
412+ self .options .os_trust_id ):
368413 raise exc .CommandError (
369- "You must provide a password via"
370- " either --os-password, or env[OS_PASSWORD], "
371- " or prompted response" )
372-
373- if not ((self .options .os_project_id
374- or self .options .os_project_name ) or
375- (self .options .os_domain_id
376- or self .options .os_domain_name ) or
377- self .options .os_trust_id ):
378- raise exc .CommandError (
379- "You must provide authentication scope as a project "
380- "or a domain via --os-project-id or env[OS_PROJECT_ID], "
381- "--os-project-name or env[OS_PROJECT_NAME], "
382- "--os-domain-id or env[OS_DOMAIN_ID], or"
383- "--os-domain-name or env[OS_DOMAIN_NAME], or "
384- "--os-trust-id or env[OS_TRUST_ID]." )
414+ "You must provide authentication scope as a project "
415+ "or a domain via --os-project-id or env[OS_PROJECT_ID], "
416+ "--os-project-name or env[OS_PROJECT_NAME], "
417+ "--os-domain-id or env[OS_DOMAIN_ID], or"
418+ "--os-domain-name or env[OS_DOMAIN_NAME], or "
419+ "--os-trust-id or env[OS_TRUST_ID]." )
420+
421+ if not self .options .os_auth_url :
422+ raise exc .CommandError (
423+ "You must provide an auth url via"
424+ " either --os-auth-url or via env[OS_AUTH_URL]" )
385425
386426 if not self .options .os_auth_url :
387427 raise exc .CommandError (
@@ -421,6 +461,7 @@ def authenticate_user(self):
421461 timing = self .options .timing ,
422462 api_version = self .api_version ,
423463 trust_id = self .options .os_trust_id ,
464+ federated = self .options .federated
424465 )
425466 return
426467
0 commit comments