From 6c1fa80f429fcf9f1edc08390c9b128a0be08002 Mon Sep 17 00:00:00 2001 From: vakarisz Date: Tue, 31 May 2022 13:59:47 +0300 Subject: [PATCH] Island: Rename Filesystem to FileSystem --- .../monkey_island/cc/repository/__init__.py | 2 +- ...stem_storage.py => file_system_storage.py} | 2 +- .../monkey_island/cc/services/initialize.py | 4 ++-- .../test_directory_file_storage_service.py | 24 +++++++++---------- .../cc/services/test_post_breach_files.py | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) rename monkey/monkey_island/cc/repository/file_storage/{filesystem_storage.py => file_system_storage.py} (98%) diff --git a/monkey/monkey_island/cc/repository/__init__.py b/monkey/monkey_island/cc/repository/__init__.py index 020b5a1f2..249e17fd4 100644 --- a/monkey/monkey_island/cc/repository/__init__.py +++ b/monkey/monkey_island/cc/repository/__init__.py @@ -1,2 +1,2 @@ -from .file_storage.filesystem_storage import FilesystemStorage +from .file_storage.file_system_storage import FileSystemStorage from .file_storage.i_file_repository import IFileRepository, FileRetrievalError diff --git a/monkey/monkey_island/cc/repository/file_storage/filesystem_storage.py b/monkey/monkey_island/cc/repository/file_storage/file_system_storage.py similarity index 98% rename from monkey/monkey_island/cc/repository/file_storage/filesystem_storage.py rename to monkey/monkey_island/cc/repository/file_storage/file_system_storage.py index 1d4f1fad2..adc6ff700 100644 --- a/monkey/monkey_island/cc/repository/file_storage/filesystem_storage.py +++ b/monkey/monkey_island/cc/repository/file_storage/file_system_storage.py @@ -11,7 +11,7 @@ from .i_file_repository import FileRetrievalError, IFileRepository logger = logging.getLogger(__name__) -class FilesystemStorage(IFileRepository): +class FileSystemStorage(IFileRepository): """ A implementation of IFileStorageService that reads and writes files from/to the local filesystem. diff --git a/monkey/monkey_island/cc/services/initialize.py b/monkey/monkey_island/cc/services/initialize.py index 3d08d5ca1..08396510b 100644 --- a/monkey/monkey_island/cc/services/initialize.py +++ b/monkey/monkey_island/cc/services/initialize.py @@ -2,7 +2,7 @@ from pathlib import Path from common import DIContainer from common.aws import AWSInstance -from monkey_island.cc.repository import FilesystemStorage, IFileRepository +from monkey_island.cc.repository import FileSystemStorage, IFileRepository from monkey_island.cc.services import AWSService from monkey_island.cc.services.post_breach_files import PostBreachFilesService from monkey_island.cc.services.run_local_monkey import LocalMonkeyRunService @@ -15,7 +15,7 @@ def initialize_services(data_dir: Path) -> DIContainer: container = DIContainer() container.register_instance(AWSInstance, AWSInstance()) - container.register_instance(IFileRepository, FilesystemStorage(data_dir / "custom_pbas")) + container.register_instance(IFileRepository, FileSystemStorage(data_dir / "custom_pbas")) container.register_instance(AWSService, container.resolve(AWSService)) # This is temporary until we get DI all worked out. diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/test_directory_file_storage_service.py b/monkey/tests/unit_tests/monkey_island/cc/services/test_directory_file_storage_service.py index 7ccb62a20..184f66edd 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/test_directory_file_storage_service.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/test_directory_file_storage_service.py @@ -4,7 +4,7 @@ from pathlib import Path import pytest from tests.monkey_island.utils import assert_linux_permissions, assert_windows_permissions -from monkey_island.cc.repository import FileRetrievalError, FilesystemStorage +from monkey_island.cc.repository import FileRetrievalError, FileSystemStorage from monkey_island.cc.server_utils.file_utils import is_windows_os @@ -13,13 +13,13 @@ def test_error_if_storage_directory_is_file(tmp_path): new_file.write_text("HelloWorld!") with pytest.raises(ValueError): - FilesystemStorage(new_file) + FileSystemStorage(new_file) def test_directory_created(tmp_path): new_dir = tmp_path / "new_dir" - FilesystemStorage(new_dir) + FileSystemStorage(new_dir) assert new_dir.exists() and new_dir.is_dir() @@ -28,7 +28,7 @@ def test_directory_created(tmp_path): def test_directory_permissions__linux(tmp_path): new_dir = tmp_path / "new_dir" - FilesystemStorage(new_dir) + FileSystemStorage(new_dir) assert_linux_permissions(new_dir) @@ -37,7 +37,7 @@ def test_directory_permissions__linux(tmp_path): def test_directory_permissions__windows(tmp_path): new_dir = tmp_path / "new_dir" - FilesystemStorage(new_dir) + FileSystemStorage(new_dir) assert_windows_permissions(new_dir) @@ -47,7 +47,7 @@ def save_file(tmp_path, file_path_prefix=""): file_contents = "Hello World!" expected_file_path = tmp_path / file_name - fss = FilesystemStorage(tmp_path) + fss = FileSystemStorage(tmp_path) fss.save_file(Path(file_path_prefix) / file_name, io.BytesIO(file_contents.encode())) assert expected_file_path.is_file() @@ -60,7 +60,7 @@ def delete_file(tmp_path, file_path_prefix=""): file.touch() assert file.is_file() - fss = FilesystemStorage(tmp_path) + fss = FileSystemStorage(tmp_path) fss.delete_file(Path(file_path_prefix) / file_name) assert not file.exists() @@ -72,7 +72,7 @@ def open_file(tmp_path, file_path_prefix=""): expected_file_path = tmp_path / file_name expected_file_path.write_text(expected_file_contents) - fss = FilesystemStorage(tmp_path) + fss = FileSystemStorage(tmp_path) with fss.open_file(Path(file_path_prefix) / file_name) as f: actual_file_contents = f.read() @@ -101,7 +101,7 @@ def test_remove_all_files(tmp_path): for filename in ["1.txt", "2.txt", "3.txt"]: (tmp_path / filename).touch() - fss = FilesystemStorage(tmp_path) + fss = FileSystemStorage(tmp_path) fss.delete_all_files() for file in tmp_path.iterdir(): @@ -114,7 +114,7 @@ def test_remove_all_files__skip_directories(tmp_path): for filename in ["1.txt", "2.txt", "3.txt"]: (tmp_path / filename).touch() - fss = FilesystemStorage(tmp_path) + fss = FileSystemStorage(tmp_path) fss.delete_all_files() for file in tmp_path.iterdir(): @@ -122,14 +122,14 @@ def test_remove_all_files__skip_directories(tmp_path): def test_remove_nonexistant_file(tmp_path): - fss = FilesystemStorage(tmp_path) + fss = FileSystemStorage(tmp_path) # This test will fail if this call raises an exception. fss.delete_file("nonexistant_file.txt") def test_open_nonexistant_file(tmp_path): - fss = FilesystemStorage(tmp_path) + fss = FileSystemStorage(tmp_path) with pytest.raises(FileRetrievalError): fss.open_file("nonexistant_file.txt") diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/test_post_breach_files.py b/monkey/tests/unit_tests/monkey_island/cc/services/test_post_breach_files.py index 6d87627b9..a6f5b5a24 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/test_post_breach_files.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/test_post_breach_files.py @@ -4,13 +4,13 @@ import os import pytest from tests.utils import raise_ -from monkey_island.cc.repository import FilesystemStorage +from monkey_island.cc.repository import FileSystemStorage from monkey_island.cc.services.post_breach_files import PostBreachFilesService @pytest.fixture def file_storage_service(tmp_path): - return FilesystemStorage(tmp_path) + return FileSystemStorage(tmp_path) @pytest.fixture(autouse=True)