From 55f95891e10079b9d1a5a21822c14e686c322fe7 Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Mon, 18 Jul 2022 13:35:40 +0200 Subject: [PATCH] Island: Fix minor things in MongoCredentialsRepository and credentials endpoint --- .../mongo_credentials_repository.py | 30 +++++-------------- .../cc/resources/propagation_credentials.py | 2 +- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/monkey/monkey_island/cc/repository/mongo_credentials_repository.py b/monkey/monkey_island/cc/repository/mongo_credentials_repository.py index cfeb0874f..ee8beb13c 100644 --- a/monkey/monkey_island/cc/repository/mongo_credentials_repository.py +++ b/monkey/monkey_island/cc/repository/mongo_credentials_repository.py @@ -15,19 +15,13 @@ class MongoCredentialsRepository(ICredentialsRepository): def __init__(self, mongo: MongoClient, repository_encryptor: ILockableEncryptor): self._database = mongo.monkeyisland - + self._repository_encryptor = repository_encryptor def get_configured_credentials(self) -> Sequence[Credentials]: - return MongoCredentialsRepository._get_credentials_from_collection( - self._database.configured_credentials - ) - + return self._get_credentials_from_collection(self._database.configured_credentials) def get_stolen_credentials(self) -> Sequence[Credentials]: - return MongoCredentialsRepository._get_credentials_from_collection( - self._database.stolen_credentials - ) - + return self._get_credentials_from_collection(self._database.stolen_credentials) def get_all_credentials(self) -> Sequence[Credentials]: configured_credentials = self.get_configured_credentials() @@ -37,26 +31,16 @@ class MongoCredentialsRepository(ICredentialsRepository): def save_configured_credentials(self, credentials: Sequence[Credentials]): # TODO: Fix deduplication of Credentials in mongo - MongoCredentialsRepository._save_credentials_to_collection( - credentials, self._database.configured_credentials - ) - + self._save_credentials_to_collection(credentials, self._database.configured_credentials) def save_stolen_credentials(self, credentials: Sequence[Credentials]): - MongoCredentialsRepository._save_credentials_to_collection( - credentials, self._database.stolen_credentials - ) - + self._save_credentials_to_collection(credentials, self._database.stolen_credentials) def remove_configured_credentials(self): - MongoCredentialsRepository._remove_credentials_fom_collection( - self._database.configured_credentials - ) + self._remove_credentials_fom_collection(self._database.configured_credentials) def remove_stolen_credentials(self): - MongoCredentialsRepository._remove_credentials_fom_collection( - self._database.stolen_credentials - ) + self._remove_credentials_fom_collection(self._database.stolen_credentials) def remove_all_credentials(self): self.remove_configured_credentials() diff --git a/monkey/monkey_island/cc/resources/propagation_credentials.py b/monkey/monkey_island/cc/resources/propagation_credentials.py index 9ef22f832..978569cee 100644 --- a/monkey/monkey_island/cc/resources/propagation_credentials.py +++ b/monkey/monkey_island/cc/resources/propagation_credentials.py @@ -29,7 +29,7 @@ class PropagationCredentials(AbstractResource): return propagation_credentials, HTTPStatus.OK def post(self, collection=None): - credentials = [Credentials.from_mapping(c) for c in request.json] + credentials = [Credentials.from_json(c) for c in request.json] if collection == _configured_collection: self._credentials_repository.save_configured_credentials(credentials)