Merge two approaches for GAM header on SA

- Ross approach put headers on both SA token generation request and API calls
- Jay approach appending to existing header if it exists
This commit is contained in:
Jay Lee
2017-12-21 10:12:46 -05:00
parent 14fab0293e
commit 134f170726
2 changed files with 6 additions and 6 deletions

View File

@ -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):

View File

@ -112,9 +112,13 @@ class Request(transport.Request):
'Set the timeout when constructing the httplib2.Http instance.'
)
try:
if self.user_agent is not None:
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:
_LOGGER.debug('Making request: %s %s', method, url)
response, data = self.http.request(
url, method=method, body=body, headers=headers, **kwargs)
@ -172,7 +176,6 @@ class AuthorizedHttp(object):
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
@ -191,8 +194,6 @@ class AuthorizedHttp(object):
# 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'):