island: Move `get_mode()` and `set_mode()` to a single file `island_mode_service.py`

This commit is contained in:
Shreya 2021-07-21 17:49:28 +05:30
parent 7b79c297b9
commit af7651c53b
4 changed files with 16 additions and 18 deletions

View File

@ -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__)

View File

@ -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

View File

@ -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.
"""

View File

@ -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.
"""