X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Ftools%2Fswarming_client%2Fauth.py;h=40703c5109207dc774e87a97bc92ce8e3b121209;hb=ff3e2503a20db9193d323c1d19c38c68004dec4a;hp=f7f4b44e458dc8997a0d8801d0a86c1fd516b875;hpb=7338fba38ba696536d1cc9d389afd716a6ab2fe6;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/tools/swarming_client/auth.py b/src/tools/swarming_client/auth.py index f7f4b44..40703c5 100755 --- a/src/tools/swarming_client/auth.py +++ b/src/tools/swarming_client/auth.py @@ -23,16 +23,20 @@ def add_auth_options(parser): """Adds command line options related to authentication.""" parser.auth_group = optparse.OptionGroup(parser, 'Authentication') parser.auth_group.add_option( - '--use-cookie-auth', action='store_true', - help='Use cookie-based authentication instead of OAuth.') + '--auth-method', + metavar='METHOD', + default='bot' if tools.is_headless() else 'oauth', + help='Authentication method to use: %s. [default: %%default]' % + ', '.join(net.AUTH_METHODS)) parser.add_option_group(parser.auth_group) oauth.add_oauth_options(parser) -def process_auth_options(options): +def process_auth_options(parser, options): """Configures process-wide authentication parameters based on |options|.""" - method = 'cookie' if options.use_cookie_auth else 'oauth' - net.configure_auth(method, oauth_options=options) + if options.auth_method not in net.AUTH_METHODS: + parser.error('Invalid --auth-method value: %s' % options.auth_method) + net.configure_auth(options.auth_method, oauth_options=options) class AuthServiceError(Exception): @@ -45,9 +49,9 @@ class AuthService(object): def __init__(self, url): self._service = net.get_http_service(url) - def login(self): + def login(self, allow_user_interaction): """Refreshes cached access token or creates a new one.""" - return self._service.login() + return self._service.login(allow_user_interaction) def logout(self): """Purges cached access token.""" @@ -69,11 +73,11 @@ class AuthService(object): @subcommand.usage('[options]') def CMDlogin(parser, args): - """Refreshes short lived authentication token.""" + """Runs interactive login flow and stores auth token/cookie on disk.""" (options, args) = parser.parse_args(args) - process_auth_options(options) + process_auth_options(parser, options) service = AuthService(options.service) - if service.login(): + if service.login(True): print 'Logged in as \'%s\'.' % service.get_current_identity() return 0 else: @@ -83,20 +87,23 @@ def CMDlogin(parser, args): @subcommand.usage('[options]') def CMDlogout(parser, args): - """Purges cached credentials.""" + """Purges cached auth token/cookie.""" (options, args) = parser.parse_args(args) - process_auth_options(options) + process_auth_options(parser, options) service = AuthService(options.service) service.logout() + return 0 @subcommand.usage('[options]') def CMDcheck(parser, args): - """Shows identity associated with currently cached credentials.""" + """Shows identity associated with currently cached auth token/cookie.""" (options, args) = parser.parse_args(args) - process_auth_options(options) + process_auth_options(parser, options) service = AuthService(options.service) + service.login(False) print service.get_current_identity() + return 0 class OptionParserAuth(tools.OptionParserWithLogging):