From ec4af2cc57ccc975184b63dda89cb4d311cdb018 Mon Sep 17 00:00:00 2001 From: vakarisz Date: Fri, 20 May 2022 17:24:18 +0300 Subject: [PATCH] Island: Add INetMapRepository.py and a mock entities for it --- monkey/monkey_island/cc/models/netmap.py | 17 +++++++++++ .../cc/repository/IEdgeRepository.py | 30 ------------------- .../cc/repository/INetMapRepository.py | 11 +++++++ 3 files changed, 28 insertions(+), 30 deletions(-) create mode 100644 monkey/monkey_island/cc/models/netmap.py delete mode 100644 monkey/monkey_island/cc/repository/IEdgeRepository.py create mode 100644 monkey/monkey_island/cc/repository/INetMapRepository.py diff --git a/monkey/monkey_island/cc/models/netmap.py b/monkey/monkey_island/cc/models/netmap.py new file mode 100644 index 000000000..4d482e686 --- /dev/null +++ b/monkey/monkey_island/cc/models/netmap.py @@ -0,0 +1,17 @@ +from dataclasses import dataclass +from typing import Mapping, Sequence + + +# This is the most concise way to represent a graph: +# Machine id as key, Arch list as a value +# Not sure how compatible this will be with ORM objects though, +# might require more complex casting logic +@dataclass +class Netmap: + nodes: Mapping[str, Sequence[Arch]] + + +@dataclass +class Arch: + dst_machine: Machine + status: str diff --git a/monkey/monkey_island/cc/repository/IEdgeRepository.py b/monkey/monkey_island/cc/repository/IEdgeRepository.py deleted file mode 100644 index 3b1393f31..000000000 --- a/monkey/monkey_island/cc/repository/IEdgeRepository.py +++ /dev/null @@ -1,30 +0,0 @@ -from abc import ABC -from typing import Optional, Sequence - -from monkey_island.cc.models.edge import Edge - - -class IEdgeRepository(ABC): - def get_all_edges(self): - pass - - def get_edges(self, src_machine_id: str, dst_machine_id: str) -> Sequence[Edge]: - pass - - def save_edge(self, edge: Edge): - pass - - def get_by_dst(self, dst_machine_id: str) -> Sequence[Edge]: - pass - - # If tunnel is None then it gets all edges, if True/False then gets only - # tunneling/non-tunneling edges - def get_by_src(self, src_machine_id: str, tunnel: Optional[bool] = None) -> Sequence[Edge]: - pass - - def get_by_id(self, edge_id: str) -> Edge: - pass - - # Scan telemetries might change the label once we know more about the target system - def set_label(self, edge_id: str, label: str): - pass diff --git a/monkey/monkey_island/cc/repository/INetMapRepository.py b/monkey/monkey_island/cc/repository/INetMapRepository.py new file mode 100644 index 000000000..ad3c0e1bb --- /dev/null +++ b/monkey/monkey_island/cc/repository/INetMapRepository.py @@ -0,0 +1,11 @@ +from abc import ABC + + +class INetMapRepository(ABC): + + # TODO Define NetMap object + def get_map(self) -> NetMap: + pass + + def save_netmap(self, netmap: NetMap): + pass