diff --git a/monkey/monkey_island/cc/agent_event_subscribers/__init__.py b/monkey/monkey_island/cc/agent_event_subscribers/__init__.py index f206087d7..755f52bd2 100644 --- a/monkey/monkey_island/cc/agent_event_subscribers/__init__.py +++ b/monkey/monkey_island/cc/agent_event_subscribers/__init__.py @@ -1 +1,2 @@ from .save_event_to_event_repository import save_event_to_event_repository +from .save_stolen_credentials_to_repository import save_stolen_credentials_to_repository diff --git a/monkey/monkey_island/cc/agent_event_subscribers/save_stolen_credentials_to_repository.py b/monkey/monkey_island/cc/agent_event_subscribers/save_stolen_credentials_to_repository.py new file mode 100644 index 000000000..3ac80bb10 --- /dev/null +++ b/monkey/monkey_island/cc/agent_event_subscribers/save_stolen_credentials_to_repository.py @@ -0,0 +1,23 @@ +import logging + +from common.events import CredentialsStolenEvent +from monkey_island.cc.repository import ICredentialsRepository, StorageError + +logger = logging.getLogger(__name__) + + +class save_stolen_credentials_to_repository: + """ + Accepts CredentialsStolenEvent and pushes the stolen credentials into ICredentialsRepository + """ + + def __init__(self, credentials_repository: ICredentialsRepository): + self._credentials_repository = credentials_repository + + def __call__(self, credentials_stolen_event: CredentialsStolenEvent): + try: + self._credentials_repository.save_stolen_credentials( + credentials_stolen_event.stolen_credentials + ) + except StorageError as err: + logger.error(f"Error occurred while storing stolen credentials: {err}")