From 66b3fb1d4749646ca4673194ff44c60e2381cf7a Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Fri, 21 May 2021 12:10:24 +0300 Subject: [PATCH] Added boilerplate methods for mongodb launch. --- monkey/monkey_island/cc/main.py | 10 ++++++---- monkey/monkey_island/cc/{setup.py => mongo_setup.py} | 7 ++++++- 2 files changed, 12 insertions(+), 5 deletions(-) rename monkey/monkey_island/cc/{setup.py => mongo_setup.py} (94%) diff --git a/monkey/monkey_island/cc/main.py b/monkey/monkey_island/cc/main.py index b9dd9b197..21b118447 100644 --- a/monkey/monkey_island/cc/main.py +++ b/monkey/monkey_island/cc/main.py @@ -24,13 +24,13 @@ from common.version import get_version # noqa: E402 from monkey_island.cc.app import init_app # noqa: E402 from monkey_island.cc.database import get_db_version # noqa: E402 from monkey_island.cc.database import is_db_server_up # noqa: E402 +from monkey_island.cc.mongo_setup import init_collections, launch_mongodb # noqa: E402 from monkey_island.cc.resources.monkey_download import MonkeyDownload # noqa: E402 from monkey_island.cc.server_utils.bootloader_server import BootloaderHttpServer # noqa: E402 from monkey_island.cc.server_utils.encryptor import initialize_encryptor # noqa: E402 from monkey_island.cc.services.initialize import initialize_services # noqa: E402 from monkey_island.cc.services.reporting.exporter_init import populate_exporter_list # noqa: E402 from monkey_island.cc.services.utils.network_utils import local_ip_addresses # noqa: E402 -from monkey_island.cc.setup import setup # noqa: E402 MINIMUM_MONGO_DB_VERSION_REQUIRED = "4.2.0" @@ -47,11 +47,13 @@ def main(setup_only: bool, server_config_path: str, config_options: IslandConfig ) bootloader_server_thread.start() - start_island_server(setup_only) + start_island_server(setup_only, config_options) bootloader_server_thread.join() -def start_island_server(should_setup_only): +def start_island_server(should_setup_only, config_options: IslandConfigOptions): + if config_options.start_mongodb: + launch_mongodb() mongo_url = os.environ.get("MONGO_URL", env_singleton.env.get_mongo_url()) wait_for_mongo_db_server(mongo_url) assert_mongo_db_version(mongo_url) @@ -62,7 +64,7 @@ def start_island_server(should_setup_only): crt_path = str(Path(MONKEY_ISLAND_ABS_PATH, "cc", "server.crt")) key_path = str(Path(MONKEY_ISLAND_ABS_PATH, "cc", "server.key")) - setup() + init_collections() if should_setup_only: logger.warning("Setup only flag passed. Exiting.") diff --git a/monkey/monkey_island/cc/setup.py b/monkey/monkey_island/cc/mongo_setup.py similarity index 94% rename from monkey/monkey_island/cc/setup.py rename to monkey/monkey_island/cc/mongo_setup.py index a03c554be..74cb29fc2 100644 --- a/monkey/monkey_island/cc/setup.py +++ b/monkey/monkey_island/cc/mongo_setup.py @@ -9,7 +9,12 @@ from monkey_island.cc.services.attack.mitre_api_interface import MitreApiInterfa logger = logging.getLogger(__name__) -def setup(): +def launch_mongodb(): + # TODO: Implement the launch of mongodb process + pass + + +def init_collections(): logger.info("Setting up the Monkey Island, this might take a while...") try_store_mitigations_on_mongo()