From cc00b85edc846f0cd0e157e350275a015ad8ec18 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Tue, 1 Jun 2021 12:54:52 +0300 Subject: [PATCH] Refactored monkey island startup files to the old structure which was compatible with our build scripts. --- monkey/monkey_island.py | 32 ++------------------- monkey/monkey_island/monkey_island.spec | 2 +- monkey/monkey_island/startup.py | 37 +++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 31 deletions(-) create mode 100644 monkey/monkey_island/startup.py diff --git a/monkey/monkey_island.py b/monkey/monkey_island.py index f96314c63..b51ffcb94 100644 --- a/monkey/monkey_island.py +++ b/monkey/monkey_island.py @@ -1,32 +1,4 @@ -# This import patches other imports and needs to be first -import monkey_island.setup.gevent_setup # noqa: F401 isort:skip - -import json - -from monkey_island.cc.arg_parser import parse_cli_args -from monkey_island.cc.server_setup import setup_island -from monkey_island.cc.server_utils.island_logger import setup_logging -from monkey_island.setup.config_setup import setup_config_by_cmd_arg, setup_default_config +from monkey_island.startup import start_island if "__main__" == __name__: - island_args = parse_cli_args() - - # This is here in order to catch EVERYTHING, some functions are being called on - # imports, so the log init needs to be first. - try: - if island_args.server_config_path: - config, server_config_path = setup_config_by_cmd_arg(island_args.server_config_path) - else: - config, server_config_path = setup_default_config() - - setup_logging(config.data_dir, config.log_level) - - except OSError as ex: - print(f"Error opening server config file: {ex}") - exit(1) - - except json.JSONDecodeError as ex: - print(f"Error loading server config: {ex}") - exit(1) - - setup_island(island_args.setup_only, config, server_config_path) + start_island() diff --git a/monkey/monkey_island/monkey_island.spec b/monkey/monkey_island/monkey_island.spec index 59f95e34f..9994fbffd 100644 --- a/monkey/monkey_island/monkey_island.spec +++ b/monkey/monkey_island/monkey_island.spec @@ -16,7 +16,7 @@ def main(): ("../monkey_island/cc/services/attack/attack_data", "/monkey_island/cc/services/attack/attack_data") ] - a = Analysis(['cc/main.py'], + a = Analysis(['startup.py'], pathex=['..'], hiddenimports=get_hidden_imports(), hookspath=[os.path.join(".", "pyinstaller_hooks")], diff --git a/monkey/monkey_island/startup.py b/monkey/monkey_island/startup.py new file mode 100644 index 000000000..f53c679ab --- /dev/null +++ b/monkey/monkey_island/startup.py @@ -0,0 +1,37 @@ +# This import patches other imports and needs to be first +import monkey_island.setup.gevent_setup # noqa: F401 isort:skip + +import json + +from monkey_island.cc.arg_parser import parse_cli_args +from monkey_island.cc.server_setup import setup_island +from monkey_island.cc.server_utils.island_logger import setup_logging +from monkey_island.setup.config_setup import setup_config_by_cmd_arg, setup_default_config + + +def start_island(): + island_args = parse_cli_args() + + # This is here in order to catch EVERYTHING, some functions are being called on + # imports, so the log init needs to be first. + try: + if island_args.server_config_path: + config, server_config_path = setup_config_by_cmd_arg(island_args.server_config_path) + else: + config, server_config_path = setup_default_config() + + setup_logging(config.data_dir, config.log_level) + + except OSError as ex: + print(f"Error opening server config file: {ex}") + exit(1) + + except json.JSONDecodeError as ex: + print(f"Error loading server config: {ex}") + exit(1) + + setup_island(island_args.setup_only, config, server_config_path) + + +if "__main__" == __name__: + start_island()