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

Unified Diff: third_party/oauth2client/gce.py

Issue 1085893002: Upgrade 3rd packages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: rebase Created 5 years, 8 months 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 side-by-side diff with in-line comments
Download patch
Index: third_party/oauth2client/gce.py
diff --git a/third_party/oauth2client/gce.py b/third_party/oauth2client/gce.py
index c7fd7c18a9b20bdbce80389e57a217861c0e54f3..ebd14e378bae7b01dcab88b9994780c55c8e974b 100644
--- a/third_party/oauth2client/gce.py
+++ b/third_party/oauth2client/gce.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012 Google Inc.
+# Copyright 2014 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -19,14 +19,13 @@ Utilities for making it easier to use OAuth 2.0 on Google Compute Engine.
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
-import httplib2
+import json
import logging
-import uritemplate
+from third_party.six.moves import urllib
-from oauth2client import util
-from oauth2client.anyjson import simplejson
-from oauth2client.client import AccessTokenRefreshError
-from oauth2client.client import AssertionCredentials
+from third_party.oauth2client import util
+from third_party.oauth2client.client import AccessTokenRefreshError
+from third_party.oauth2client.client import AssertionCredentials
logger = logging.getLogger(__name__)
@@ -57,13 +56,14 @@ class AppAssertionCredentials(AssertionCredentials):
requested.
"""
self.scope = util.scopes_to_string(scope)
+ self.kwargs = kwargs
# Assertion type is no longer used, but still in the parent class signature.
super(AppAssertionCredentials, self).__init__(None)
@classmethod
- def from_json(cls, json):
- data = simplejson.loads(json)
+ def from_json(cls, json_data):
+ data = json.loads(json_data)
return AppAssertionCredentials(data['scope'])
def _refresh(self, http_request):
@@ -78,13 +78,28 @@ class AppAssertionCredentials(AssertionCredentials):
Raises:
AccessTokenRefreshError: When the refresh fails.
"""
- uri = uritemplate.expand(META, {'scope': self.scope})
+ query = '?scope=%s' % urllib.parse.quote(self.scope, '')
+ uri = META.replace('{?scope}', query)
response, content = http_request(uri)
if response.status == 200:
try:
- d = simplejson.loads(content)
- except StandardError, e:
+ d = json.loads(content)
+ except Exception as e:
raise AccessTokenRefreshError(str(e))
self.access_token = d['accessToken']
else:
+ if response.status == 404:
+ content += (' This can occur if a VM was created'
+ ' with no service account or scopes.')
raise AccessTokenRefreshError(content)
+
+ @property
+ def serialization_data(self):
+ raise NotImplementedError(
+ 'Cannot serialize credentials for GCE service accounts.')
+
+ def create_scoped_required(self):
+ return not self.scope
+
+ def create_scoped(self, scopes):
+ return AppAssertionCredentials(scopes, **self.kwargs)

Powered by Google App Engine
This is Rietveld 408576698