forked from p15670423/monkey
Agent: Simplify credentials in ssh credentials collector
This commit is contained in:
parent
213b161d1a
commit
f421f42604
|
@ -29,11 +29,11 @@ class SSHCredentialCollector(ICredentialCollector):
|
|||
ssh_credentials = []
|
||||
|
||||
for info in ssh_info:
|
||||
identities = []
|
||||
secrets = []
|
||||
identity = None
|
||||
secret = None
|
||||
|
||||
if info.get("name", ""):
|
||||
identities.append(Username(info["name"]))
|
||||
identity = Username(info["name"])
|
||||
|
||||
ssh_keypair = {}
|
||||
for key in ["public_key", "private_key"]:
|
||||
|
@ -41,13 +41,11 @@ class SSHCredentialCollector(ICredentialCollector):
|
|||
ssh_keypair[key] = info[key]
|
||||
|
||||
if len(ssh_keypair):
|
||||
secrets.append(
|
||||
SSHKeypair(
|
||||
ssh_keypair.get("private_key", ""), ssh_keypair.get("public_key", "")
|
||||
)
|
||||
secret = SSHKeypair(
|
||||
ssh_keypair.get("private_key", ""), ssh_keypair.get("public_key", "")
|
||||
)
|
||||
|
||||
if identities != [] or secrets != []:
|
||||
ssh_credentials.append(Credentials(identities, secrets))
|
||||
if identity is not None:
|
||||
ssh_credentials.append(Credentials(identity, secret))
|
||||
|
||||
return ssh_credentials
|
||||
|
|
|
@ -55,9 +55,9 @@ def test_ssh_info_result_parsing(monkeypatch, patch_telemetry_messenger):
|
|||
ssh_keypair2 = SSHKeypair("", "AnotherPublicKey")
|
||||
|
||||
expected = [
|
||||
Credentials(identities=[username], secrets=[ssh_keypair1]),
|
||||
Credentials(identities=[username2], secrets=[ssh_keypair2]),
|
||||
Credentials(identities=[username3], secrets=[]),
|
||||
Credentials(identity=username, secret=ssh_keypair1),
|
||||
Credentials(identity=username2, secret=ssh_keypair2),
|
||||
Credentials(identity=username3, secret=None),
|
||||
]
|
||||
collected = SSHCredentialCollector(patch_telemetry_messenger).collect_credentials()
|
||||
assert expected == collected
|
||||
|
|
Loading…
Reference in New Issue