diff --git a/stix_shifter_utils/stix_transmission/utils/RestApiClientAsync.py b/stix_shifter_utils/stix_transmission/utils/RestApiClientAsync.py index d414d95ba..b14a146ea 100644 --- a/stix_shifter_utils/stix_transmission/utils/RestApiClientAsync.py +++ b/stix_shifter_utils/stix_transmission/utils/RestApiClientAsync.py @@ -57,6 +57,17 @@ def __init__(self, host, port=None, headers={}, url_modifier_function=None, cert unique_file_handle = uuid.uuid4() self.server_cert_name = "/tmp/{0}-server_cert.pem".format(unique_file_handle) server_ip = host + + #To enable proxy, set the environment variable "STIX_SHIFTER_ENABLE_TRUST_ENV" to true. This option will allow the connection + #to use the system environments proxy settings. This can be done by setting the "https_proxy" environment variable to + #"http(s)://[username]:[password]@[hostname]/[ipaddress]:[port]". Alternative proxy schema's may or may not work. + self.trust_env_enabled = os.environ.get("STIX_SHIFTER_ENABLE_TRUST_ENV", "False").lower() + if self.trust_env_enabled == "true": + self.trust_env_enabled = True + else: + self.trust_env_enabled = False + self.logger.debug(f"Proxy Environment - Trusted_Env Enabled : {self.trust_env_enabled}") + if port is not None: server_ip += ":" + str(port) self.server_ip = server_ip @@ -101,7 +112,7 @@ async def call_api(self, endpoint, method, headers=None, cookies=None, data=None try: client_timeout = ClientTimeout(connect=self.connect_timeout, total=timeout) # https://docs.aiohttp.org/en/stable/client_reference.html?highlight=timeout#aiohttp.ClientTimeout retry_options = ExponentialRetry(attempts=self.retry_max, statuses=[429, 500, 502, 503, 504]) - async with RetryClient(retry_options=retry_options) as client: + async with RetryClient(trust_env=self.trust_env_enabled, retry_options=retry_options) as client: call = getattr(client, method.lower()) async with call(url, headers=actual_headers, params=urldata, data=data,