| OLD | NEW |
| (Empty) |
| 1 from boto.auth_handler import AuthHandler | |
| 2 from boto.auth_handler import NotReadyToAuthenticate | |
| 3 import oauth2_client | |
| 4 import oauth2_helper | |
| 5 from gslib.cred_types import CredTypes | |
| 6 | |
| 7 IS_SERVICE_ACCOUNT = False | |
| 8 | |
| 9 class OAuth2Auth(AuthHandler): | |
| 10 | |
| 11 capability = ['google-oauth2', 's3'] | |
| 12 | |
| 13 def __init__(self, path, config, provider): | |
| 14 if (provider.name == 'google' | |
| 15 and config.has_option('Credentials', 'gs_oauth2_refresh_token')): | |
| 16 self.oauth2_client = oauth2_helper.OAuth2ClientFromBotoConfig(config) | |
| 17 else: | |
| 18 raise NotReadyToAuthenticate() | |
| 19 | |
| 20 def add_auth(self, http_request): | |
| 21 http_request.headers['Authorization'] = \ | |
| 22 self.oauth2_client.GetAuthorizationHeader() | |
| 23 | |
| 24 class OAuth2ServiceAccountAuth(AuthHandler): | |
| 25 | |
| 26 capability = ['google-oauth2', 's3'] | |
| 27 | |
| 28 def __init__(self, path, config, provider): | |
| 29 if (provider.name == 'google' | |
| 30 and config.has_option('Credentials', 'gs_service_client_id') | |
| 31 and config.has_option('Credentials', 'gs_service_key_file')): | |
| 32 self.oauth2_client = oauth2_helper.OAuth2ClientFromBotoConfig(config, | |
| 33 cred_type=CredTypes.OAUTH2_SERVICE_ACCOUNT) | |
| 34 | |
| 35 # If we make it to this point, then we will later attempt to authenticate | |
| 36 # as a service account based on how the boto auth plugins work. This is | |
| 37 # global so that command.py can access this value once it's set. | |
| 38 # TODO: replace this approach with a way to get the current plugin | |
| 39 # from boto so that we don't have to have global variables. | |
| 40 global IS_SERVICE_ACCOUNT | |
| 41 IS_SERVICE_ACCOUNT = True | |
| 42 else: | |
| 43 raise NotReadyToAuthenticate() | |
| 44 | |
| 45 def add_auth(self, http_request): | |
| 46 http_request.headers['Authorization'] = \ | |
| 47 self.oauth2_client.GetAuthorizationHeader() | |
| 48 | |
| OLD | NEW |