- vultr_api/: Python library wrapping Vultr API v2 - 17 resource modules (instances, dns, firewall, vpc, etc.) - Pagination support, error handling - server/: FastAPI REST server - All API endpoints exposed via HTTP - X-API-Key header authentication - Swagger docs at /docs - Podman quadlet config for systemd deployment Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
100 lines
2.2 KiB
Python
100 lines
2.2 KiB
Python
"""
|
|
SSH Keys Resource
|
|
|
|
SSH key management
|
|
"""
|
|
|
|
from typing import Dict, List
|
|
from .base import BaseResource
|
|
|
|
|
|
class SSHKeysResource(BaseResource):
|
|
"""
|
|
SSH key management
|
|
|
|
Usage:
|
|
# List keys
|
|
keys = client.ssh_keys.list()
|
|
|
|
# Create key
|
|
key = client.ssh_keys.create(
|
|
name="my-key",
|
|
ssh_key="ssh-rsa AAAAB3..."
|
|
)
|
|
|
|
# Delete key
|
|
client.ssh_keys.delete("key-id")
|
|
"""
|
|
|
|
def list(self, per_page: int = 100, cursor: str = None) -> Dict:
|
|
"""
|
|
List SSH keys
|
|
|
|
Returns:
|
|
Dict with 'ssh_keys' list and 'meta' pagination
|
|
"""
|
|
params = {"per_page": per_page}
|
|
if cursor:
|
|
params["cursor"] = cursor
|
|
return self.client.get("ssh-keys", params=params)
|
|
|
|
def list_all(self) -> List[Dict]:
|
|
"""List all SSH keys (auto-paginate)"""
|
|
return self.client.paginate("ssh-keys", "ssh_keys")
|
|
|
|
def get(self, ssh_key_id: str) -> Dict:
|
|
"""
|
|
Get SSH key details
|
|
|
|
Args:
|
|
ssh_key_id: SSH key ID
|
|
|
|
Returns:
|
|
SSH key details
|
|
"""
|
|
response = self.client.get(f"ssh-keys/{ssh_key_id}")
|
|
return response.get("ssh_key", {})
|
|
|
|
def create(self, name: str, ssh_key: str) -> Dict:
|
|
"""
|
|
Create an SSH key
|
|
|
|
Args:
|
|
name: Key name
|
|
ssh_key: Public key content
|
|
|
|
Returns:
|
|
Created SSH key details
|
|
"""
|
|
response = self.client.post("ssh-keys", {
|
|
"name": name,
|
|
"ssh_key": ssh_key
|
|
})
|
|
return response.get("ssh_key", {})
|
|
|
|
def update(self, ssh_key_id: str, name: str = None, ssh_key: str = None) -> None:
|
|
"""
|
|
Update an SSH key
|
|
|
|
Args:
|
|
ssh_key_id: Key ID
|
|
name: New name
|
|
ssh_key: New public key content
|
|
"""
|
|
data = {}
|
|
if name:
|
|
data["name"] = name
|
|
if ssh_key:
|
|
data["ssh_key"] = ssh_key
|
|
|
|
self.client.patch(f"ssh-keys/{ssh_key_id}", data)
|
|
|
|
def delete(self, ssh_key_id: str) -> None:
|
|
"""
|
|
Delete an SSH key
|
|
|
|
Args:
|
|
ssh_key_id: Key ID to delete
|
|
"""
|
|
self.client.delete(f"ssh-keys/{ssh_key_id}")
|