island: Create custom PBA directory on PostBreachFilesService init

This commit is contained in:
Mike Salvatore 2021-05-11 08:44:31 -04:00
parent be0f7ac881
commit ca65330e86
4 changed files with 13 additions and 5 deletions

View File

@ -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):
"""

View File

@ -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

View File

@ -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)

View File

@ -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():