forked from p15670423/monkey
Common: Use IJSONSerializable interface for credentials
This commit is contained in:
parent
4bbcffabd3
commit
43387dc1a5
|
@ -7,6 +7,7 @@ from typing import Any, Mapping, MutableMapping, Sequence, Tuple
|
||||||
from marshmallow import Schema, fields, post_load, pre_dump
|
from marshmallow import Schema, fields, post_load, pre_dump
|
||||||
from marshmallow.exceptions import MarshmallowError
|
from marshmallow.exceptions import MarshmallowError
|
||||||
|
|
||||||
|
from ..utils import IJSONSerializable
|
||||||
from . import (
|
from . import (
|
||||||
CredentialComponentType,
|
CredentialComponentType,
|
||||||
InvalidCredentialComponentError,
|
InvalidCredentialComponentError,
|
||||||
|
@ -116,7 +117,7 @@ class CredentialsSchema(Schema):
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class Credentials:
|
class Credentials(IJSONSerializable):
|
||||||
identities: Tuple[ICredentialComponent]
|
identities: Tuple[ICredentialComponent]
|
||||||
secrets: Tuple[ICredentialComponent]
|
secrets: Tuple[ICredentialComponent]
|
||||||
|
|
||||||
|
@ -141,8 +142,8 @@ class Credentials:
|
||||||
except MarshmallowError as err:
|
except MarshmallowError as err:
|
||||||
raise InvalidCredentialsError(str(err))
|
raise InvalidCredentialsError(str(err))
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def from_json(credentials: str) -> Credentials:
|
def from_json(cls, credentials: str) -> Credentials:
|
||||||
"""
|
"""
|
||||||
Construct a Credentials object from a JSON string
|
Construct a Credentials object from a JSON string
|
||||||
|
|
||||||
|
@ -180,8 +181,8 @@ class Credentials:
|
||||||
credentials_list = json.loads(credentials_array_json)
|
credentials_list = json.loads(credentials_array_json)
|
||||||
return [Credentials.from_mapping(c) for c in credentials_list]
|
return [Credentials.from_mapping(c) for c in credentials_list]
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def to_json(credentials: Credentials) -> str:
|
def to_json(cls, credentials: Credentials) -> str:
|
||||||
"""
|
"""
|
||||||
Serialize a Credentials object to JSON
|
Serialize a Credentials object to JSON
|
||||||
|
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
from .timer import Timer
|
from .timer import Timer
|
||||||
|
from .IJSONSerializable import IJSONSerializable
|
||||||
|
|
|
@ -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.
|
Vulture doesn't mark these as dead again.
|
||||||
"""
|
"""
|
||||||
from infection_monkey.exploit.log4shell_utils.ldap_server import LDAPServerFactory
|
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 import Report
|
||||||
from monkey_island.cc.models.networkmap import Arc, NetworkMap
|
from monkey_island.cc.models.networkmap import Arc, NetworkMap
|
||||||
from monkey_island.cc.repository.attack.IMitigationsRepository import IMitigationsRepository
|
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
|
# TODO DELETE AFTER RESOURCE REFACTORING
|
||||||
|
|
||||||
|
# https://github.com/jendrikseipp/vulture/issues/287
|
||||||
|
# Both happen in common\utils\IJSONSerializable.py
|
||||||
|
json_string
|
||||||
|
class_object
|
||||||
|
|
||||||
NetworkMap
|
NetworkMap
|
||||||
Arc.dst_machine
|
Arc.dst_machine
|
||||||
IMitigationsRepository.get_mitigations
|
IMitigationsRepository.get_mitigations
|
||||||
|
|
Loading…
Reference in New Issue