From 030f941d0f48d080f98c767314c8c9ec246f305e Mon Sep 17 00:00:00 2001 From: Marek Zbroch Date: Fri, 16 Feb 2024 09:59:30 +0100 Subject: [PATCH] Providing fixes for common operations --- netutils/acl.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/netutils/acl.py b/netutils/acl.py index 88eeba66..2136d662 100644 --- a/netutils/acl.py +++ b/netutils/acl.py @@ -201,7 +201,7 @@ def load_data(self) -> None: """Load the data into the rule while verifying input data, result data, and processing data.""" self.input_data_check() for attr in self.attrs: - if not self.data.get(attr): + if attr not in self.data: continue if hasattr(self, f"process_{attr}"): proccessor = getattr(self, f"process_{attr}") @@ -254,9 +254,10 @@ def process_dst_port( staying unchanged, but sourced from https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv. """ - output = [] if not self.dst_port_process: - return None + return dst_port + + output = [] if not isinstance(dst_port, list): dst_port = [dst_port] for item in dst_port: @@ -510,12 +511,12 @@ def match(self, rule: ACLRule) -> str: rule: The `ACLRule` rule to test against the list of `ACLRule`s loaded in initiation. Returns: - The response from the rule that matched, or `deny` by default. + A boolean if there was a full match or not. """ for item in self.rules: - if item.match(self.class_obj(rule)): - return str(item.action) - return str(item.deny) # pylint: disable=undefined-loop-variable + if item.match(rule): + return True + return False # pylint: disable=undefined-loop-variable def match_details(self, rule: ACLRule) -> t.Any: """Verbosely check the rules loaded in `load_data` match against a new `rule`. @@ -528,5 +529,5 @@ def match_details(self, rule: ACLRule) -> t.Any: """ output = [] for item in self.rules: - output.append(item.match_details(self.class_obj(rule))) + output.append(item.match_details(rule)) return output