forked from p15670423/monkey
island: Remove circular dep btw ConfigService and PostBreachFilesService
This commit is contained in:
parent
ea82e86df5
commit
9476441526
|
@ -9,9 +9,11 @@ import monkey_island.cc.environment.environment_singleton as env_singleton
|
||||||
from monkey_island.cc.database import mongo
|
from monkey_island.cc.database import mongo
|
||||||
from monkey_island.cc.server_utils.encryptor import get_encryptor
|
from monkey_island.cc.server_utils.encryptor import get_encryptor
|
||||||
from monkey_island.cc.services.config_schema.config_schema import SCHEMA
|
from monkey_island.cc.services.config_schema.config_schema import SCHEMA
|
||||||
|
from monkey_island.cc.services.post_breach_files import (
|
||||||
# TODO: Remove circular dependency between ConfigService and PostBreachFilesService.
|
PBA_LINUX_FILENAME_PATH,
|
||||||
from monkey_island.cc.services.post_breach_files import PostBreachFilesService
|
PBA_WINDOWS_FILENAME_PATH,
|
||||||
|
PostBreachFilesService,
|
||||||
|
)
|
||||||
from monkey_island.cc.services.utils.network_utils import local_ip_addresses
|
from monkey_island.cc.services.utils.network_utils import local_ip_addresses
|
||||||
|
|
||||||
__author__ = "itay.mizeretz"
|
__author__ = "itay.mizeretz"
|
||||||
|
@ -193,7 +195,7 @@ class ConfigService:
|
||||||
# PBA file upload happens on pba_file_upload endpoint and corresponding config options
|
# PBA file upload happens on pba_file_upload endpoint and corresponding config options
|
||||||
# are set there
|
# are set there
|
||||||
config_json = ConfigService._filter_none_values(config_json)
|
config_json = ConfigService._filter_none_values(config_json)
|
||||||
PostBreachFilesService.set_config_PBA_files(config_json)
|
ConfigService.set_config_PBA_files(config_json)
|
||||||
if should_encrypt:
|
if should_encrypt:
|
||||||
try:
|
try:
|
||||||
ConfigService.encrypt_config(config_json)
|
ConfigService.encrypt_config(config_json)
|
||||||
|
@ -204,6 +206,19 @@ class ConfigService:
|
||||||
logger.info("monkey config was updated")
|
logger.info("monkey config was updated")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def set_config_PBA_files(config_json):
|
||||||
|
"""
|
||||||
|
Sets PBA file info in config_json to current config's PBA file info values.
|
||||||
|
:param config_json: config_json that will be modified
|
||||||
|
"""
|
||||||
|
if ConfigService.get_config():
|
||||||
|
linux_filename = ConfigService.get_config_value(PBA_LINUX_FILENAME_PATH)
|
||||||
|
windows_filename = ConfigService.get_config_value(PBA_WINDOWS_FILENAME_PATH)
|
||||||
|
|
||||||
|
config_json["monkey"]["post_breach"]["PBA_linux_filename"] = linux_filename
|
||||||
|
config_json["monkey"]["post_breach"]["PBA_windows_filename"] = windows_filename
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def init_default_config():
|
def init_default_config():
|
||||||
if ConfigService.default_config is None:
|
if ConfigService.default_config is None:
|
||||||
|
|
|
@ -2,16 +2,13 @@ import logging
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
# TODO: Remove circular dependency between ConfigService and PostBreachFilesService.
|
|
||||||
import monkey_island.cc.services.config
|
|
||||||
|
|
||||||
__author__ = "VakarisZ"
|
__author__ = "VakarisZ"
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Where to find file names in config
|
# Where to find file names in config
|
||||||
PBA_WINDOWS_FILENAME_PATH = ["monkey", "post_breach", "PBA_windows_filename"]
|
|
||||||
PBA_LINUX_FILENAME_PATH = ["monkey", "post_breach", "PBA_linux_filename"]
|
PBA_LINUX_FILENAME_PATH = ["monkey", "post_breach", "PBA_linux_filename"]
|
||||||
|
PBA_WINDOWS_FILENAME_PATH = ["monkey", "post_breach", "PBA_windows_filename"]
|
||||||
|
|
||||||
|
|
||||||
class PostBreachFilesService:
|
class PostBreachFilesService:
|
||||||
|
@ -45,19 +42,3 @@ class PostBreachFilesService:
|
||||||
return os.path.join(
|
return os.path.join(
|
||||||
PostBreachFilesService.DATA_DIR, PostBreachFilesService.CUSTOM_PBA_DIRNAME
|
PostBreachFilesService.DATA_DIR, PostBreachFilesService.CUSTOM_PBA_DIRNAME
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def set_config_PBA_files(config_json):
|
|
||||||
"""
|
|
||||||
Sets PBA file info in config_json to current config's PBA file info values.
|
|
||||||
:param config_json: config_json that will be modified
|
|
||||||
"""
|
|
||||||
if monkey_island.cc.services.config.ConfigService.get_config():
|
|
||||||
linux_filename = monkey_island.cc.services.config.ConfigService.get_config_value(
|
|
||||||
PBA_LINUX_FILENAME_PATH
|
|
||||||
)
|
|
||||||
windows_filename = monkey_island.cc.services.config.ConfigService.get_config_value(
|
|
||||||
PBA_WINDOWS_FILENAME_PATH
|
|
||||||
)
|
|
||||||
config_json["monkey"]["post_breach"]["PBA_linux_filename"] = linux_filename
|
|
||||||
config_json["monkey"]["post_breach"]["PBA_windows_filename"] = windows_filename
|
|
||||||
|
|
Loading…
Reference in New Issue