Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to enable trusted_env. #1727

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion stix_shifter_utils/stix_transmission/utils/RestApiClientAsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Loading