| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """AuthHandler plugin for gsutil's boto to support LOAS based auth.""" | 5 """AuthHandler plugin for gsutil's boto to support LOAS based auth.""" |
| 6 | 6 |
| 7 import getpass | 7 import getpass |
| 8 import json | 8 import json |
| 9 import os | 9 import os |
| 10 import re | 10 import re |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 | 39 |
| 40 class SSOAuth(AuthHandler): | 40 class SSOAuth(AuthHandler): |
| 41 """SSO based auth handler.""" | 41 """SSO based auth handler.""" |
| 42 | 42 |
| 43 capability = ['google-oauth2', 's3'] | 43 capability = ['google-oauth2', 's3'] |
| 44 | 44 |
| 45 def __init__(self, path, config, provider): | 45 def __init__(self, path, config, provider): |
| 46 if provider.name == 'google' and self.has_prodaccess(): | 46 if provider.name == 'google' and self.has_prodaccess(): |
| 47 # If we don't have a loas token, then bypass this auth handler. | 47 # If we don't have a loas token, then bypass this auth handler. |
| 48 if subprocess.call('loas_check', | 48 if subprocess.call(['loas_check', '-loas_check_retry_attempts=0'], |
| 49 stdout=subprocess.PIPE, | 49 stdout=subprocess.PIPE, |
| 50 stderr=subprocess.PIPE): | 50 stderr=subprocess.PIPE): |
| 51 raise NotReadyToAuthenticate() | 51 raise NotReadyToAuthenticate() |
| 52 else: | 52 else: |
| 53 raise NotReadyToAuthenticate() | 53 raise NotReadyToAuthenticate() |
| 54 self.token = None | 54 self.token = None |
| 55 self.expire = 0 | 55 self.expire = 0 |
| 56 | 56 |
| 57 def GetAccessToken(self): | 57 def GetAccessToken(self): |
| 58 """Returns a valid devstore access token. | 58 """Returns a valid devstore access token. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 def add_auth(self, http_request): | 96 def add_auth(self, http_request): |
| 97 http_request.headers['Authorization'] = 'OAuth %s' % self.GetAccessToken() | 97 http_request.headers['Authorization'] = 'OAuth %s' % self.GetAccessToken() |
| 98 | 98 |
| 99 @staticmethod | 99 @staticmethod |
| 100 def has_prodaccess(): | 100 def has_prodaccess(): |
| 101 for path in os.environ['PATH'].split(os.pathsep): | 101 for path in os.environ['PATH'].split(os.pathsep): |
| 102 exe_file = os.path.join(path, 'prodaccess') | 102 exe_file = os.path.join(path, 'prodaccess') |
| 103 if os.path.exists(exe_file) and os.access(exe_file, os.X_OK): | 103 if os.path.exists(exe_file) and os.access(exe_file, os.X_OK): |
| 104 return True | 104 return True |
| 105 return False | 105 return False |
| OLD | NEW |