Skip to content

Commit

Permalink
Merge two approaches for GAM header on SA
Browse files Browse the repository at this point in the history
- Ross approach put headers on both SA token generation request and API calls
- Jay approach appending to existing header if it exists
  • Loading branch information
jay0lee committed Dec 21, 2017
1 parent 14fab02 commit 134f170
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/gam.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,6 @@ def getSvcAcctCredentials(scopes, act_as):
credentials = google.oauth2.service_account.Credentials.from_service_account_info(GM_Globals[GM_OAUTH2SERVICE_JSON_DATA])
credentials = credentials.with_scopes(scopes)
credentials = credentials.with_subject(act_as)
# TODO: figure out how to set user agent
GM_Globals[GM_OAUTH2SERVICE_ACCOUNT_CLIENT_ID] = GM_Globals[GM_OAUTH2SERVICE_JSON_DATA]['client_id']
return credentials
except (ValueError, KeyError):
Expand Down
11 changes: 6 additions & 5 deletions src/google_auth_httplib2.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,13 @@ def __call__(self, url, method='GET', body=None, headers=None,
'Set the timeout when constructing the httplib2.Http instance.'
)

if self.user_agent:
if headers.get('user-agent'):
headers['user-agent'] = '%s %s' % (self.user_agent, headers['user-agent'])
else:
headers['user-agent'] = self.user_agent

try:
if self.user_agent is not None:
headers['user-agent'] = self.user_agent
_LOGGER.debug('Making request: %s %s', method, url)
response, data = self.http.request(
url, method=method, body=body, headers=headers, **kwargs)
Expand Down Expand Up @@ -172,7 +176,6 @@ def __init__(self, credentials, http=None, user_agent=None,
http = _make_default_http()

self.http = http
self.user_agent = user_agent
self.credentials = credentials
self.user_agent = user_agent
self._refresh_status_codes = refresh_status_codes
Expand All @@ -191,8 +194,6 @@ def request(self, uri, method='GET', body=None, headers=None,
# Make a copy of the headers. They will be modified by the credentials
# and we want to pass the original headers if we recurse.
request_headers = headers.copy() if headers is not None else {}
if self.user_agent is not None:
request_headers['user-agent'] = self.user_agent

if self.user_agent:
if request_headers.get('user-agent'):
Expand Down

0 comments on commit 134f170

Please sign in to comment.