using name and id as pk for PyFilter when updating stats

This commit is contained in:
Domingo Dirutigliano
2025-06-13 13:33:13 +02:00
parent 2f925925e9
commit d7f6eb7524

View File

@@ -1,6 +1,15 @@
class Service:
def __init__(self, service_id: str, status: str, port: int, name: str, proto: str, ip_int: str, fail_open: bool, **other):
def __init__(
self,
service_id: str,
status: str,
port: int,
name: str,
proto: str,
ip_int: str,
fail_open: bool,
**other,
):
self.id = service_id
self.status = status
self.port = port
@@ -15,15 +24,31 @@ class Service:
class PyFilter:
def __init__(self, name: str, blocked_packets: int, edited_packets: int, active: bool, db, **other):
def __init__(
self,
name: str,
service_id: str,
blocked_packets: int,
edited_packets: int,
active: bool,
db,
**other,
):
self.name = name
self.blocked_packets = blocked_packets
self.edited_packets = edited_packets
self.active = active
self.__db = db
self.srv_id = service_id
async def update(self):
self.__db.query("UPDATE pyfilter SET blocked_packets = ?, edited_packets = ? WHERE name = ?;", self.blocked_packets, self.edited_packets, self.name)
self.__db.query(
"UPDATE pyfilter SET blocked_packets = ?, edited_packets = ? WHERE name = ? AND service_id = ?;",
self.blocked_packets,
self.edited_packets,
self.name,
self.srv_id,
)
def __repr__(self):
return f"<PyFilter {self.name}>"