From 638658178b3a90791999c787b20142dab087888a Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Tue, 29 Mar 2022 13:39:58 +0200 Subject: [PATCH] Agent: Create credential attribute even if we don't have credentials --- .../aggregating_credentials_store.py | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/monkey/infection_monkey/credential_store/aggregating_credentials_store.py b/monkey/infection_monkey/credential_store/aggregating_credentials_store.py index 31c0a156a..f95611166 100644 --- a/monkey/infection_monkey/credential_store/aggregating_credentials_store.py +++ b/monkey/infection_monkey/credential_store/aggregating_credentials_store.py @@ -48,22 +48,27 @@ class AggregatingCredentialsStore(ICredentialsStore): def _aggregate_credentials(self, credentials_to_aggr: Mapping): for cred_attr, credentials_values in credentials_to_aggr.items(): - if credentials_values: - self._set_attribute(cred_attr, credentials_values) + self._set_attribute(cred_attr, credentials_values) def _set_attribute(self, attribute_to_be_set, credentials_values): if attribute_to_be_set not in self.stored_credentials: self.stored_credentials[attribute_to_be_set] = [] - if isinstance(credentials_values[0], dict): - self.stored_credentials.setdefault(attribute_to_be_set, []).extend(credentials_values) - self.stored_credentials[attribute_to_be_set] = [ - dict(s_c) - for s_c in set( - frozenset(d_c.items()) for d_c in self.stored_credentials[attribute_to_be_set] + if credentials_values: + if isinstance(credentials_values[0], dict): + self.stored_credentials.setdefault(attribute_to_be_set, []).extend( + credentials_values + ) + self.stored_credentials[attribute_to_be_set] = [ + dict(s_c) + for s_c in set( + frozenset(d_c.items()) + for d_c in self.stored_credentials[attribute_to_be_set] + ) + ] + else: + self.stored_credentials[attribute_to_be_set] = sorted( + list( + set(self.stored_credentials[attribute_to_be_set]).union(credentials_values) + ) ) - ] - else: - self.stored_credentials[attribute_to_be_set] = sorted( - list(set(self.stored_credentials[attribute_to_be_set]).union(credentials_values)) - )