fix: allow authenticated one-shot DNS token fallback
This commit is contained in:
parent
d598af02d4
commit
ed501e676b
1 changed files with 4 additions and 3 deletions
7
app.py
7
app.py
|
|
@ -920,6 +920,7 @@ def _validate_proxy_route(domain: str, upstream: str) -> tuple[str, str, str, st
|
||||||
class ProxyRouteRequest(BaseModel):
|
class ProxyRouteRequest(BaseModel):
|
||||||
domain: str
|
domain: str
|
||||||
upstream: str
|
upstream: str
|
||||||
|
dns_token: str | None = None
|
||||||
|
|
||||||
|
|
||||||
def _remote_python(script: str, timeout: int = 30) -> tuple[int, str, str]:
|
def _remote_python(script: str, timeout: int = 30) -> tuple[int, str, str]:
|
||||||
|
|
@ -995,8 +996,8 @@ def _get_hetzner_dns_token() -> str:
|
||||||
return token
|
return token
|
||||||
|
|
||||||
|
|
||||||
async def _upsert_dns_records(zone: str, name: str) -> dict:
|
async def _upsert_dns_records(zone: str, name: str, token_override: str | None = None) -> dict:
|
||||||
token = await asyncio.to_thread(_get_hetzner_dns_token)
|
token = token_override or await asyncio.to_thread(_get_hetzner_dns_token)
|
||||||
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
|
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
|
||||||
api = "https://api.hetzner.cloud/v1"
|
api = "https://api.hetzner.cloud/v1"
|
||||||
async with httpx.AsyncClient(timeout=30) as client:
|
async with httpx.AsyncClient(timeout=30) as client:
|
||||||
|
|
@ -1027,7 +1028,7 @@ async def vps_proxy_route(req: ProxyRouteRequest, _=Depends(_verify)):
|
||||||
raise HTTPException(400, str(exc)) from exc
|
raise HTTPException(400, str(exc)) from exc
|
||||||
caddy = await asyncio.to_thread(_configure_caddy_route, domain, upstream)
|
caddy = await asyncio.to_thread(_configure_caddy_route, domain, upstream)
|
||||||
try:
|
try:
|
||||||
dns = await _upsert_dns_records(zone, name)
|
dns = await _upsert_dns_records(zone, name, req.dns_token)
|
||||||
except Exception:
|
except Exception:
|
||||||
await asyncio.to_thread(_restore_caddy_backup, caddy["backup"])
|
await asyncio.to_thread(_restore_caddy_backup, caddy["backup"])
|
||||||
raise
|
raise
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue