From 1bfffb0bfdc89ce052f21ee796d138c0865b7907 Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Mon, 30 May 2022 09:46:25 +0200 Subject: [PATCH] Project: Fix travis build --- .pre-commit-config.yaml | 1 - .travis.yml | 1 - monkey/monkey_island/cc/models/networkmap.py | 4 +-- .../cc/repository/ILogRepository.py | 4 +-- .../cc/repository/IMachineRepository.py | 6 ++-- .../cc/repository/INetworkMapRepository.py | 4 +-- .../cc/repository/ISimulationRepository.py | 2 +- .../cc/repository/ITelemetryRepository.py | 2 +- .../resources/blackbox/utils/telem_store.py | 1 + monkey/monkey_island/cc/services/node.py | 30 +++++++++---------- pyproject.toml | 2 +- 11 files changed, 28 insertions(+), 29 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4d350fdc8..ee808ac88 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -52,4 +52,3 @@ repos: rev: v2.3 hooks: - id: vulture - exclude: "monkey/monkey_island/docs/source/conf.py" diff --git a/.travis.yml b/.travis.yml index 3eefb8ec7..ed8ccaaa5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,7 +57,6 @@ jobs: # check python code ## check syntax errors and fail the build if any are found. - flake8 . - ## check import order - python -m isort ./monkey --check-only diff --git a/monkey/monkey_island/cc/models/networkmap.py b/monkey/monkey_island/cc/models/networkmap.py index 4f40b9f8b..e249a19fc 100644 --- a/monkey/monkey_island/cc/models/networkmap.py +++ b/monkey/monkey_island/cc/models/networkmap.py @@ -8,10 +8,10 @@ from typing import Mapping, Sequence # might require more complex casting logic @dataclass class NetworkMap: - nodes: Mapping[str, Sequence[Arc]] + nodes: Mapping[str, Sequence[Arc]] # noqa: F821 @dataclass class Arc: - dst_machine: Machine + dst_machine: Machine # noqa: F821 status: str diff --git a/monkey/monkey_island/cc/repository/ILogRepository.py b/monkey/monkey_island/cc/repository/ILogRepository.py index 3da83d167..b3ac2ae48 100644 --- a/monkey/monkey_island/cc/repository/ILogRepository.py +++ b/monkey/monkey_island/cc/repository/ILogRepository.py @@ -4,10 +4,10 @@ from typing import Optional, Sequence class ILogRepository(ABC): # Define log object - def get_logs(self, agent_id: Optional[str] = None) -> Sequence[Log]: + def get_logs(self, agent_id: Optional[str] = None) -> Sequence[Log]: # noqa: F821 pass - def save_log(self, log: Log): + def save_log(self, log: Log): # noqa: F821 pass def delete_log(self, agent_id: str): diff --git a/monkey/monkey_island/cc/repository/IMachineRepository.py b/monkey/monkey_island/cc/repository/IMachineRepository.py index da2526507..270ea58ef 100644 --- a/monkey/monkey_island/cc/repository/IMachineRepository.py +++ b/monkey/monkey_island/cc/repository/IMachineRepository.py @@ -4,7 +4,7 @@ from typing import Optional, Sequence class IMachineRepository(ABC): # TODO define Machine object(ORM model) - def save_machine(self, machine: Machine): + def save_machine(self, machine: Machine): # noqa: F821 pass # TODO define Machine object(ORM model) @@ -14,7 +14,7 @@ class IMachineRepository(ABC): self, id: Optional[str] = None, ips: Optional[Sequence[str]] = None, - state: Optional[MachineState] = None, + state: Optional[MachineState] = None, # noqa: F821 is_island: Optional[bool] = None, - ) -> Sequence[Machine]: + ) -> Sequence[Machine]: # noqa: F821 pass diff --git a/monkey/monkey_island/cc/repository/INetworkMapRepository.py b/monkey/monkey_island/cc/repository/INetworkMapRepository.py index 8a53dd044..0b0b29847 100644 --- a/monkey/monkey_island/cc/repository/INetworkMapRepository.py +++ b/monkey/monkey_island/cc/repository/INetworkMapRepository.py @@ -4,8 +4,8 @@ from abc import ABC class INetworkMapRepository(ABC): # TODO Define NetMap object - def get_map(self) -> NetMap: + def get_map(self) -> NetMap: # noqa: F821 pass - def save_netmap(self, netmap: NetMap): + def save_netmap(self, netmap: NetMap): # noqa: F821 pass diff --git a/monkey/monkey_island/cc/repository/ISimulationRepository.py b/monkey/monkey_island/cc/repository/ISimulationRepository.py index 96cc3dc17..3a3854fb0 100644 --- a/monkey/monkey_island/cc/repository/ISimulationRepository.py +++ b/monkey/monkey_island/cc/repository/ISimulationRepository.py @@ -4,7 +4,7 @@ from abc import ABC class ISimulationRepository(ABC): # TODO define simulation object. It should contain metadata about simulation, # like start, end times, mode and last forced stop of all monkeys - def save_simulation(self, simulation: Simulation): + def save_simulation(self, simulation: Simulation): # noqa: F821 pass def get_simulation(self): diff --git a/monkey/monkey_island/cc/repository/ITelemetryRepository.py b/monkey/monkey_island/cc/repository/ITelemetryRepository.py index 69aa2ff35..f857b59f5 100644 --- a/monkey/monkey_island/cc/repository/ITelemetryRepository.py +++ b/monkey/monkey_island/cc/repository/ITelemetryRepository.py @@ -14,7 +14,7 @@ class ITelemetryRepository(ABC): def get_telemetries( self, id: Optional[str] = None, - type: Optional[TelemetryType] = None, + type: Optional[TelemetryType] = None, # noqa: F821 monkey_id: Optional[str] = None, ) -> Sequence[Telemetry]: pass diff --git a/monkey/monkey_island/cc/resources/blackbox/utils/telem_store.py b/monkey/monkey_island/cc/resources/blackbox/utils/telem_store.py index 7dad4b48b..f6e9a8406 100644 --- a/monkey/monkey_island/cc/resources/blackbox/utils/telem_store.py +++ b/monkey/monkey_island/cc/resources/blackbox/utils/telem_store.py @@ -15,6 +15,7 @@ MAX_SAME_CATEGORY_TELEMS = 10000 logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) + # TODO this will break with the IRepository implementation. Remove it class TestTelemStore: TELEMS_EXPORTED = False diff --git a/monkey/monkey_island/cc/services/node.py b/monkey/monkey_island/cc/services/node.py index e144ed0a6..b53696433 100644 --- a/monkey/monkey_island/cc/services/node.py +++ b/monkey/monkey_island/cc/services/node.py @@ -188,15 +188,15 @@ class NodeService: tunnel_host_id = NodeService.get_monkey_by_ip(tunnel_host_ip)["_id"] NodeService.unset_all_monkey_tunnels(monkey_id) mongo.db.monkey.update( - {"_id": monkey_id}, {"$set": {"tunnel": tunnel_host_id}}, upsert=False + {"_id": monkey_id}, {"$set": {"tunnel": tunnel_host_id}}, upsert=False ) monkey_label = NodeService.get_label_for_endpoint(monkey_id) tunnel_host_label = NodeService.get_label_for_endpoint(tunnel_host_id) tunnel_edge = EdgeService.get_or_create_edge( - src_node_id=monkey_id, - dst_node_id=tunnel_host_id, - src_label=monkey_label, - dst_label=tunnel_host_label, + src_node_id=monkey_id, + dst_node_id=tunnel_host_id, + src_label=monkey_label, + dst_label=tunnel_host_label, ) tunnel_edge.tunnel = True tunnel_edge.ip_address = tunnel_host_ip @@ -205,13 +205,13 @@ class NodeService: @staticmethod def insert_node(ip_address, domain_name=""): new_node_insert_result = mongo.db.node.insert_one( - { - "ip_addresses": [ip_address], - "domain_name": domain_name, - "exploited": False, - "propagated": False, - "os": {"type": "unknown", "version": "unknown"}, - } + { + "ip_addresses": [ip_address], + "domain_name": domain_name, + "exploited": False, + "propagated": False, + "os": {"type": "unknown", "version": "unknown"}, + } ) return mongo.db.node.find_one({"_id": new_node_insert_result.inserted_id}) @@ -252,7 +252,7 @@ class NodeService: @staticmethod def update_monkey_modify_time(monkey_id): mongo.db.monkey.update( - {"_id": monkey_id}, {"$set": {"modifytime": datetime.now()}}, upsert=False + {"_id": monkey_id}, {"$set": {"modifytime": datetime.now()}}, upsert=False ) @staticmethod @@ -268,7 +268,7 @@ class NodeService: @staticmethod def add_communication_info(monkey, info): mongo.db.monkey.update( - {"guid": monkey["guid"]}, {"$set": {"command_control_channel": info}}, upsert=False + {"guid": monkey["guid"]}, {"$set": {"command_control_channel": info}}, upsert=False ) # TODO this returns a mock island agent @@ -343,7 +343,7 @@ class NodeService: @staticmethod def get_hostname_by_id(node_id): return NodeService.get_node_hostname( - mongo.db.monkey.find_one({"_id": node_id}, {"hostname": 1}) + mongo.db.monkey.find_one({"_id": node_id}, {"hostname": 1}) ) @staticmethod diff --git a/pyproject.toml b/pyproject.toml index 88da84d42..10415750f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,5 +25,5 @@ norecursedirs = "node_modules dist" markers = ["slow: mark test as slow"] [tool.vulture] -exclude = ["monkey/monkey_island/cc/ui/", "monkey/tests/"] +exclude = ["monkey/monkey_island/cc/ui/", "monkey/tests/", "monkey/monkey_island/docs/"] paths = ["."]