Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions hcloud/ssh_keys/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ def get_by_name(self, name):
"""
return super(SSHKeysClient, self).get_by_name(name)

def get_by_fingerprint(self, fingerprint):
# type: (str) -> BoundSSHKey
"""Get ssh key by fingerprint

:param fingerprint: str
Used to get ssh key by fingerprint.
:return: :class:`BoundSSHKey <hcloud.ssh_keys.client.BoundSSHKey>`
"""
response = self.get_list(fingerprint=fingerprint)
sshkeys = response.ssh_keys
return sshkeys[0] if sshkeys else None

def create(self, name, public_key, labels=None):
# type: (str, str, Optional[Dict[str, str]]) -> BoundSSHKey
"""Creates a new SSH key with the given name and public_key.
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/ssh_keys/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ def test_get_by_name(self, ssh_keys_client, one_ssh_keys_response):
assert ssh_keys.id == 2323
assert ssh_keys.name == "SSH-Key"

def test_get_by_fingerprint(self, ssh_keys_client, one_ssh_keys_response):
ssh_keys_client._client.request.return_value = one_ssh_keys_response
ssh_keys = ssh_keys_client.get_by_fingerprint("b7:2f:30:a0:2f:6c:58:6c:21:04:58:61:ba:06:3b:2f")

params = {'fingerprint': "b7:2f:30:a0:2f:6c:58:6c:21:04:58:61:ba:06:3b:2f"}
ssh_keys_client._client.request.assert_called_with(url="/ssh_keys", method="GET", params=params)

assert ssh_keys._client is ssh_keys_client
assert ssh_keys.id == 2323
assert ssh_keys.name == "SSH-Key"

def test_create(self, ssh_keys_client, ssh_key_response):
ssh_keys_client._client.request.return_value = ssh_key_response
ssh_key = ssh_keys_client.create(name="My ssh key", public_key="ssh-rsa AAAjjk76kgf...Xt")
Expand Down