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

Side by Side Diff: gslib/third_party/oauth2_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
OLDNEW
(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
OLDNEW
« no previous file with comments | « gslib/third_party/oauth2_plugin/oauth2_helper.py ('k') | gslib/third_party/protorpc/__init__.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698