Skip to content

Commit

Permalink
doc: update sphinx versions and fix docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
mamullen13316 committed May 8, 2024
1 parent 6cf2871 commit f9022c7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 42 deletions.
41 changes: 21 additions & 20 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pytest = "^7.4.2"
optional = true

[tool.poetry.group.docs.dependencies]
sphinx = "^7.2.6"
sphinx-rtd-theme = "^1.3.0"
sphinx = "^7.3.7"
sphinx-rtd-theme = "^2.0.0"


[build-system]
Expand Down
51 changes: 31 additions & 20 deletions sophosfirewall_python/firewallapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def update(
update_params: dict,
name: str = None,
output_format: str = "dict",
debug: bool = False
debug: bool = False,
):
"""Update an existing object on the firewall.
Expand All @@ -305,7 +305,7 @@ def update(
update_params (dict): Keys/values to be updated. Keys must match an existing XML key.
name (str, optional): The name of the object to be updated, if applicable.
output_format(str): Output format. Valid options are "dict" or "xml". Defaults to dict.
debug (bool): Displays the XML payload that was submitted
debug (bool): Displays the XML payload that was submitted
"""
if name:
resp = self.get_tag_with_filter(
Expand Down Expand Up @@ -835,10 +835,7 @@ def create_service(
Args:
name (str): Service name
service_list(list): List of dictionaries containing the below keys for each port/proto pair
src_port (str, optional): Source TCP/UDP port. Default=1:65535.
dst_port (str): Destination TCP/UDP port
protocol (str): TCP or UDP
service_list(list): List of dictionaries containing src_port (str, optional) Default=1:65535, dst_port(str), and protocol(str).
debug (bool, optional): Enable debug mode. Defaults to False.
Returns:
dict: XML response converted to Python dictionary
Expand Down Expand Up @@ -1029,16 +1026,17 @@ def update_urlgroup(
return resp

def update_service(
self, name: str, service_list: list[dict], action: str = "add", debug: bool = False
self,
name: str,
service_list: list[dict],
action: str = "add",
debug: bool = False,
):
"""Add or remove a service entry to/from a service
Args:
name (str): Service name.
service_list (list[dict]): List of dicts containing port/protocol pairs to be added or removed.
src_port(str, optional): Source TCP/UDP port range. Default=1:65535.
dst_port(str): Destination TCP/UDP port range.
protocol(str): TCP or UDP
service_list(list): List of dictionaries containing src_port (str, optional) Default=1:65535, dst_port(str), and protocol(str).
action (str): Options are 'add', 'remove' or 'replace'. Defaults to 'add'.
debug (bool, optional): Enable debug mode. Defaults to False.
Expand All @@ -1061,7 +1059,10 @@ def update_service(
resp = self.get_service(name=name)
if "ServiceDetail" in resp["Response"]["Services"]["ServiceDetails"]:
exist_list = (
resp.get("Response").get("Services").get("ServiceDetails").get("ServiceDetail")
resp.get("Response")
.get("Services")
.get("ServiceDetails")
.get("ServiceDetail")
)
else:
exist_list = None
Expand All @@ -1075,14 +1076,22 @@ def update_service(
new_service_list = []
if exist_list:
if isinstance(exist_list, dict):
new_service_list.append({"src_port": exist_list["SourcePort"],
"dst_port": exist_list["DestinationPort"],
"protocol": exist_list["Protocol"]})
new_service_list.append(
{
"src_port": exist_list["SourcePort"],
"dst_port": exist_list["DestinationPort"],
"protocol": exist_list["Protocol"],
}
)
elif isinstance(exist_list, list):
for service in exist_list:
new_service_list.append({"src_port": service["SourcePort"],
"dst_port": service["DestinationPort"],
"protocol": service["Protocol"]})
new_service_list.append(
{
"src_port": service["SourcePort"],
"dst_port": service["DestinationPort"],
"protocol": service["Protocol"],
}
)
for service in service_list:
if action.lower() == "add" and service not in new_service_list:
new_service_list.append(service)
Expand Down Expand Up @@ -1186,13 +1195,15 @@ def update_backup(self, backup_params: dict, debug: bool = False):
dict: XML response converted to Python dictionary
"""
updated_params = {}
current_params = self.get_backup()['Response']['BackupRestore']['ScheduleBackup']
current_params = self.get_backup()["Response"]["BackupRestore"][
"ScheduleBackup"
]
for param in current_params:
if param in backup_params:
updated_params[param] = backup_params[param]
else:
updated_params[param] = current_params[param]

resp = self.submit_template(
"updatebackup.j2", template_vars=updated_params, debug=debug
)
Expand Down

0 comments on commit f9022c7

Please sign in to comment.