From 1659f630802746c27376a4a6e37c122cae350eb8 Mon Sep 17 00:00:00 2001 From: Matt Mullen Date: Tue, 15 Oct 2024 14:48:27 -0400 Subject: [PATCH] fix: provide ability to configure the lookup key for objects when updating --- sophosfirewall_python/api_client.py | 4 +++- sophosfirewall_python/firewallapi.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/sophosfirewall_python/api_client.py b/sophosfirewall_python/api_client.py index 0542640..f692ed0 100644 --- a/sophosfirewall_python/api_client.py +++ b/sophosfirewall_python/api_client.py @@ -335,6 +335,7 @@ def update( xml_tag: str, update_params: dict, name: str = None, + lookup_key: str = "Name", output_format: str = "dict", debug: bool = False, ): @@ -344,12 +345,13 @@ def update( xml_tag (str): The XML tag indicating the type of object to be updated. 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. + 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. debug (bool): Displays the XML payload that was submitted """ if name: resp = self.get_tag_with_filter( - xml_tag=xml_tag, key="Name", value=name, operator="=" + xml_tag=xml_tag, key=lookup_key, value=name, operator="=" ) else: resp = self.get_tag(xml_tag=xml_tag) diff --git a/sophosfirewall_python/firewallapi.py b/sophosfirewall_python/firewallapi.py index 0fe443a..26334a1 100644 --- a/sophosfirewall_python/firewallapi.py +++ b/sophosfirewall_python/firewallapi.py @@ -147,6 +147,7 @@ def update( xml_tag: str, update_params: dict, name: str = None, + lookup_key: str = "Name", output_format: str = "dict", debug: bool = False, ): @@ -156,10 +157,11 @@ def update( xml_tag (str): The XML tag indicating the type of object to be updated. 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. + 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. debug (bool): Displays the XML payload that was submitted """ - return self.client.update(xml_tag, update_params, name, output_format, debug) + return self.client.update(xml_tag, update_params, name, lookup_key, output_format, debug) # METHODS FOR OBJECT RETRIEVAL (GET)