aboutsummaryrefslogtreecommitdiff
path: root/oauth2client/contrib/_metadata.py
diff options
context:
space:
mode:
authorDanny Hermes <daniel.j.hermes@gmail.com>2016-08-09 19:49:56 -0700
committerNathaniel Manista <nathaniel@google.com>2016-08-09 19:49:56 -0700
commitf282a9260e858b4f7aecfc69336d18c42f988655 (patch)
tree4a62c366efabb2a1c7178474ecfb9ef48ea60f98 /oauth2client/contrib/_metadata.py
parentb1a17432731344d2e44b1ef78ab52f2202bee703 (diff)
downloadoauth2client-f282a9260e858b4f7aecfc69336d18c42f988655.tar.gz
Remove distinction between http and http.request (#602)
Diffstat (limited to 'oauth2client/contrib/_metadata.py')
-rw-r--r--oauth2client/contrib/_metadata.py25
1 files changed, 10 insertions, 15 deletions
diff --git a/oauth2client/contrib/_metadata.py b/oauth2client/contrib/_metadata.py
index 4c4588a..1a18bd4 100644
--- a/oauth2client/contrib/_metadata.py
+++ b/oauth2client/contrib/_metadata.py
@@ -32,15 +32,13 @@ METADATA_ROOT = 'http://metadata.google.internal/computeMetadata/v1/'
METADATA_HEADERS = {'Metadata-Flavor': 'Google'}
-def get(http_request, path, root=METADATA_ROOT, recursive=None):
+def get(http, path, root=METADATA_ROOT, recursive=None):
"""Fetch a resource from the metadata server.
Args:
+ http: an object to be used to make HTTP requests.
path: A string indicating the resource to retrieve. For example,
'instance/service-accounts/defualt'
- http_request: A callable that matches the method
- signature of httplib2.Http.request. Used to make the request to the
- metadataserver.
root: A string indicating the full path to the metadata server root.
recursive: A boolean indicating whether to do a recursive query of
metadata. See
@@ -57,7 +55,7 @@ def get(http_request, path, root=METADATA_ROOT, recursive=None):
url = _helpers._add_query_parameter(url, 'recursive', recursive)
response, content = transport.request(
- http_request, url, headers=METADATA_HEADERS)
+ http, url, headers=METADATA_HEADERS)
if response.status == http_client.OK:
decoded = _helpers._from_bytes(content)
@@ -71,16 +69,15 @@ def get(http_request, path, root=METADATA_ROOT, recursive=None):
'metadata service. Response:\n{1}'.format(url, response))
-def get_service_account_info(http_request, service_account='default'):
+def get_service_account_info(http, service_account='default'):
"""Get information about a service account from the metadata server.
Args:
+ http: an object to be used to make HTTP requests.
service_account: An email specifying the service account for which to
look up information. Default will be information for the "default"
service account of the current compute engine instance.
- http_request: A callable that matches the method
- signature of httplib2.Http.request. Used to make the request to the
- metadata server.
+
Returns:
A dictionary with information about the specified service account,
for example:
@@ -92,21 +89,19 @@ def get_service_account_info(http_request, service_account='default'):
}
"""
return get(
- http_request,
+ http,
'instance/service-accounts/{0}/'.format(service_account),
recursive=True)
-def get_token(http_request, service_account='default'):
+def get_token(http, service_account='default'):
"""Fetch an oauth token for the
Args:
+ http: an object to be used to make HTTP requests.
service_account: An email specifying the service account this token
should represent. Default will be a token for the "default" service
account of the current compute engine instance.
- http_request: A callable that matches the method
- signature of httplib2.Http.request. Used to make the request to the
- metadataserver.
Returns:
A tuple of (access token, token expiration), where access token is the
@@ -114,7 +109,7 @@ def get_token(http_request, service_account='default'):
that indicates when the access token will expire.
"""
token_json = get(
- http_request,
+ http,
'instance/service-accounts/{0}/token'.format(service_account))
token_expiry = client._UTCNOW() + datetime.timedelta(
seconds=token_json['expires_in'])