diff --git a/monkey/monkey_island/cc/services/__init__.py b/monkey/monkey_island/cc/services/__init__.py index b3dcba9de..15d0b801d 100644 --- a/monkey/monkey_island/cc/services/__init__.py +++ b/monkey/monkey_island/cc/services/__init__.py @@ -1,2 +1,3 @@ from .authentication.authentication_service import AuthenticationService from .authentication.json_file_user_datastore import JsonFileUserDatastore +from .i_file_storage_service import IFileStorageService diff --git a/monkey/monkey_island/cc/services/i_file_storage_service.py b/monkey/monkey_island/cc/services/i_file_storage_service.py new file mode 100644 index 000000000..a27cbf6ad --- /dev/null +++ b/monkey/monkey_island/cc/services/i_file_storage_service.py @@ -0,0 +1,45 @@ +import abc +from typing import BinaryIO + + +class IFileStorageService(metaclass=abc.ABCMeta): + """ + A service that allows the storage and retrieval of individual files. + """ + + @abc.abstractmethod + def save_file(self, unsafe_file_name: str, file_contents: BinaryIO): + """ + Save a file, identified by a name + + :param unsafe_file_name: An unsanitized file name that will identify the file + :param file_contents: The data to be stored in the file + """ + pass + + @abc.abstractmethod + def open_file(self, unsafe_file_name: str) -> BinaryIO: + """ + Open a file and return a file-like object + + :param unsafe_file_name: An unsanitized file name that identifies the file to be opened + :return: A file-like object providing access to the file's contents + :rtype: io.BinaryIO + """ + pass + + @abc.abstractmethod + def delete_file(self, unsafe_file_name: str): + """ + Delete a file + + :param unsafe_file_name: An unsanitized file name that identifies the file to be deleted + """ + pass + + @abc.abstractmethod + def delete_all_files(self): + """ + Delete all files that have been stored using this service. + """ + pass