From af7651c53b56431cc5da5d700c53545b8e9e20f6 Mon Sep 17 00:00:00 2001 From: Shreya Date: Wed, 21 Jul 2021 17:49:28 +0530 Subject: [PATCH] island: Move `get_mode()` and `set_mode()` to a single file `island_mode_service.py` --- monkey/monkey_island/cc/resources/island_mode.py | 3 +-- monkey/monkey_island/cc/services/config.py | 2 +- .../cc/services/mode/get_island_mode_service.py | 15 --------------- ...and_mode_service.py => island_mode_service.py} | 14 ++++++++++++++ 4 files changed, 16 insertions(+), 18 deletions(-) delete mode 100644 monkey/monkey_island/cc/services/mode/get_island_mode_service.py rename monkey/monkey_island/cc/services/mode/{set_island_mode_service.py => island_mode_service.py} (69%) diff --git a/monkey/monkey_island/cc/resources/island_mode.py b/monkey/monkey_island/cc/resources/island_mode.py index a7d0a81de..7698fca9d 100644 --- a/monkey/monkey_island/cc/resources/island_mode.py +++ b/monkey/monkey_island/cc/resources/island_mode.py @@ -5,9 +5,8 @@ import flask_restful from flask import make_response, request from monkey_island.cc.resources.auth.auth import jwt_required -from monkey_island.cc.services.mode.get_island_mode_service import ModeNotSetError, get_mode +from monkey_island.cc.services.mode.island_mode_service import ModeNotSetError, get_mode, set_mode from monkey_island.cc.services.mode.mode_enum import IslandModeEnum -from monkey_island.cc.services.mode.set_island_mode_service import set_mode logger = logging.getLogger(__name__) diff --git a/monkey/monkey_island/cc/services/config.py b/monkey/monkey_island/cc/services/config.py index 2dfcd175b..8a107f5b5 100644 --- a/monkey/monkey_island/cc/services/config.py +++ b/monkey/monkey_island/cc/services/config.py @@ -10,7 +10,7 @@ from monkey_island.cc.database import mongo from monkey_island.cc.server_utils.encryptor import get_encryptor from monkey_island.cc.services.config_manipulator import update_config_per_mode from monkey_island.cc.services.config_schema.config_schema import SCHEMA -from monkey_island.cc.services.mode.get_island_mode_service import ModeNotSetError, get_mode +from monkey_island.cc.services.mode.island_mode_service import ModeNotSetError, get_mode from monkey_island.cc.services.post_breach_files import PostBreachFilesService from monkey_island.cc.services.utils.network_utils import local_ip_addresses diff --git a/monkey/monkey_island/cc/services/mode/get_island_mode_service.py b/monkey/monkey_island/cc/services/mode/get_island_mode_service.py deleted file mode 100644 index 1f27ad3b1..000000000 --- a/monkey/monkey_island/cc/services/mode/get_island_mode_service.py +++ /dev/null @@ -1,15 +0,0 @@ -from monkey_island.cc.models.island_mode_model import IslandMode - - -def get_mode() -> str: - if IslandMode.objects: - mode = IslandMode.objects[0].mode - return mode - else: - raise ModeNotSetError - - -class ModeNotSetError(Exception): - """ - Throw this exception when island mode is not set. - """ diff --git a/monkey/monkey_island/cc/services/mode/set_island_mode_service.py b/monkey/monkey_island/cc/services/mode/island_mode_service.py similarity index 69% rename from monkey/monkey_island/cc/services/mode/set_island_mode_service.py rename to monkey/monkey_island/cc/services/mode/island_mode_service.py index ef6f5e5b4..5109c6910 100644 --- a/monkey/monkey_island/cc/services/mode/set_island_mode_service.py +++ b/monkey/monkey_island/cc/services/mode/island_mode_service.py @@ -15,3 +15,17 @@ def set_mode(mode: IslandModeEnum): LOG.error( "Could not apply configuration changes per mode. Using default advanced configuration." ) + + +def get_mode() -> str: + if IslandMode.objects: + mode = IslandMode.objects[0].mode + return mode + else: + raise ModeNotSetError + + +class ModeNotSetError(Exception): + """ + Throw this exception when island mode is not set. + """