Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: third_party/gcs-oauth2-boto-plugin/gcs_oauth2_boto_plugin/oauth2_plugin.py

Issue 698893003: Update checked in version of gsutil to version 4.6 (Closed) Base URL: http://dart.googlecode.com/svn/third_party/gsutil/
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 # Copyright 2014 Google Inc. All Rights Reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 """Boto auth plugin for OAuth2.0 for Google Cloud Storage."""
16
17 from __future__ import absolute_import
18
19 from boto.auth_handler import AuthHandler
20 from boto.auth_handler import NotReadyToAuthenticate
21
22 from gcs_oauth2_boto_plugin import oauth2_client
23 from gcs_oauth2_boto_plugin import oauth2_helper
24
25 IS_SERVICE_ACCOUNT = False
26
27
28 class OAuth2Auth(AuthHandler):
29
30 capability = ['google-oauth2', 's3']
31
32 def __init__(self, path, config, provider):
33 self.oauth2_client = None
34 if (provider.name == 'google'):
35 if config.has_option('Credentials', 'gs_oauth2_refresh_token'):
36 self.oauth2_client = oauth2_helper.OAuth2ClientFromBotoConfig(config)
37 elif config.has_option('GoogleCompute', 'service_account'):
38 self.oauth2_client = oauth2_client.CreateOAuth2GCEClient()
39 if not self.oauth2_client:
40 raise NotReadyToAuthenticate()
41
42 def add_auth(self, http_request):
43 http_request.headers['Authorization'] = \
44 self.oauth2_client.GetAuthorizationHeader()
45
46
47 class OAuth2ServiceAccountAuth(AuthHandler):
48
49 capability = ['google-oauth2', 's3']
50
51 def __init__(self, path, config, provider):
52 if (provider.name == 'google'
53 and config.has_option('Credentials', 'gs_service_client_id')
54 and config.has_option('Credentials', 'gs_service_key_file')):
55 self.oauth2_client = oauth2_helper.OAuth2ClientFromBotoConfig(config,
56 cred_type=oauth2_client.CredTypes.OAUTH2_SERVICE_ACCOUNT)
57
58 # If we make it to this point, then we will later attempt to authenticate
59 # as a service account based on how the boto auth plugins work. This is
60 # global so that command.py can access this value once it's set.
61 # TODO: replace this approach with a way to get the current plugin
62 # from boto so that we don't have to have global variables.
63 global IS_SERVICE_ACCOUNT
64 IS_SERVICE_ACCOUNT = True
65 else:
66 raise NotReadyToAuthenticate()
67
68 def add_auth(self, http_request):
69 http_request.headers['Authorization'] = \
70 self.oauth2_client.GetAuthorizationHeader()
71
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698