mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-03 12:21:35 +00:00
GAM User-Agent header for service account requests
This commit is contained in:
@@ -1015,7 +1015,7 @@ def buildGAPIServiceObject(api, act_as, showAuthError=True):
|
||||
request = google_auth_httplib2.Request(http)
|
||||
try:
|
||||
credentials.refresh(request)
|
||||
service._http = google_auth_httplib2.AuthorizedHttp(credentials, http=http)
|
||||
service._http = google_auth_httplib2.AuthorizedHttp(credentials, http=http, user_agent=GAM_INFO)
|
||||
except httplib2.ServerNotFoundError as e:
|
||||
systemErrorExit(4, e)
|
||||
except google.auth.exceptions.RefreshError as e:
|
||||
|
||||
@@ -147,7 +147,7 @@ class AuthorizedHttp(object):
|
||||
The underlying :meth:`request` implementation handles adding the
|
||||
credentials' headers to the request and refreshing credentials as needed.
|
||||
"""
|
||||
def __init__(self, credentials, http=None,
|
||||
def __init__(self, credentials, http=None, user_agent=None,
|
||||
refresh_status_codes=transport.DEFAULT_REFRESH_STATUS_CODES,
|
||||
max_refresh_attempts=transport.DEFAULT_MAX_REFRESH_ATTEMPTS):
|
||||
"""
|
||||
@@ -168,6 +168,7 @@ class AuthorizedHttp(object):
|
||||
http = _make_default_http()
|
||||
|
||||
self.http = http
|
||||
self.user_agent = user_agent
|
||||
self.credentials = credentials
|
||||
self._refresh_status_codes = refresh_status_codes
|
||||
self._max_refresh_attempts = max_refresh_attempts
|
||||
@@ -186,6 +187,12 @@ class AuthorizedHttp(object):
|
||||
# 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:
|
||||
if request_headers.get('user-agent'):
|
||||
request_headers['user-agent'] = '%s %s' % (self.user_agent, request_headers['user-agent'])
|
||||
else:
|
||||
request_headers['user-agent'] = self.user_agent
|
||||
|
||||
self.credentials.before_request(
|
||||
self._request, method, uri, request_headers)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user