Island: small improvements code style in credential parsing code
This commit is contained in:
parent
9d23c3dd62
commit
e17d95bf18
|
@ -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"],
|
||||
|
|
|
@ -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"]
|
||||
]
|
||||
|
||||
|
|
|
@ -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"]
|
||||
|
||||
|
|
Loading…
Reference in New Issue