using name and id as pk for PyFilter when updating stats
This commit is contained in:
@@ -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
|
||||
@@ -8,22 +17,38 @@ class Service:
|
||||
self.proto = proto
|
||||
self.ip_int = ip_int
|
||||
self.fail_open = fail_open
|
||||
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, var: dict):
|
||||
return cls(**var)
|
||||
|
||||
|
||||
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}>"
|
||||
|
||||
Reference in New Issue
Block a user