mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-05 13: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)
|
request = google_auth_httplib2.Request(http)
|
||||||
try:
|
try:
|
||||||
credentials.refresh(request)
|
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:
|
except httplib2.ServerNotFoundError as e:
|
||||||
systemErrorExit(4, e)
|
systemErrorExit(4, e)
|
||||||
except google.auth.exceptions.RefreshError as e:
|
except google.auth.exceptions.RefreshError as e:
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ class AuthorizedHttp(object):
|
|||||||
The underlying :meth:`request` implementation handles adding the
|
The underlying :meth:`request` implementation handles adding the
|
||||||
credentials' headers to the request and refreshing credentials as needed.
|
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,
|
refresh_status_codes=transport.DEFAULT_REFRESH_STATUS_CODES,
|
||||||
max_refresh_attempts=transport.DEFAULT_MAX_REFRESH_ATTEMPTS):
|
max_refresh_attempts=transport.DEFAULT_MAX_REFRESH_ATTEMPTS):
|
||||||
"""
|
"""
|
||||||
@@ -168,6 +168,7 @@ class AuthorizedHttp(object):
|
|||||||
http = _make_default_http()
|
http = _make_default_http()
|
||||||
|
|
||||||
self.http = http
|
self.http = http
|
||||||
|
self.user_agent = user_agent
|
||||||
self.credentials = credentials
|
self.credentials = credentials
|
||||||
self._refresh_status_codes = refresh_status_codes
|
self._refresh_status_codes = refresh_status_codes
|
||||||
self._max_refresh_attempts = max_refresh_attempts
|
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.
|
# and we want to pass the original headers if we recurse.
|
||||||
request_headers = headers.copy() if headers is not None else {}
|
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.credentials.before_request(
|
||||||
self._request, method, uri, request_headers)
|
self._request, method, uri, request_headers)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user