Files
vultr-api/server/routers/ssh_keys.py
HWANG BYUNGHA 184054c6c1 Initial commit: Vultr API v2 Python wrapper with FastAPI server
- 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>
2026-01-22 01:08:17 +09:00

60 lines
1.6 KiB
Python

"""SSH Keys router"""
from fastapi import APIRouter, Depends, Query
from typing import Optional
from pydantic import BaseModel
from vultr_api import VultrClient
from deps import get_client
router = APIRouter()
class CreateSSHKeyRequest(BaseModel):
name: str
ssh_key: str
class UpdateSSHKeyRequest(BaseModel):
name: Optional[str] = None
ssh_key: Optional[str] = None
@router.get("")
async def list_ssh_keys(
per_page: int = Query(25, le=500),
cursor: Optional[str] = None,
client: VultrClient = Depends(get_client)
):
"""List all SSH keys"""
return client.ssh_keys.list(per_page=per_page, cursor=cursor)
@router.get("/all")
async def list_all_ssh_keys(client: VultrClient = Depends(get_client)):
"""List all SSH keys (auto-paginated)"""
return {"ssh_keys": client.ssh_keys.list_all()}
@router.get("/{ssh_key_id}")
async def get_ssh_key(ssh_key_id: str, client: VultrClient = Depends(get_client)):
"""Get SSH key details"""
return client.ssh_keys.get(ssh_key_id)
@router.post("")
async def create_ssh_key(req: CreateSSHKeyRequest, client: VultrClient = Depends(get_client)):
"""Create an SSH key"""
return client.ssh_keys.create(name=req.name, ssh_key=req.ssh_key)
@router.patch("/{ssh_key_id}")
async def update_ssh_key(ssh_key_id: str, req: UpdateSSHKeyRequest, client: VultrClient = Depends(get_client)):
"""Update an SSH key"""
return client.ssh_keys.update(ssh_key_id, **req.model_dump(exclude_none=True))
@router.delete("/{ssh_key_id}")
async def delete_ssh_key(ssh_key_id: str, client: VultrClient = Depends(get_client)):
"""Delete an SSH key"""
return client.ssh_keys.delete(ssh_key_id)