Island: Add FileRepositoryLoggingDecorator

This commit is contained in:
Mike Salvatore 2022-07-02 09:49:12 -04:00
parent c00249fc17
commit bc0c4a1c8e
2 changed files with 32 additions and 0 deletions

View File

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

View File

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