forked from p15670423/monkey
Merge pull request #2252 from guardicore/2217-remove-unused-code
2217 remove unused code
This commit is contained in:
commit
6891c82a46
|
@ -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
|
|
@ -1,2 +1 @@
|
|||
from .timer import Timer
|
||||
from .IJSONSerializable import IJSONSerializable
|
||||
|
|
|
@ -52,7 +52,6 @@ from monkey_island.cc.resources.version import Version
|
|||
from monkey_island.cc.resources.zero_trust.finding_event import ZeroTrustFindingEvent
|
||||
from monkey_island.cc.resources.zero_trust.zero_trust_report import ZeroTrustReport
|
||||
from monkey_island.cc.server_utils.consts import MONKEY_ISLAND_ABS_PATH
|
||||
from monkey_island.cc.server_utils.custom_json_encoder import CustomJSONEncoder
|
||||
from monkey_island.cc.services.representations import output_json
|
||||
|
||||
HOME_FILE = "index.html"
|
||||
|
@ -97,7 +96,6 @@ def init_app_config(app, mongo_url):
|
|||
app.config["JSON_SORT_KEYS"] = False
|
||||
|
||||
app.url_map.strict_slashes = False
|
||||
app.json_encoder = CustomJSONEncoder
|
||||
|
||||
|
||||
def init_app_services(app):
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
from bson import ObjectId, json_util
|
||||
from flask.json import JSONEncoder
|
||||
|
||||
|
||||
class CustomJSONEncoder(JSONEncoder):
|
||||
def default(self, obj):
|
||||
try:
|
||||
if isinstance(obj, ObjectId):
|
||||
return json_util.dumps(obj)
|
||||
except TypeError:
|
||||
pass
|
||||
return JSONEncoder.default(self, obj)
|
|
@ -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):
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
import Form from 'react-jsonschema-form-bs4';
|
||||
import React, {useState} from 'react';
|
||||
import {Nav} from 'react-bootstrap';
|
||||
|
||||
const sectionOrder = [
|
||||
'network',
|
||||
'exploits',
|
||||
'classes',
|
||||
'general'
|
||||
];
|
||||
const initialSection = sectionOrder[0];
|
||||
|
||||
export default function InternalConfig(props) {
|
||||
const {
|
||||
schema,
|
||||
uiSchema,
|
||||
onChange,
|
||||
customFormats,
|
||||
className,
|
||||
formData
|
||||
} = props;
|
||||
const [selectedSection, setSelectedSection] = useState(initialSection);
|
||||
const [displayedSchema, setDisplayedSchema] = useState(getSchemaByKey(schema, initialSection));
|
||||
const [displayedSchemaUi, setDisplayedSchemaUi] = useState(uiSchema[initialSection]);
|
||||
|
||||
const onInnerDataChange = (innerData) => {
|
||||
formData[selectedSection] = innerData.formData;
|
||||
onChange({formData: formData});
|
||||
}
|
||||
|
||||
const setSection = (sectionKey) => {
|
||||
setSelectedSection(sectionKey);
|
||||
setDisplayedSchema(getSchemaByKey(schema, sectionKey));
|
||||
setDisplayedSchemaUi(uiSchema[sectionKey]);
|
||||
}
|
||||
|
||||
const renderNav = () => {
|
||||
return (<Nav variant='tabs'
|
||||
fill
|
||||
activeKey={selectedSection} onSelect={setSection}
|
||||
style={{'marginBottom': '2em'}}
|
||||
className={'config-nav'}>
|
||||
{sectionOrder.map(section => {
|
||||
return (
|
||||
<Nav.Item key={section}>
|
||||
<Nav.Link eventKey={section}>{getNavTitle(schema, section)}</Nav.Link>
|
||||
</Nav.Item>);
|
||||
})}
|
||||
</Nav>)
|
||||
}
|
||||
|
||||
return (<div>
|
||||
{renderNav()}
|
||||
<Form schema={displayedSchema}
|
||||
uiSchema={displayedSchemaUi}
|
||||
formData={formData[selectedSection]}
|
||||
onChange={onInnerDataChange}
|
||||
customFormats={customFormats}
|
||||
className={className}
|
||||
liveValidate>
|
||||
<button type='submit' className={'hidden'}>Submit</button>
|
||||
</Form>
|
||||
</div>)
|
||||
}
|
||||
|
||||
function getSchemaByKey(schema, key) {
|
||||
let definitions = schema['definitions'];
|
||||
return {definitions: definitions, properties: schema['properties'][key]['properties']};
|
||||
}
|
||||
|
||||
function getNavTitle(schema, key) {
|
||||
return schema.properties[key].title;
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue