Common: Use a temporary hack to define non-defaults from a inherited class event

This commit is contained in:
Ilija Lazoroski 2022-08-15 18:24:01 +02:00
parent 5f631a78f7
commit 486a7a9225
2 changed files with 12 additions and 7 deletions

View File

@ -1,8 +1,9 @@
import time
from abc import ABC
from dataclasses import dataclass
from dataclasses import dataclass, field
from ipaddress import IPv4Address
from typing import FrozenSet, Union
from uuid import UUID
from uuid import UUID, getnode
@dataclass(frozen=True)
@ -21,7 +22,7 @@ class AbstractEvent(ABC):
:param tags: The set of tags associated with the event
"""
source: UUID
target: Union[UUID, IPv4Address, None]
timestamp: float
tags: FrozenSet[str]
target: Union[UUID, IPv4Address, None]
source: UUID = field(default_factory=getnode)
timestamp: float = field(default_factory=time.time)

View File

@ -1,4 +1,4 @@
from dataclasses import dataclass
from dataclasses import dataclass, field
from typing import Sequence
from common.credentials import Credentials
@ -6,6 +6,10 @@ from common.credentials import Credentials
from . import AbstractEvent
def hack_event():
raise TypeError("Missing a required argument")
@dataclass(frozen=True)
class CredentialsStolenEvent(AbstractEvent):
"""
@ -15,4 +19,4 @@ class CredentialsStolenEvent(AbstractEvent):
:param stolen_credentials: The credentials that were stolen by an agent
"""
stolen_credentials: Sequence[Credentials]
stolen_credentials: Sequence[Credentials] = field(default_factory=hack_event)