From 95dfa53e18d74c5516bf1bf49da6878323257e53 Mon Sep 17 00:00:00 2001 From: carnivuth Date: Tue, 27 Jan 2026 17:41:41 +0100 Subject: [PATCH] added firewall strategy pattern --- src/firewall/fwtype.py | 2 +- src/firewall/iptables.py | 9 ++++++--- src/firewall/raw.py | 3 +-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/firewall/fwtype.py b/src/firewall/fwtype.py index 0e0e421..8617b4d 100644 --- a/src/firewall/fwtype.py +++ b/src/firewall/fwtype.py @@ -14,7 +14,7 @@ class FWType(ABC): cls._registry[cls.__name__.lower()] = cls @classmethod - def create(cls, fw_type: str, **kwargs) -> "FWType": + def create(cls, fw_type: str, **kwargs) -> 'FWType': """ Factory method to create instances of child classes. diff --git a/src/firewall/iptables.py b/src/firewall/iptables.py index 159171e..73ac623 100644 --- a/src/firewall/iptables.py +++ b/src/firewall/iptables.py @@ -1,11 +1,10 @@ from typing_extensions import override from firewall.fwtype import FWType - class Iptables(FWType): @override - def getBanlist(self, ips) -> str: + def getBanlist(self,ips) -> str: """ Generate iptables ban rules from an array of IP addresses. @@ -30,7 +29,11 @@ class Iptables(FWType): ip = ip.strip() # Build the iptables command - rule_parts = ["iptables", "-A", chain, "-s", ip] + rule_parts = [ + "iptables", + "-A", chain, + "-s", ip + ] # Add target rule_parts.extend(["-j", target]) diff --git a/src/firewall/raw.py b/src/firewall/raw.py index e0c82fe..1e29e75 100644 --- a/src/firewall/raw.py +++ b/src/firewall/raw.py @@ -1,11 +1,10 @@ from typing_extensions import override from firewall.fwtype import FWType - class Raw(FWType): @override - def getBanlist(self, ips) -> str: + def getBanlist(self,ips) -> str: """ Generate raw list of bad IP addresses.