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 = []
|
ssh_credentials = []
|
||||||
|
|
||||||
for info in ssh_info:
|
for info in ssh_info:
|
||||||
identities = []
|
identity = None
|
||||||
secrets = []
|
secret = None
|
||||||
|
|
||||||
if info.get("name", ""):
|
if info.get("name", ""):
|
||||||
identities.append(Username(info["name"]))
|
identity = Username(info["name"])
|
||||||
|
|
||||||
ssh_keypair = {}
|
ssh_keypair = {}
|
||||||
for key in ["public_key", "private_key"]:
|
for key in ["public_key", "private_key"]:
|
||||||
|
@ -41,13 +41,11 @@ class SSHCredentialCollector(ICredentialCollector):
|
||||||
ssh_keypair[key] = info[key]
|
ssh_keypair[key] = info[key]
|
||||||
|
|
||||||
if len(ssh_keypair):
|
if len(ssh_keypair):
|
||||||
secrets.append(
|
secret = SSHKeypair(
|
||||||
SSHKeypair(
|
|
||||||
ssh_keypair.get("private_key", ""), ssh_keypair.get("public_key", "")
|
ssh_keypair.get("private_key", ""), ssh_keypair.get("public_key", "")
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
if identities != [] or secrets != []:
|
if identity is not None:
|
||||||
ssh_credentials.append(Credentials(identities, secrets))
|
ssh_credentials.append(Credentials(identity, secret))
|
||||||
|
|
||||||
return ssh_credentials
|
return ssh_credentials
|
||||||
|
|
|
@ -55,9 +55,9 @@ def test_ssh_info_result_parsing(monkeypatch, patch_telemetry_messenger):
|
||||||
ssh_keypair2 = SSHKeypair("", "AnotherPublicKey")
|
ssh_keypair2 = SSHKeypair("", "AnotherPublicKey")
|
||||||
|
|
||||||
expected = [
|
expected = [
|
||||||
Credentials(identities=[username], secrets=[ssh_keypair1]),
|
Credentials(identity=username, secret=ssh_keypair1),
|
||||||
Credentials(identities=[username2], secrets=[ssh_keypair2]),
|
Credentials(identity=username2, secret=ssh_keypair2),
|
||||||
Credentials(identities=[username3], secrets=[]),
|
Credentials(identity=username3, secret=None),
|
||||||
]
|
]
|
||||||
collected = SSHCredentialCollector(patch_telemetry_messenger).collect_credentials()
|
collected = SSHCredentialCollector(patch_telemetry_messenger).collect_credentials()
|
||||||
assert expected == collected
|
assert expected == collected
|
||||||
|
|
Loading…
Reference in New Issue