Skip to content

Commit

Permalink
feat: Add replace option to update_ip_hostgroup (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
mamullen13316 authored Dec 21, 2023
1 parent bca60f9 commit d4ed632
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "sophosfirewall-python"
packages = [
{ include = "sophosfirewall_python" },
]
version = "0.1.28"
version = "0.1.29"
description = "Python SDK for Sophos Firewall"
authors = ["Matt Mullen <[email protected]>"]
readme = "README.md"
Expand Down
11 changes: 9 additions & 2 deletions sophosfirewall_python/firewallapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,20 +995,25 @@ def update_ip_hostgroup(
name (str): IP Host Group name.
description (str): IP Host Group description.
host_list (str): List of IP Hosts to be added to or removed from the Host List.
action (str): Add or Remove from Host list. Specify None to disable updating Host List. Defaults to Add.
action (str): Add/Remove from Host List, or Replace existing Host List. Specify None to disable updating Host List. Defaults to Add.
debug (bool, optional): Enable debug mode. Defaults to False.
Returns:
dict: XML response converted to Python dictionary
"""
# Get the existing Host list first, if any

resp = self.get_ip_hostgroup(name=name)
if "HostList" in resp["Response"]["IPHostGroup"]:
exist_list = (
resp.get("Response").get("IPHostGroup").get("HostList").get("Host")
)
else:
exist_list = None

if action.lower() == "replace":
exist_list = None

new_host_list = []
if exist_list:
if isinstance(exist_list, str):
Expand All @@ -1019,8 +1024,10 @@ def update_ip_hostgroup(
if action:
if action.lower() == "add" and not ip_host in new_host_list:
new_host_list.append(ip_host)
elif action == "remove".lower() and ip_host in new_host_list:
elif action.lower() == "remove" and ip_host in new_host_list:
new_host_list.remove(ip_host)
elif action.lower() == "replace":
new_host_list.append(ip_host)
if not description:
description = resp.get("Response").get("IPHostGroup").get("Description")

Expand Down

0 comments on commit d4ed632

Please sign in to comment.