forked from shaba/openuds
Added no proxy for local requests on udsactor
This commit is contained in:
parent
9d19aebdf6
commit
c3915fd8fe
@ -36,6 +36,12 @@ import requests
|
||||
|
||||
from ..log import logger
|
||||
|
||||
# For avoid proxy on localhost connections
|
||||
NO_PROXY = {
|
||||
'http': None,
|
||||
'https': None,
|
||||
}
|
||||
|
||||
class UDSActorClientPool:
|
||||
_clientUrl: typing.List[str]
|
||||
|
||||
@ -47,7 +53,7 @@ class UDSActorClientPool:
|
||||
result: typing.List[typing.Any] = []
|
||||
for clientUrl in self._clientUrl:
|
||||
try:
|
||||
result.append(requests.post(clientUrl + '/' + method, data=json.dumps(data), verify=False, timeout=timeout))
|
||||
result.append(requests.post(clientUrl + '/' + method, data=json.dumps(data), verify=False, timeout=timeout, proxy=NO_PROXY))
|
||||
except Exception as e:
|
||||
# If cannot request to a clientUrl, remove it from list
|
||||
logger.info('Could not connect with client %s: %s. Removed from registry.', e, clientUrl)
|
||||
|
@ -67,6 +67,11 @@ class RESTUserServiceNotFoundError(RESTError):
|
||||
class RESTOsManagerError(RESTError):
|
||||
ERRCODE = 4
|
||||
|
||||
# For avoid proxy on localhost connections
|
||||
NO_PROXY = {
|
||||
'http': None,
|
||||
'https': None,
|
||||
}
|
||||
#
|
||||
# Basic UDS Api
|
||||
#
|
||||
@ -104,11 +109,20 @@ class UDSApi: # pylint: disable=too-few-public-methods
|
||||
self,
|
||||
method: str, # i.e. 'initialize', 'ready', ....
|
||||
payLoad: typing.MutableMapping[str, typing.Any],
|
||||
headers: typing.Optional[typing.MutableMapping[str, str]] = None
|
||||
headers: typing.Optional[typing.MutableMapping[str, str]] = None,
|
||||
disableProxy: bool = False
|
||||
) -> typing.Any:
|
||||
headers = headers or self._headers
|
||||
try:
|
||||
result = requests.post(self._apiURL(method), data=json.dumps(payLoad), headers=headers, verify=self._validateCert, timeout=TIMEOUT)
|
||||
result = requests.post(
|
||||
self._apiURL(method),
|
||||
data=json.dumps(payLoad),
|
||||
headers=headers,
|
||||
verify=self._validateCert,
|
||||
timeout=TIMEOUT,
|
||||
proxies=NO_PROXY if disableProxy else None # If disable proxy, force skip it
|
||||
)
|
||||
|
||||
if result.ok:
|
||||
j = result.json()
|
||||
if not j.get('error', None):
|
||||
@ -326,24 +340,31 @@ class UDSClientApi(UDSApi):
|
||||
def _apiURL(self, method: str) -> str:
|
||||
return self._url + method
|
||||
|
||||
def post(
|
||||
self,
|
||||
method: str, # i.e. 'initialize', 'ready', ....
|
||||
payLoad: typing.MutableMapping[str, typing.Any]
|
||||
) -> typing.Any:
|
||||
return self._doPost(method=method, payLoad=payLoad, disableProxy=True)
|
||||
|
||||
def register(self, callbackUrl: str) -> None:
|
||||
payLoad = {
|
||||
'callback_url': callbackUrl
|
||||
}
|
||||
self._doPost('register', payLoad)
|
||||
self.post('register', payLoad)
|
||||
|
||||
def unregister(self, callbackUrl: str) -> None:
|
||||
payLoad = {
|
||||
'callback_url': callbackUrl
|
||||
}
|
||||
self._doPost('unregister', payLoad)
|
||||
self.post('unregister', payLoad)
|
||||
|
||||
def login(self, username: str, sessionType: typing.Optional[str] = None) -> types.LoginResultInfoType:
|
||||
payLoad = {
|
||||
'username': username,
|
||||
'session_type': sessionType or UNKNOWN,
|
||||
}
|
||||
result = self._doPost('login', payLoad)
|
||||
result = self.post('login', payLoad)
|
||||
return types.LoginResultInfoType(
|
||||
ip=result['ip'],
|
||||
hostname=result['hostname'],
|
||||
@ -355,7 +376,7 @@ class UDSClientApi(UDSApi):
|
||||
payLoad = {
|
||||
'username': username
|
||||
}
|
||||
self._doPost('logout', payLoad)
|
||||
self.post('logout', payLoad)
|
||||
|
||||
def ping(self) -> bool:
|
||||
return self._doPost('ping', {}) == 'pong'
|
||||
return self.post('ping', {}) == 'pong'
|
||||
|
Loading…
Reference in New Issue
Block a user