From 895de8c7206b60648a9293d377ef09649f2f69bc Mon Sep 17 00:00:00 2001 From: vakaris_zilius Date: Wed, 7 Sep 2022 09:25:50 +0000 Subject: [PATCH] Common: Delete IJSONSerializable.py This interface is no longer used (replaced by pydantic objects) --- monkey/common/utils/IJSONSerializable.py | 15 -------------- monkey/common/utils/__init__.py | 1 - .../cc/services/representations.py | 6 +----- .../cc/services/test_representations.py | 20 ------------------- vulture_allowlist.py | 4 ---- 5 files changed, 1 insertion(+), 45 deletions(-) delete mode 100644 monkey/common/utils/IJSONSerializable.py diff --git a/monkey/common/utils/IJSONSerializable.py b/monkey/common/utils/IJSONSerializable.py deleted file mode 100644 index 39eefbf90..000000000 --- a/monkey/common/utils/IJSONSerializable.py +++ /dev/null @@ -1,15 +0,0 @@ -from __future__ import annotations - -from abc import ABC, abstractmethod - - -class IJSONSerializable(ABC): - @classmethod - @abstractmethod - def from_json(cls, json_string: str) -> IJSONSerializable: - pass - - @classmethod - @abstractmethod - def to_json(cls, class_object: IJSONSerializable) -> str: - pass diff --git a/monkey/common/utils/__init__.py b/monkey/common/utils/__init__.py index 1b11c54e3..57725fa62 100644 --- a/monkey/common/utils/__init__.py +++ b/monkey/common/utils/__init__.py @@ -1,2 +1 @@ from .timer import Timer -from .IJSONSerializable import IJSONSerializable diff --git a/monkey/monkey_island/cc/services/representations.py b/monkey/monkey_island/cc/services/representations.py index 19218ba37..56fbb2c24 100644 --- a/monkey/monkey_island/cc/services/representations.py +++ b/monkey/monkey_island/cc/services/representations.py @@ -1,14 +1,12 @@ from datetime import datetime from enum import Enum -from json import JSONEncoder, dumps, loads +from json import JSONEncoder, dumps from typing import Any import bson from flask import make_response from pydantic import BaseModel -from common.utils import IJSONSerializable - class APIEncoder(JSONEncoder): def default(self, value: Any) -> Any: @@ -20,8 +18,6 @@ class APIEncoder(JSONEncoder): return str(value) if issubclass(type(value), Enum): return value.name - if issubclass(type(value), IJSONSerializable): - return loads(value.__class__.to_json(value)) if issubclass(type(value), set): return list(value) if issubclass(type(value), BaseModel): diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/test_representations.py b/monkey/tests/unit_tests/monkey_island/cc/services/test_representations.py index 541a64c18..0a04032f3 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/test_representations.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/test_representations.py @@ -5,7 +5,6 @@ from enum import Enum import bson -from common.utils import IJSONSerializable from monkey_island.cc.services.representations import APIEncoder @@ -73,22 +72,3 @@ def test_api_encoder_tuple(): bogus_tuple = [{"my_tuple": (bogus_object1, bogus_object2, "string")}] expected_tuple = [{"my_tuple": ({"a": 1}, {"a": 2}, "string")}] assert json.dumps(expected_tuple) == json.dumps(bogus_tuple, cls=APIEncoder) - - -class BogusSerializableClass(IJSONSerializable): - def __init__(self, a): - self.a = a - - @classmethod - def to_json(cls, class_object: IJSONSerializable) -> str: - return json.dumps({"wacky": class_object.a}) - - @classmethod - def from_json(cls, json_string: str) -> IJSONSerializable: - pass - - -def test_api_encoder_json_serializable(): - bogus_data = {"target": [BogusSerializableClass("macky")]} - expected_result = {"target": [{"wacky": "macky"}]} - assert json.dumps(expected_result) == json.dumps(bogus_data, cls=APIEncoder) diff --git a/vulture_allowlist.py b/vulture_allowlist.py index caf7c3e24..14a311f0e 100644 --- a/vulture_allowlist.py +++ b/vulture_allowlist.py @@ -316,10 +316,6 @@ EXPLOITED CC CC_TUNNEL -# TODO Remove with #2217 -IJSONSerializable -from_json - IslandEventTopic.AGENT_CONNECTED IslandEventTopic.CLEAR_SIMULATION_DATA IslandEventTopic.RESET_AGENT_CONFIGURATION