How to use the hcloud.ssh_keys.client.BoundSSHKey function in hcloud

To help you get started, we’ve selected a few hcloud examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hetznercloud / hcloud-python / tests / unit / ssh_keys / test_client.py View on Github external
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"
github hetznercloud / hcloud-python / tests / unit / ssh_keys / test_client.py View on Github external
    @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"
github hetznercloud / hcloud-python / tests / unit / ssh_keys / test_client.py View on Github external
def bound_ssh_key(self, hetzner_client):
        return BoundSSHKey(client=hetzner_client.ssh_keys, data=dict(id=14))
github hetznercloud / hcloud-python / tests / integration / ssh_keys / test_ssh_keys.py View on Github external
def bound_ssh_key(self, hetzner_client):
        return BoundSSHKey(client=hetzner_client.ssh_keys, data=dict(id=42))
github hetznercloud / hcloud-python / tests / integration / ssh_keys / test_ssh_keys.py View on Github external
    @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"
github hetznercloud / hcloud-python / hcloud / ssh_keys / client.py View on Github external
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'])
github hetznercloud / hcloud-python / hcloud / ssh_keys / client.py View on Github external
: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'])
github hetznercloud / hcloud-python / hcloud / ssh_keys / client.py View on Github external
"""
        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)
github hetznercloud / hcloud-python / hcloud / ssh_keys / client.py View on Github external
: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'])