Skip to content

Commit

Permalink
Timeout fix (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
mamullen13316 authored Feb 24, 2025
1 parent 6724e17 commit f78fa64
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions sophosfirewall_python/firewallapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,23 @@ def login(self, output_format: str = "dict"):
"""
return self.client.login(output_format)

def get_tag(self, xml_tag: str, output_format: str = "dict"):
def get_tag(self, xml_tag: str, timeout: int = 30, output_format: str = "dict"):
"""Execute a get for a specified XML tag.
Args:
xml_tag (str): XML tag for the request
timeout (int): Request timeout in seconds. Defaults to 30 seconds.
output_format(str): Output format. Valid options are "dict" or "xml". Defaults to dict.
"""
return self.client.get_tag(xml_tag, output_format)
return self.client.get_tag(xml_tag, timeout, output_format)

def get_tag_with_filter(
self,
xml_tag: str,
key: str,
value: str,
operator: str = "like",
timeout: int = 30,
output_format: str = dict,
):
"""Execute a get for a specified XML tag with filter criteria.
Expand All @@ -91,17 +93,19 @@ def get_tag_with_filter(
key (str): Search key
value (str): Search value
operator (str, optional): Operator for search (“=”,”!=”,”like”). Defaults to "like".
timeout (int): Request timeout in seconds. Defaults to 30 seconds.
output_format(str): Output format. Valid options are "dict" or "xml". Defaults to dict.
"""
return self.client.get_tag_with_filter(
xml_tag, key, value, operator, output_format
xml_tag, key, value, operator, timeout, output_format
)

def submit_template(
self,
filename: str,
template_vars: dict,
template_dir: str = None,
timeout: int = 30,
debug: bool = False,
) -> dict:
"""Submits XML payload stored as a Jinja2 file
Expand All @@ -110,18 +114,20 @@ def submit_template(
filename (str): Jinja2 template filename. Place in "templates" directory or configure template_dir.
template_vars (dict): Dictionary of variables to inject into the template. Username and password are passed in by default.
template_dir (str): Directory to look for templates. Default is "./templates".
timeout (int): Request timeout in seconds. Defaults to 30 seconds.
debug (bool, optional): Enable debug mode to display XML payload. Defaults to False.
Returns:
dict
"""
return self.client.submit_template(filename, template_vars, template_dir, debug)
return self.client.submit_template(filename, template_vars, template_dir, timeout, debug)

def submit_xml(
self,
template_data: str,
template_vars: dict = None,
set_operation: str = "add",
timeout: int = 30,
debug: bool = False,
) -> dict:
"""Submits XML payload as a string to the API.
Expand All @@ -134,11 +140,11 @@ def submit_xml(
dict
"""
return self.client.submit_xml(
template_data, template_vars, set_operation, debug
template_data, template_vars, set_operation, timeout, debug
)

def remove(
self, xml_tag: str, name: str, key: str = "Name", output_format: str = "dict"
self, xml_tag: str, name: str, key: str = "Name", timeout: int = 30, output_format: str = "dict"
):
"""Remove an object from the firewall.
Expand All @@ -148,7 +154,7 @@ def remove(
key (str): The primary XML key that is used to look up the object. Defaults to Name.
output_format (str): Output format. Valid options are "dict" or "xml". Defaults to dict.
"""
return self.client.remove(xml_tag, name, key, output_format)
return self.client.remove(xml_tag, name, key, timeout, output_format)

def update(
self,
Expand All @@ -157,6 +163,7 @@ def update(
name: str = None,
lookup_key: str = "Name",
output_format: str = "dict",
timeout: int = 30,
debug: bool = False,
):
"""Update an existing object on the firewall.
Expand All @@ -167,10 +174,11 @@ def update(
name (str, optional): The name of the object to be updated, if applicable.
lookup_key (str, optional): The XML key name to look up the name of the object. Default is "Name".
output_format(str): Output format. Valid options are "dict" or "xml". Defaults to dict.
timeout (int): Request timeout in seconds. Defaults to 30 seconds.
debug (bool): Displays the XML payload that was submitted
"""
return self.client.update(
xml_tag, update_params, name, lookup_key, output_format, debug
xml_tag, update_params, name, lookup_key, output_format, timeout, debug
)

# METHODS FOR OBJECT RETRIEVAL (GET)
Expand Down

0 comments on commit f78fa64

Please sign in to comment.