Agent: Use distinct fields for SSH Keypair

This commit is contained in:
Ilija Lazoroski 2022-02-16 18:37:16 +01:00
parent 5f8e3e3d8e
commit 897bc11d7b
3 changed files with 9 additions and 6 deletions

View File

@ -6,4 +6,5 @@ from infection_monkey.i_puppet import CredentialType, ICredentialComponent
@dataclass(frozen=True)
class SSHKeypair(ICredentialComponent):
credential_type: CredentialType = field(default=CredentialType.SSH_KEYPAIR, init=False)
content: dict
private_key: str
public_key: str

View File

@ -41,7 +41,11 @@ class SSHCredentialCollector(ICredentialCollector):
ssh_keypair[key] = info[key]
if len(ssh_keypair):
secrets.append(SSHKeypair(ssh_keypair))
secrets.append(
SSHKeypair(
ssh_keypair.get("private_key", ""), ssh_keypair.get("public_key", "")
)
)
if identities != [] or secrets != []:
ssh_credentials.append(Credentials(identities, secrets))

View File

@ -52,10 +52,8 @@ def test_ssh_info_result_parsing(monkeypatch, patch_telemetry_messenger):
username2 = Username("mcus")
username3 = Username("guest")
ssh_keypair1 = SSHKeypair(
{"public_key": "SomePublicKeyUbuntu", "private_key": "ExtremelyGoodPrivateKey"}
)
ssh_keypair2 = SSHKeypair({"public_key": "AnotherPublicKey"})
ssh_keypair1 = SSHKeypair("ExtremelyGoodPrivateKey", "SomePublicKeyUbuntu")
ssh_keypair2 = SSHKeypair("", "AnotherPublicKey")
expected = [
Credentials(identities=[username], secrets=[ssh_keypair1]),