From 736c8008a01d17c9f71a5bbf58149f0c3bddb20d Mon Sep 17 00:00:00 2001 From: Shreya Date: Wed, 21 Jul 2021 18:00:55 +0530 Subject: [PATCH] island: Update config after mode set in island mode resource instead of island mode service --- monkey/monkey_island/cc/resources/island_mode.py | 9 ++++++++- .../cc/services/mode/island_mode_service.py | 5 ----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/monkey/monkey_island/cc/resources/island_mode.py b/monkey/monkey_island/cc/resources/island_mode.py index 7698fca9d..6df681fd7 100644 --- a/monkey/monkey_island/cc/resources/island_mode.py +++ b/monkey/monkey_island/cc/resources/island_mode.py @@ -5,10 +5,11 @@ import flask_restful from flask import make_response, request from monkey_island.cc.resources.auth.auth import jwt_required +from monkey_island.cc.services.config_manipulator import update_config_on_mode_set 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 -logger = logging.getLogger(__name__) +LOG = logging.getLogger(__name__) class IslandMode(flask_restful.Resource): @@ -21,6 +22,12 @@ class IslandMode(flask_restful.Resource): mode = IslandModeEnum(mode_str) set_mode(mode) + if not update_config_on_mode_set(mode): + LOG.error( + "Could not apply configuration changes per mode. " + "Using default advanced configuration." + ) + return make_response({}, 200) except (AttributeError, json.decoder.JSONDecodeError): return make_response({}, 400) diff --git a/monkey/monkey_island/cc/services/mode/island_mode_service.py b/monkey/monkey_island/cc/services/mode/island_mode_service.py index 5109c6910..c45e03116 100644 --- a/monkey/monkey_island/cc/services/mode/island_mode_service.py +++ b/monkey/monkey_island/cc/services/mode/island_mode_service.py @@ -1,7 +1,6 @@ import logging from monkey_island.cc.models.island_mode_model import IslandMode -from monkey_island.cc.services.config_manipulator import update_config_on_mode_set from monkey_island.cc.services.mode.mode_enum import IslandModeEnum LOG = logging.getLogger(__name__) @@ -11,10 +10,6 @@ def set_mode(mode: IslandModeEnum): island_mode_model = IslandMode() island_mode_model.mode = mode.value island_mode_model.save() - if not update_config_on_mode_set(mode): - LOG.error( - "Could not apply configuration changes per mode. Using default advanced configuration." - ) def get_mode() -> str: