Skip to content

Commit

Permalink
Adding extra __environ__ for user agent.
Browse files Browse the repository at this point in the history
Fixes #566.
  • Loading branch information
dhermes committed Jan 27, 2015
1 parent 10cff29 commit cf58724
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 28 additions & 0 deletions gcloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,32 @@

from pkg_resources import get_distribution

import httplib2
import socket

__environ__ = ''
try:
from google import appengine
__environ__ = '-GAE' # pragma: NO COVER
except ImportError:
pass


__version__ = get_distribution('gcloud').version


if __environ__ == '':
RESPONSE = None
try:
RESPONSE, _ = httplib2.Http(timeout=0.1).request(
uri='http://169.254.169.254/computeMetadata/v1/project/project-id',
headers={'Metadata-Flavor': 'Google'})

if RESPONSE['status'] == '200': # pragma: NO COVER
__environ__ = '-GCE' # pragma: NO COVER
except socket.timeout:
pass
finally:
del RESPONSE
else: # pragma: NO COVER
pass # pragma: NO COVER
3 changes: 2 additions & 1 deletion gcloud/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class Connection(object):
_EMPTY = object()
"""A pointer to represent an empty value for default arguments."""

USER_AGENT = "gcloud-python/{0}".format(gcloud.__version__)
USER_AGENT = "gcloud-python/{0}{1}".format(gcloud.__version__,
gcloud.__environ__)
"""The user agent for gcloud-python requests."""

def __init__(self, credentials=None):
Expand Down

0 comments on commit cf58724

Please sign in to comment.