From 4db251dd7d933d1f3381a77d94a4bb342bbaf3d9 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 14 Sep 2022 13:49:23 -0400 Subject: [PATCH] Island: Add save_stolen_credentials_to_repository --- .../cc/agent_event_subscribers/__init__.py | 1 + .../save_stolen_credentials_to_repository.py | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 monkey/monkey_island/cc/agent_event_subscribers/save_stolen_credentials_to_repository.py 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}")