From 43387dc1a5f71e10812d791d050d4d7d6e768bbe Mon Sep 17 00:00:00 2001 From: vakarisz Date: Tue, 12 Jul 2022 11:58:42 +0300 Subject: [PATCH] Common: Use IJSONSerializable interface for credentials --- monkey/common/credentials/credentials.py | 11 ++++++----- monkey/common/utils/__init__.py | 1 + vulture_allowlist.py | 7 ++++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/monkey/common/credentials/credentials.py b/monkey/common/credentials/credentials.py index 9fdf78eab..eed392b6c 100644 --- a/monkey/common/credentials/credentials.py +++ b/monkey/common/credentials/credentials.py @@ -7,6 +7,7 @@ from typing import Any, Mapping, MutableMapping, Sequence, Tuple from marshmallow import Schema, fields, post_load, pre_dump from marshmallow.exceptions import MarshmallowError +from ..utils import IJSONSerializable from . import ( CredentialComponentType, InvalidCredentialComponentError, @@ -116,7 +117,7 @@ class CredentialsSchema(Schema): @dataclass(frozen=True) -class Credentials: +class Credentials(IJSONSerializable): identities: Tuple[ICredentialComponent] secrets: Tuple[ICredentialComponent] @@ -141,8 +142,8 @@ class Credentials: except MarshmallowError as err: raise InvalidCredentialsError(str(err)) - @staticmethod - def from_json(credentials: str) -> Credentials: + @classmethod + def from_json(cls, credentials: str) -> Credentials: """ Construct a Credentials object from a JSON string @@ -180,8 +181,8 @@ class Credentials: credentials_list = json.loads(credentials_array_json) return [Credentials.from_mapping(c) for c in credentials_list] - @staticmethod - def to_json(credentials: Credentials) -> str: + @classmethod + def to_json(cls, credentials: Credentials) -> str: """ Serialize a Credentials object to JSON diff --git a/monkey/common/utils/__init__.py b/monkey/common/utils/__init__.py index 57725fa62..1b11c54e3 100644 --- a/monkey/common/utils/__init__.py +++ b/monkey/common/utils/__init__.py @@ -1 +1,2 @@ from .timer import Timer +from .IJSONSerializable import IJSONSerializable diff --git a/vulture_allowlist.py b/vulture_allowlist.py index 049e487fc..4b4262b47 100644 --- a/vulture_allowlist.py +++ b/vulture_allowlist.py @@ -4,7 +4,6 @@ dead or is kept deliberately. Referencing these in a file like this makes sure t Vulture doesn't mark these as dead again. """ from infection_monkey.exploit.log4shell_utils.ldap_server import LDAPServerFactory -from monkey_island.cc import app from monkey_island.cc.models import Report from monkey_island.cc.models.networkmap import Arc, NetworkMap from monkey_island.cc.repository.attack.IMitigationsRepository import IMitigationsRepository @@ -207,6 +206,12 @@ _make_simulation # unused method (monkey/monkey_island/cc/models/simulation.py: # TODO DELETE AFTER RESOURCE REFACTORING + +# https://github.com/jendrikseipp/vulture/issues/287 +# Both happen in common\utils\IJSONSerializable.py +json_string +class_object + NetworkMap Arc.dst_machine IMitigationsRepository.get_mitigations