Common: Make AbstractAgentEvent to be a pydantic modell

In this way we are saying that every event needs to be a pydantic model
for which we may pay the price later on.
This commit is contained in:
Ilija Lazoroski 2022-09-13 17:32:33 +02:00
parent a68a765722
commit 1799f1253c
1 changed files with 9 additions and 7 deletions

View File

@ -1,13 +1,15 @@
import time import time
from abc import ABC from abc import ABC
from dataclasses import dataclass, field
from ipaddress import IPv4Address from ipaddress import IPv4Address
from typing import FrozenSet, Union from typing import FrozenSet, Union
from uuid import getnode from uuid import getnode
from pydantic import Field
@dataclass(frozen=True) from common.base_models import InfectionMonkeyBaseModel
class AbstractAgentEvent(ABC):
class AbstractAgentEvent(InfectionMonkeyBaseModel, ABC):
""" """
An event that was initiated or observed by an agent An event that was initiated or observed by an agent
@ -22,7 +24,7 @@ class AbstractAgentEvent(ABC):
:param tags: The set of tags associated with the event :param tags: The set of tags associated with the event
""" """
source: int = field(default_factory=getnode) source: int = Field(default_factory=getnode)
target: Union[int, IPv4Address, None] = field(default=None) target: Union[int, IPv4Address, None] = Field(default=None)
timestamp: float = field(default_factory=time.time) timestamp: float = Field(default_factory=time.time)
tags: FrozenSet[str] = field(default_factory=frozenset) tags: FrozenSet[str] = Field(default_factory=frozenset)