From ca65330e863eb91205f6d007751e4e0270a32f01 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 11 May 2021 08:44:31 -0400 Subject: [PATCH] island: Create custom PBA directory on PostBreachFilesService init --- monkey/monkey_island/cc/resources/pba_file_upload.py | 4 ---- monkey/monkey_island/cc/services/config.py | 2 ++ monkey/monkey_island/cc/services/initialize.py | 2 +- monkey/monkey_island/cc/services/post_breach_files.py | 10 ++++++++++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/monkey/monkey_island/cc/resources/pba_file_upload.py b/monkey/monkey_island/cc/resources/pba_file_upload.py index 6ae209a12..01cae595e 100644 --- a/monkey/monkey_island/cc/resources/pba_file_upload.py +++ b/monkey/monkey_island/cc/resources/pba_file_upload.py @@ -28,10 +28,6 @@ class FileUpload(flask_restful.Resource): File upload endpoint used to exchange files with filepond component on the front-end """ - def __init__(self): - # Create all directories on the way if they don't exist - Path(env_singleton.env.get_config().data_dir_abs_path).mkdir(parents=True, exist_ok=True) - @jwt_required def get(self, file_type): """ diff --git a/monkey/monkey_island/cc/services/config.py b/monkey/monkey_island/cc/services/config.py index 4b41501b4..3dbdd9039 100644 --- a/monkey/monkey_island/cc/services/config.py +++ b/monkey/monkey_island/cc/services/config.py @@ -9,6 +9,8 @@ import monkey_island.cc.environment.environment_singleton as env_singleton from monkey_island.cc.database import mongo from monkey_island.cc.server_utils.encryptor import get_encryptor from monkey_island.cc.services.config_schema.config_schema import SCHEMA + +# TODO: Remove circular dependency between ConfigService and PostBreachFilesService. from monkey_island.cc.services.post_breach_files import PostBreachFilesService from monkey_island.cc.services.utils.network_utils import local_ip_addresses diff --git a/monkey/monkey_island/cc/services/initialize.py b/monkey/monkey_island/cc/services/initialize.py index 45301946f..564babcac 100644 --- a/monkey/monkey_island/cc/services/initialize.py +++ b/monkey/monkey_island/cc/services/initialize.py @@ -6,4 +6,4 @@ def initialize_services(data_dir): def initialize_post_breach_file_service(data_dir): - PostBreachFilesService.DATA_DIR = data_dir + PostBreachFilesService.initialize(data_dir) diff --git a/monkey/monkey_island/cc/services/post_breach_files.py b/monkey/monkey_island/cc/services/post_breach_files.py index d0c1b6a56..a56c585de 100644 --- a/monkey/monkey_island/cc/services/post_breach_files.py +++ b/monkey/monkey_island/cc/services/post_breach_files.py @@ -1,6 +1,8 @@ import logging import os +from pathlib import Path +# TODO: Remove circular dependency between ConfigService and PostBreachFilesService. import monkey_island.cc.services.config __author__ = "VakarisZ" @@ -16,6 +18,14 @@ class PostBreachFilesService: DATA_DIR = None CUSTOM_PBA_DIRNAME = "custom_pbas" + # TODO: A number of these services should be instance objects instead of + # static/singleton hybrids. At the moment, this requires invasive refactoring that's + # not a priority. + @classmethod + def initialize(cls, data_dir): + cls.DATA_DIR = data_dir + Path(cls.get_custom_pba_directory()).mkdir(mode=0o0700, parents=True, exist_ok=True) + @staticmethod def remove_PBA_files(): if monkey_island.cc.services.config.ConfigService.get_config():