From 486a7a9225758b0c7383f79f164c6e14628477d7 Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Mon, 15 Aug 2022 18:24:01 +0200 Subject: [PATCH] Common: Use a temporary hack to define non-defaults from a inherited class event --- monkey/common/events/abstract_event.py | 11 ++++++----- monkey/common/events/credentials_stolen_events.py | 8 ++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/monkey/common/events/abstract_event.py b/monkey/common/events/abstract_event.py index 33bb25506..03629c442 100644 --- a/monkey/common/events/abstract_event.py +++ b/monkey/common/events/abstract_event.py @@ -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) diff --git a/monkey/common/events/credentials_stolen_events.py b/monkey/common/events/credentials_stolen_events.py index f1db1c142..7ad06cb10 100644 --- a/monkey/common/events/credentials_stolen_events.py +++ b/monkey/common/events/credentials_stolen_events.py @@ -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)