From 7bcf49daf98166c93825f87bbaa49268062fe764 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 7 Jul 2022 13:06:38 -0400 Subject: [PATCH] Island: Modify ICredentialsRepository to save a Sequence of Credentials --- .../cc/repository/i_credentials_repository.py | 4 ++-- .../cc/repository/mongo_credentials_repository.py | 8 ++++---- .../stub_propagation_credentials_repository.py | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/monkey/monkey_island/cc/repository/i_credentials_repository.py b/monkey/monkey_island/cc/repository/i_credentials_repository.py index 42fc3898f..381782533 100644 --- a/monkey/monkey_island/cc/repository/i_credentials_repository.py +++ b/monkey/monkey_island/cc/repository/i_credentials_repository.py @@ -43,7 +43,7 @@ class ICredentialsRepository(ABC): """ pass - def save_configured_credentials(self, credentials: Credentials): + def save_configured_credentials(self, credentials: Sequence[Credentials]): """ Save credentials that were configured. @@ -52,7 +52,7 @@ class ICredentialsRepository(ABC): """ pass - def save_stolen_credentials(self, credentials: Credentials): + def save_stolen_credentials(self, credentials: Sequence[Credentials]): """ Save credentials that were stolen during a simulation. diff --git a/monkey/monkey_island/cc/repository/mongo_credentials_repository.py b/monkey/monkey_island/cc/repository/mongo_credentials_repository.py index c124490a4..df5d0e417 100644 --- a/monkey/monkey_island/cc/repository/mongo_credentials_repository.py +++ b/monkey/monkey_island/cc/repository/mongo_credentials_repository.py @@ -34,15 +34,15 @@ class MongoCredentialsRepository(ICredentialsRepository): except RetrievalError as err: raise err - def save_configured_credentials(self, credentials: Credentials): + def save_configured_credentials(self, credentials: Sequence[Credentials]): try: - mongo.db.configured_credentials.insert_one(credentials) + mongo.db.configured_credentials.insert_many(credentials) except Exception as err: raise StorageError(err) - def save_stolen_credentials(self, credentials: Credentials): + def save_stolen_credentials(self, credentials: Sequence[Credentials]): try: - mongo.db.stolen_credentials.insert_one(credentials) + mongo.db.stolen_credentials.insert_many(credentials) except Exception as err: raise StorageError(err) diff --git a/monkey/tests/monkey_island/stub_propagation_credentials_repository.py b/monkey/tests/monkey_island/stub_propagation_credentials_repository.py index 7bf6f85a7..7a2375c6c 100644 --- a/monkey/tests/monkey_island/stub_propagation_credentials_repository.py +++ b/monkey/tests/monkey_island/stub_propagation_credentials_repository.py @@ -47,10 +47,10 @@ class StubPropagationCredentialsRepository(ICredentialsRepository): Credentials.from_mapping(PROPAGATION_CREDENTIALS_2, monkey_guid="second_guid"), ] - def save_configured_credentials(self, credentials: Credentials): + def save_configured_credentials(self, credentials: Sequence[Credentials]): pass - def save_stolen_credentials(self, credentials: Credentials): + def save_stolen_credentials(self, credentials: Sequence[Credentials]): pass def remove_configured_credentials(self):