mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-04 04:41:35 +00:00
Set user-agent (#660)
This commit is contained in:
@@ -1012,7 +1012,7 @@ def buildGAPIServiceObject(api, act_as, showAuthError=True):
|
|||||||
GM_Globals[GM_CURRENT_API_USER] = act_as
|
GM_Globals[GM_CURRENT_API_USER] = act_as
|
||||||
GM_Globals[GM_CURRENT_API_SCOPES] = API_SCOPE_MAPPING[api]
|
GM_Globals[GM_CURRENT_API_SCOPES] = API_SCOPE_MAPPING[api]
|
||||||
credentials = getSvcAcctCredentials(GM_Globals[GM_CURRENT_API_SCOPES], act_as)
|
credentials = getSvcAcctCredentials(GM_Globals[GM_CURRENT_API_SCOPES], act_as)
|
||||||
request = google_auth_httplib2.Request(http)
|
request = google_auth_httplib2.Request(http, user_agent=GAM_INFO)
|
||||||
try:
|
try:
|
||||||
credentials.refresh(request)
|
credentials.refresh(request)
|
||||||
service._http = google_auth_httplib2.AuthorizedHttp(credentials, http=http, user_agent=GAM_INFO)
|
service._http = google_auth_httplib2.AuthorizedHttp(credentials, http=http, user_agent=GAM_INFO)
|
||||||
@@ -1077,7 +1077,7 @@ def doCheckServiceAccount(users):
|
|||||||
for scope in all_scopes:
|
for scope in all_scopes:
|
||||||
try:
|
try:
|
||||||
credentials = getSvcAcctCredentials([scope], user)
|
credentials = getSvcAcctCredentials([scope], user)
|
||||||
request = google_auth_httplib2.Request(httplib2.Http(disable_ssl_certificate_validation=GC_Values[GC_NO_VERIFY_SSL]))
|
request = google_auth_httplib2.Request(httplib2.Http(disable_ssl_certificate_validation=GC_Values[GC_NO_VERIFY_SSL]), user_agent=GAM_INFO)
|
||||||
credentials.refresh(request)
|
credentials.refresh(request)
|
||||||
result = u'PASS'
|
result = u'PASS'
|
||||||
except httplib2.ServerNotFoundError as e:
|
except httplib2.ServerNotFoundError as e:
|
||||||
|
|||||||
@@ -80,8 +80,9 @@ class Request(transport.Request):
|
|||||||
|
|
||||||
.. automethod:: __call__
|
.. automethod:: __call__
|
||||||
"""
|
"""
|
||||||
def __init__(self, http):
|
def __init__(self, http, user_agent=None):
|
||||||
self.http = http
|
self.http = http
|
||||||
|
self.user_agent = user_agent
|
||||||
|
|
||||||
def __call__(self, url, method='GET', body=None, headers=None,
|
def __call__(self, url, method='GET', body=None, headers=None,
|
||||||
timeout=None, **kwargs):
|
timeout=None, **kwargs):
|
||||||
@@ -112,6 +113,8 @@ class Request(transport.Request):
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if self.user_agent is not None:
|
||||||
|
headers['user-agent'] = self.user_agent
|
||||||
_LOGGER.debug('Making request: %s %s', method, url)
|
_LOGGER.debug('Making request: %s %s', method, url)
|
||||||
response, data = self.http.request(
|
response, data = self.http.request(
|
||||||
url, method=method, body=body, headers=headers, **kwargs)
|
url, method=method, body=body, headers=headers, **kwargs)
|
||||||
@@ -157,6 +160,7 @@ class AuthorizedHttp(object):
|
|||||||
http (httplib2.Http): The underlying HTTP object to
|
http (httplib2.Http): The underlying HTTP object to
|
||||||
use to make requests. If not specified, a
|
use to make requests. If not specified, a
|
||||||
:class:`httplib2.Http` instance will be constructed.
|
:class:`httplib2.Http` instance will be constructed.
|
||||||
|
user_agent: the user-agent header
|
||||||
refresh_status_codes (Sequence[int]): Which HTTP status codes
|
refresh_status_codes (Sequence[int]): Which HTTP status codes
|
||||||
indicate that credentials should be refreshed and the request
|
indicate that credentials should be refreshed and the request
|
||||||
should be retried.
|
should be retried.
|
||||||
@@ -170,11 +174,12 @@ class AuthorizedHttp(object):
|
|||||||
self.http = http
|
self.http = http
|
||||||
self.user_agent = user_agent
|
self.user_agent = user_agent
|
||||||
self.credentials = credentials
|
self.credentials = credentials
|
||||||
|
self.user_agent = user_agent
|
||||||
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
|
||||||
# Request instance used by internal methods (for example,
|
# Request instance used by internal methods (for example,
|
||||||
# credentials.refresh).
|
# credentials.refresh).
|
||||||
self._request = Request(self.http)
|
self._request = Request(self.http, self.user_agent)
|
||||||
|
|
||||||
def request(self, uri, method='GET', body=None, headers=None,
|
def request(self, uri, method='GET', body=None, headers=None,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
@@ -186,6 +191,8 @@ class AuthorizedHttp(object):
|
|||||||
# Make a copy of the headers. They will be modified by the credentials
|
# Make a copy of the headers. They will be modified by the credentials
|
||||||
# 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 is not None:
|
||||||
|
request_headers['user-agent'] = self.user_agent
|
||||||
|
|
||||||
if self.user_agent:
|
if self.user_agent:
|
||||||
if request_headers.get('user-agent'):
|
if request_headers.get('user-agent'):
|
||||||
|
|||||||
Reference in New Issue
Block a user