Skip to content

Commit

Permalink
PAPP-34631: adding a timeout for connections
Browse files Browse the repository at this point in the history
  • Loading branch information
tapishj-splunk committed Nov 19, 2024
1 parent 53679ab commit 5dd99bd
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions ciscotalosintelligence_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def _make_rest_call(self, retry, endpoint, action_result, method="get", **kwargs
temp_file.write(cert)
temp_file.seek(0) # Move the file pointer to the beginning for reading
temp_file_path = temp_file.name # Get the name of the temporary file
self.client = httpx.Client(http2=True, verify=config.get("verify_server_cert", False), cert=temp_file_path)
self.client = httpx.Client(http2=True, verify=config.get("verify_server_cert", False), cert=temp_file_path, timeout=MAX_REQUEST_TIMEOUT)

if os.path.exists(temp_file_path):
os.remove(temp_file_path)
Expand Down Expand Up @@ -269,7 +269,7 @@ def _handle_domain_reputation(self, param):

domain = param["domain"]
if not self._is_valid_domain(domain):
return action_result.set_status(phantom.APP_ERROR, "Please provide a valid url")
return action_result.set_status(phantom.APP_ERROR, "Please provide a valid domain")

url_entry = {"raw_url": domain}

Expand Down Expand Up @@ -317,14 +317,12 @@ def _query_reputation(self, action_result, payload, observable=None):

if phantom.is_fail(taxonomy_ret_val):
return action_result.get_status()

# make rest call
ret_val, response = self._make_rest_call_helper(ENDPOINT_QUERY_REPUTATION_V3, action_result, method="post", json=payload)
if phantom.is_fail(ret_val):
return action_result.get_status()

response_taxonomy_map_version = response["taxonomy_map_version"]

if response_taxonomy_map_version > self._state["taxonomy_version"]:
taxonomy_ret_val, taxonomy = self._fetch_taxonomy(action_result, allow_cache=False)

Expand Down Expand Up @@ -482,7 +480,7 @@ def insert_newlines(string, every=64):

# exceptions shouldn't really be thrown here because most network related disconnections will happen when a request is sent
try:
self.client = httpx.Client(http2=True, verify=config.get("verify_server_cert", False), cert=temp_file_path)
self.client = httpx.Client(http2=True, verify=config.get("verify_server_cert", False), cert=temp_file_path, timeout=MAX_REQUEST_TIMEOUT)
except Exception as e:
self.debug_print(f"Could not connect to server because of {e}")
if os.path.exists(temp_file_path):
Expand Down

0 comments on commit 5dd99bd

Please sign in to comment.