Skip to content

Providing fixes for common operations #459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions netutils/acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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`.
Expand All @@ -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