Common: Move JSONSerializable to common.types

This commit is contained in:
Mike Salvatore 2022-10-01 19:41:12 -04:00
parent 25f12305f5
commit 82c81c2a4b
6 changed files with 18 additions and 17 deletions

View File

@ -1,5 +1,5 @@
from .consts import EVENT_TYPE_FIELD
from .i_agent_event_serializer import IAgentEventSerializer, JSONSerializable
from .i_agent_event_serializer import IAgentEventSerializer
from .agent_event_serializer_registry import AgentEventSerializerRegistry
from .pydantic_agent_event_serializer import PydanticAgentEventSerializer
from .register import register_common_agent_event_serializers

View File

@ -1,17 +1,7 @@
from abc import ABC, abstractmethod
from typing import Dict, List, Union
from common.agent_events import AbstractAgentEvent
JSONSerializable = Union[ # type: ignore[misc]
Dict[str, "JSONSerializable"], # type: ignore[misc]
List["JSONSerializable"], # type: ignore[misc]
int,
str,
float,
bool,
None,
]
from common.types import JSONSerializable
class IAgentEventSerializer(ABC):

View File

@ -2,9 +2,10 @@ import logging
from typing import Generic, Type, TypeVar
from common.agent_events import AbstractAgentEvent
from common.types import JSONSerializable
from common.utils.code_utils import del_key
from . import EVENT_TYPE_FIELD, IAgentEventSerializer, JSONSerializable
from . import EVENT_TYPE_FIELD, IAgentEventSerializer
logger = logging.getLogger(__name__)

View File

@ -3,7 +3,7 @@ from __future__ import annotations
from dataclasses import dataclass
from enum import Enum
from ipaddress import IPv4Address
from typing import Optional
from typing import Dict, List, Optional, Union
from uuid import UUID
from pydantic import ConstrainedInt, PositiveInt
@ -17,6 +17,16 @@ AgentID: TypeAlias = UUID
HardwareID: TypeAlias = PositiveInt
MachineID: TypeAlias = PositiveInt
JSONSerializable = Union[ # type: ignore[misc]
Dict[str, "JSONSerializable"], # type: ignore[misc]
List["JSONSerializable"], # type: ignore[misc]
int,
str,
float,
bool,
None,
]
class NetworkPort(ConstrainedInt):
"""

View File

@ -8,7 +8,7 @@ import requests
from common import AgentRegistrationData, AgentSignals, OperatingSystem
from common.agent_configuration import AgentConfiguration
from common.agent_event_serializers import AgentEventSerializerRegistry, JSONSerializable
from common.agent_event_serializers import AgentEventSerializerRegistry
from common.agent_events import AbstractAgentEvent
from common.common_consts.timeouts import (
LONG_REQUEST_TIMEOUT,
@ -16,7 +16,7 @@ from common.common_consts.timeouts import (
SHORT_REQUEST_TIMEOUT,
)
from common.credentials import Credentials
from common.types import AgentID, SocketAddress
from common.types import AgentID, JSONSerializable, SocketAddress
from . import (
AbstractIslandAPIClientFactory,

View File

@ -1,8 +1,8 @@
import json
from typing import Callable
from common.agent_event_serializers import JSONSerializable
from common.agent_events import AbstractAgentEvent
from common.types import JSONSerializable
ENCRYPTED_PREFIX = "encrypted_"
ABSTRACT_AGENT_EVENT_FIELDS = vars(AbstractAgentEvent)["__fields__"].keys()