diff --git a/monkey/monkey_island/cc/services/telemetry/processing/credentials/credentials.py b/monkey/monkey_island/cc/services/telemetry/processing/credentials/credentials.py index 70d13b594..5cb169ae4 100644 --- a/monkey/monkey_island/cc/services/telemetry/processing/credentials/credentials.py +++ b/monkey/monkey_island/cc/services/telemetry/processing/credentials/credentials.py @@ -1,17 +1,17 @@ from __future__ import annotations from dataclasses import dataclass -from typing import Sequence +from typing import Sequence, Mapping, Any @dataclass(frozen=True) class Credentials: - identities: Sequence[dict] - secrets: Sequence[dict] + identities: Sequence[Mapping] + secrets: Sequence[Mapping] monkey_guid: str @staticmethod - def from_dict(cred_dict: dict, monkey_guid: str) -> Credentials: + def from_mapping(cred_dict: Mapping[str, Any], monkey_guid: str) -> Credentials: return Credentials( identities=cred_dict["identities"], secrets=cred_dict["secrets"], diff --git a/monkey/monkey_island/cc/services/telemetry/processing/credentials/credentials_parser.py b/monkey/monkey_island/cc/services/telemetry/processing/credentials/credentials_parser.py index 2c42fa2c8..9df47f91d 100644 --- a/monkey/monkey_island/cc/services/telemetry/processing/credentials/credentials_parser.py +++ b/monkey/monkey_island/cc/services/telemetry/processing/credentials/credentials_parser.py @@ -24,7 +24,7 @@ CREDENTIAL_COMPONENT_PROCESSORS = { def parse_credentials(telemetry_dict: Mapping): credentials = [ - Credentials.from_dict(credential, telemetry_dict["monkey_guid"]) + Credentials.from_mapping(credential, telemetry_dict["monkey_guid"]) for credential in telemetry_dict["data"] ] diff --git a/monkey/monkey_island/cc/services/telemetry/processing/credentials/secrets/ssh_key_processor.py b/monkey/monkey_island/cc/services/telemetry/processing/credentials/secrets/ssh_key_processor.py index 0b299edfb..0273732da 100644 --- a/monkey/monkey_island/cc/services/telemetry/processing/credentials/secrets/ssh_key_processor.py +++ b/monkey/monkey_island/cc/services/telemetry/processing/credentials/secrets/ssh_key_processor.py @@ -15,13 +15,13 @@ class SSHKeyProcessingError(ValueError): def process_ssh_key(keypair: Mapping, credentials: Credentials): if len(credentials.identities) != 1: raise SSHKeyProcessingError( - f"SSH credentials have {len(credentials.identities)}" f" users associated with " f"it!" + f"SSH credentials have {len(credentials.identities)} users associated with it!" ) if not _contains_both_keys(keypair): - raise SSHKeyProcessingError("Private or public key missing!") + raise SSHKeyProcessingError("Private or public key missing") - # TODO SSH key should be associated with IP that monkey exploited + # TODO investigate if IP is needed at all ip = Monkey.get_single_monkey_by_guid(credentials.monkey_guid).ip_addresses[0] username = credentials.identities[0]["username"]