Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_bound_ssh_key_init(self, ssh_key_response):
bound_ssh_key = BoundSSHKey(
client=mock.MagicMock(),
data=ssh_key_response['ssh_key']
)
assert bound_ssh_key.id == 2323
assert bound_ssh_key.name == "My ssh key"
assert bound_ssh_key.fingerprint == "b7:2f:30:a0:2f:6c:58:6c:21:04:58:61:ba:06:3b:2f"
assert bound_ssh_key.public_key == "ssh-rsa AAAjjk76kgf...Xt"
@pytest.mark.parametrize("ssh_key", [SSHKey(id=1), BoundSSHKey(mock.MagicMock(), dict(id=1))])
def test_update(self, ssh_keys_client, ssh_key, response_update_ssh_key):
ssh_keys_client._client.request.return_value = response_update_ssh_key
ssh_key = ssh_keys_client.update(ssh_key, name="New name")
ssh_keys_client._client.request.assert_called_with(url="/ssh_keys/1", method="PUT", json={"name": "New name"})
assert ssh_key.id == 2323
assert ssh_key.name == "New name"
def bound_ssh_key(self, hetzner_client):
return BoundSSHKey(client=hetzner_client.ssh_keys, data=dict(id=14))
def bound_ssh_key(self, hetzner_client):
return BoundSSHKey(client=hetzner_client.ssh_keys, data=dict(id=42))
@pytest.mark.parametrize("ssh_key", [SSHKey(id=1), BoundSSHKey(mock.MagicMock(), dict(id=1))])
def test_update(self, hetzner_client, ssh_key):
ssh_key = hetzner_client.ssh_keys.update(ssh_key, name="New name")
assert ssh_key.id == 2323
assert ssh_key.name == "New name"
def get_by_id(self, id):
# type: (int) -> BoundSSHKey
"""Get a specific SSH Key by its ID
:param id: int
:return: :class:`BoundSSHKey `
"""
response = self._client.request(url="/ssh_keys/{ssh_key_id}".format(ssh_key_id=id), method="GET")
return BoundSSHKey(self, response['ssh_key'])
:param name: str
:param public_key: str
Public Key of the SSH Key you want create
:param labels: Dict[str, str] (optional)
User-defined labels (key-value pairs)
:return: :class:`BoundSSHKey `
"""
data = {
'name': name,
'public_key': public_key
}
if labels is not None:
data['labels'] = labels
response = self._client.request(url="/ssh_keys", method="POST", json=data)
return BoundSSHKey(self, response['ssh_key'])
"""
params = {}
if name is not None:
params['name'] = name
if fingerprint is not None:
params['fingerprint'] = fingerprint
if label_selector is not None:
params['label_selector'] = label_selector
if page is not None:
params['page'] = page
if per_page is not None:
params['per_page'] = per_page
response = self._client.request(url="/ssh_keys", method="GET", params=params)
ass_ssh_keys = [BoundSSHKey(self, server_data) for server_data in response['ssh_keys']]
return self._add_meta_to_result(ass_ssh_keys, response)
:param ssh_key: :class:`BoundSSHKey ` or :class:`SSHKey `
:param name: str (optional)
New Description to set
:param labels: Dict[str, str] (optional)
User-defined labels (key-value pairs)
:return: :class:`BoundSSHKey `
"""
data = {}
if name is not None:
data['name'] = name
if labels is not None:
data['labels'] = labels
response = self._client.request(url="/ssh_keys/{ssh_key_id}".format(ssh_key_id=ssh_key.id), method="PUT",
json=data)
return BoundSSHKey(self, response['ssh_key'])