Skip to content

Commit

Permalink
Feature: Add remove method (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
mamullen13316 authored Dec 12, 2023
1 parent b6665a7 commit 43fd59e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
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.22"
version = "0.1.23"
description = "Python SDK for Sophos Firewall"
authors = ["Matt Mullen <[email protected]>"]
readme = "README.md"
Expand Down
31 changes: 31 additions & 0 deletions sophosfirewall_python/firewallapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class SophosFirewallOperatorError(Exception):
"""Error raised when an invalid operator is specified"""



class SophosFirewall:
"""Class used for interacting with the Sophos Firewall XML API"""

Expand Down Expand Up @@ -252,6 +253,34 @@ def get_tag_with_filter(
return resp.content.decode()
return xmltodict.parse(resp.content.decode())

def remove(self, xml_tag: str, name: str, output_format: str = "dict"):
"""Remove an object from the firewall.
Args:
xml_tag (str): The XML tag indicating the type of object to be removed.
name (str): The name of the object to be removed.
output_format (str): Output format. Valid options are "dict" or "xml". Defaults to dict.
"""
payload = f"""
<Request>
<Login>
<Username>{self.username}</Username>
<Password>{self.password}</Password>
</Login>
<Remove>
<{xml_tag}>
<Name>{name}</Name>
</{xml_tag}>
</Remove>
</Request>
"""
resp = self._post(xmldata=payload)
self._error_check(resp, xml_tag)
if output_format == "xml":
return resp.content.decode()
return xmltodict.parse(resp.content.decode())


def _dict_to_lower(self, target_dict):
"""Convert the keys of a dictionary to lower-case
Expand Down Expand Up @@ -285,6 +314,8 @@ def _error_check(self, api_response, xml_tag):
raise SophosFirewallAPIError(
str(xmltodict.parse(api_response.content.decode()))
)



# METHODS FOR OBJECT RETRIEVAL (GET)

Expand Down

0 comments on commit 43fd59e

Please sign in to comment.