- Change auth from X-API-Key header to Authorization: Bearer format - Add /v2 prefix to all endpoints to match Vultr API URL structure - Fix router paths (dns, firewall) to avoid duplicate path segments - Split VPC 2.0 into separate router at /v2/vpc2 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
60 lines
2.3 KiB
Python
60 lines
2.3 KiB
Python
"""
|
|
Vultr API REST Server
|
|
FastAPI wrapper for vultr-api library
|
|
"""
|
|
from fastapi import FastAPI
|
|
from contextlib import asynccontextmanager
|
|
|
|
from routers import (
|
|
account, instances, dns, firewall, ssh_keys,
|
|
startup_scripts, snapshots, block_storage, reserved_ips,
|
|
vpc, vpc2, load_balancers, bare_metal, backups, plans, regions, os_api
|
|
)
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
"""Application lifespan handler"""
|
|
print("Vultr API Server starting...")
|
|
yield
|
|
print("Vultr API Server shutting down...")
|
|
|
|
|
|
app = FastAPI(
|
|
title="Vultr API Server",
|
|
description="REST API server wrapping Vultr API v2",
|
|
version="1.0.0",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
# Include routers with /v2 prefix to match Vultr API
|
|
app.include_router(account.router, prefix="/v2/account", tags=["Account"])
|
|
app.include_router(instances.router, prefix="/v2/instances", tags=["Instances"])
|
|
app.include_router(dns.router, prefix="/v2/domains", tags=["DNS"])
|
|
app.include_router(firewall.router, prefix="/v2/firewalls", tags=["Firewall"])
|
|
app.include_router(ssh_keys.router, prefix="/v2/ssh-keys", tags=["SSH Keys"])
|
|
app.include_router(startup_scripts.router, prefix="/v2/startup-scripts", tags=["Startup Scripts"])
|
|
app.include_router(snapshots.router, prefix="/v2/snapshots", tags=["Snapshots"])
|
|
app.include_router(block_storage.router, prefix="/v2/blocks", tags=["Block Storage"])
|
|
app.include_router(reserved_ips.router, prefix="/v2/reserved-ips", tags=["Reserved IPs"])
|
|
app.include_router(vpc.router, prefix="/v2/vpcs", tags=["VPC"])
|
|
app.include_router(vpc2.router, prefix="/v2/vpc2", tags=["VPC 2.0"])
|
|
app.include_router(load_balancers.router, prefix="/v2/load-balancers", tags=["Load Balancers"])
|
|
app.include_router(bare_metal.router, prefix="/v2/bare-metals", tags=["Bare Metal"])
|
|
app.include_router(backups.router, prefix="/v2/backups", tags=["Backups"])
|
|
app.include_router(plans.router, prefix="/v2/plans", tags=["Plans"])
|
|
app.include_router(regions.router, prefix="/v2/regions", tags=["Regions"])
|
|
app.include_router(os_api.router, prefix="/v2/os", tags=["Operating Systems"])
|
|
|
|
|
|
@app.get("/", tags=["Health"])
|
|
async def root():
|
|
"""Health check endpoint"""
|
|
return {"status": "ok", "service": "vultr-api-server"}
|
|
|
|
|
|
@app.get("/health", tags=["Health"])
|
|
async def health():
|
|
"""Health check endpoint"""
|
|
return {"status": "healthy"}
|