island: Return and log if config update was not successful on mode set

This commit is contained in:
Shreya 2021-07-20 14:01:20 +05:30
parent fab7738174
commit 9c48c115be
2 changed files with 12 additions and 5 deletions

View File

@ -249,14 +249,14 @@ class ConfigService:
return config
@staticmethod
def update_config_on_mode_set(mode: IslandModeEnum) -> None:
def update_config_on_mode_set(mode: IslandModeEnum) -> bool:
config = ConfigService.get_config()
ConfigService.update_config_per_mode(mode, config, True)
return ConfigService.update_config_per_mode(mode, config, True)
@staticmethod
def update_config_per_mode(mode: IslandModeEnum, config: Dict, should_encrypt: bool) -> None:
def update_config_per_mode(mode: IslandModeEnum, config: Dict, should_encrypt: bool) -> bool:
config = ConfigService._set_default_config_values_per_mode(mode, config)
ConfigService.update_config(config_json=config, should_encrypt=True)
return ConfigService.update_config(config_json=config, should_encrypt=True)
@staticmethod
def _set_default_config_values_per_mode(mode: IslandModeEnum, config: Dict) -> Dict:

View File

@ -1,10 +1,17 @@
import logging
from monkey_island.cc.models.island_mode_model import IslandMode
from monkey_island.cc.services.config import ConfigService
from monkey_island.cc.services.mode.mode_enum import IslandModeEnum
LOG = logging.getLogger(__name__)
def set_mode(mode: IslandModeEnum):
island_mode_model = IslandMode()
island_mode_model.mode = mode.value
island_mode_model.save()
ConfigService.update_config_on_mode_set(mode)
if not ConfigService.update_config_on_mode_set(mode):
LOG.error(
"Could not apply configuration changes per mode. Using default advanced configuration."
)