Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 import json | |
|
Vadim Sh.
2013/12/03 01:33:41
nit: Copyright (or license header, don't know...).
Ryan Tseng
2013/12/03 22:57:11
Done.
| |
| 2 import getpass | |
| 3 import os | |
| 4 import re | |
| 5 import urllib2 | |
| 6 import subprocess | |
| 7 | |
| 8 from boto.auth_handler import AuthHandler | |
| 9 from boto.auth_handler import NotReadyToAuthenticate | |
| 10 | |
| 11 CMD = ['stubby', '--proto2', 'call', 'blade:sso', 'CorpLogin.Exchange'] | |
|
Vadim Sh.
2013/12/03 01:33:41
nit: newline after CMD
Ryan Tseng
2013/12/03 22:57:11
Done.
| |
| 12 STUBBY_CMD = """target: { | |
| 13 scope: GAIA_USER | |
| 14 name: "%s" | |
| 15 } | |
| 16 target_credential: { | |
| 17 type: OAUTH2_TOKEN | |
| 18 oauth2_attributes: { | |
| 19 scope: 'https://www.googleapis.com/auth/devstorage.read_only' | |
| 20 } | |
| 21 }""" | |
| 22 | |
| 23 | |
| 24 class SSOAuth(AuthHandler): | |
| 25 """SSO based auth handler.""" | |
| 26 | |
| 27 capability = ['google-oauth2', 's3'] | |
|
Vadim Sh.
2013/12/03 01:33:41
Is 's3' necessary here?..
Ryan Tseng
2013/12/03 22:57:11
Actually it is, for some reason this doesn't get a
| |
| 28 | |
| 29 def __init__(self, path, config, provider): | |
| 30 if provider.name == 'google' and self.has_prodaccess(): | |
| 31 # If we don't have a loas token, then bypass this auth handler. | |
| 32 if subprocess.call('loas_check', | |
| 33 stdout=subprocess.PIPE, | |
| 34 stderr=subprocess.PIPE): | |
| 35 raise NotReadyToAuthenticate() | |
| 36 pass | |
|
Vadim Sh.
2013/12/03 01:33:41
nit: remove 'pass', it looks odd..
Ryan Tseng
2013/12/03 22:57:11
Done.
| |
| 37 else: | |
| 38 raise NotReadyToAuthenticate() | |
| 39 | |
| 40 def GetAccessToken(self): | |
|
Vadim Sh.
2013/12/03 01:33:41
How often is this called? Does it make sense to ca
Ryan Tseng
2013/12/03 22:57:11
Implemented some simple in-memory + filesystem cac
| |
| 41 username = '%s@google.com' % getpass.getuser() | |
| 42 proc = subprocess.Popen(CMD, stdin=subprocess.PIPE, stdout=subprocess.PIPE) | |
| 43 out, err = proc.communicate(STUBBY_CMD % username) | |
| 44 token_match = re.search(r'oauth2_token: "(.*)"$', out) | |
|
Vadim Sh.
2013/12/03 01:33:41
Check process exit code before parsing its output?
Ryan Tseng
2013/12/03 22:57:11
Done.
| |
| 45 if token_match: | |
| 46 return token_match.group(1) | |
| 47 return None | |
|
Vadim Sh.
2013/12/03 01:33:41
Raise some exception instead of returning None. It
Ryan Tseng
2013/12/03 22:57:11
Done.
| |
| 48 | |
| 49 def add_auth(self, http_request): | |
| 50 http_request.headers['Authorization'] = ( | |
| 51 'OAuth %s' % self.GetAccessToken()) | |
|
Vadim Sh.
2013/12/03 01:33:41
nit: is new line required? looks like it can fit o
Ryan Tseng
2013/12/03 22:57:11
Done.
| |
| 52 | |
| 53 @staticmethod | |
| 54 def has_prodaccess(): | |
| 55 for path in os.environ["PATH"].split(os.pathsep): | |
|
Vadim Sh.
2013/12/03 01:33:41
nit: single quote 'PATH'
Ryan Tseng
2013/12/03 22:57:11
Done.
| |
| 56 exe_file = os.path.join(path, 'prodaccess') | |
| 57 if os.path.exists(exe_file) and os.access(exe_file, os.X_OK): | |
| 58 return True | |
| 59 return False | |
| OLD | NEW |