forked from p15670423/monkey
Island: Add FileRepositoryLoggingDecorator
This commit is contained in:
parent
c00249fc17
commit
bc0c4a1c8e
|
@ -1,6 +1,7 @@
|
||||||
from .errors import RemovalError, RetrievalError, StorageError
|
from .errors import RemovalError, RetrievalError, StorageError
|
||||||
from .i_file_repository import FileNotFoundError, IFileRepository
|
from .i_file_repository import FileNotFoundError, IFileRepository
|
||||||
from .local_storage_file_repository import LocalStorageFileRepository
|
from .local_storage_file_repository import LocalStorageFileRepository
|
||||||
|
from .file_repository_logging_decorator import FileRepositoryLoggingDecorator
|
||||||
from .i_agent_binary_repository import IAgentBinaryRepository
|
from .i_agent_binary_repository import IAgentBinaryRepository
|
||||||
from .agent_binary_repository import AgentBinaryRepository
|
from .agent_binary_repository import AgentBinaryRepository
|
||||||
from .i_agent_configuration_repository import IAgentConfigurationRepository
|
from .i_agent_configuration_repository import IAgentConfigurationRepository
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
import logging
|
||||||
|
from typing import BinaryIO
|
||||||
|
|
||||||
|
from . import IFileRepository
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class FileRepositoryLoggingDecorator(IFileRepository):
|
||||||
|
def __init__(self, file_repository: IFileRepository):
|
||||||
|
self._file_repository = file_repository
|
||||||
|
|
||||||
|
def save_file(self, unsafe_file_name: str, file_contents: BinaryIO):
|
||||||
|
logger.info(f"Saving file {unsafe_file_name}")
|
||||||
|
|
||||||
|
return self._file_repository.save_file(unsafe_file_name, file_contents)
|
||||||
|
|
||||||
|
def open_file(self, unsafe_file_name: str) -> BinaryIO:
|
||||||
|
logger.info(f"Opening file {unsafe_file_name}")
|
||||||
|
|
||||||
|
return self._file_repository.open_file(unsafe_file_name)
|
||||||
|
|
||||||
|
def delete_file(self, unsafe_file_name: str):
|
||||||
|
logger.info(f"Deleting file {unsafe_file_name}")
|
||||||
|
|
||||||
|
return self._file_repository.delete_file(unsafe_file_name)
|
||||||
|
|
||||||
|
def delete_all_files(self):
|
||||||
|
logger.info("Deleting all files in the repository")
|
||||||
|
|
||||||
|
return self._file_repository.delete_all_files()
|
Loading…
Reference in New Issue