fix: use DDNS_URL env var for availability check; default to port 8080
Unit Tests / test (push) Successful in 15m23s
Unit Tests / test (push) Successful in 15m23s
_check_pic_ngo_available was hardcoding https://ddns.pic.ngo, ignoring DDNS_URL. Now imports DDNS_API_BASE from setup_manager so both the availability check and DDNS registration use the same configured URL. API container now receives DDNS_URL and DDNS_TOTP_SECRET from env. Default DDNS_URL points to http://ddns.pic.ngo:8080/api/v1 (the FastAPI service runs on port 8080 without TLS termination in front). Also returns 503 (not 500) when the DDNS service is unreachable. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+10
-5
@@ -4,6 +4,7 @@ import urllib.request
|
|||||||
import urllib.error
|
import urllib.error
|
||||||
import json as _json
|
import json as _json
|
||||||
from flask import Blueprint, request, jsonify
|
from flask import Blueprint, request, jsonify
|
||||||
|
from setup_manager import DDNS_API_BASE
|
||||||
|
|
||||||
logger = logging.getLogger('picell')
|
logger = logging.getLogger('picell')
|
||||||
|
|
||||||
@@ -54,8 +55,11 @@ def validate_setup_step():
|
|||||||
errors = sm.validate_cell_name(name)
|
errors = sm.validate_cell_name(name)
|
||||||
if errors:
|
if errors:
|
||||||
return jsonify({'available': False, 'errors': errors})
|
return jsonify({'available': False, 'errors': errors})
|
||||||
available = _check_pic_ngo_available(name)
|
try:
|
||||||
return jsonify({'available': available})
|
available = _check_pic_ngo_available(name)
|
||||||
|
return jsonify({'available': available})
|
||||||
|
except Exception:
|
||||||
|
return jsonify({'available': False, 'error': 'DDNS service unreachable'}), 503
|
||||||
|
|
||||||
if step == 'cloudflare_token':
|
if step == 'cloudflare_token':
|
||||||
token = data.get('token', '').strip()
|
token = data.get('token', '').strip()
|
||||||
@@ -92,12 +96,13 @@ def complete_setup():
|
|||||||
|
|
||||||
def _check_pic_ngo_available(name: str) -> bool:
|
def _check_pic_ngo_available(name: str) -> bool:
|
||||||
try:
|
try:
|
||||||
url = f'https://ddns.pic.ngo/api/v1/check/{name}'
|
url = f'{DDNS_API_BASE}/api/v1/check/{name}'
|
||||||
with urllib.request.urlopen(url, timeout=8) as resp:
|
with urllib.request.urlopen(url, timeout=8) as resp:
|
||||||
body = _json.loads(resp.read())
|
body = _json.loads(resp.read())
|
||||||
return bool(body.get('available'))
|
return bool(body.get('available'))
|
||||||
except Exception:
|
except Exception as exc:
|
||||||
return True # assume available if check fails — don't block the wizard
|
logger.warning(f'DDNS availability check failed for {name!r}: {exc}')
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
def _verify_cloudflare_token(token: str) -> bool:
|
def _verify_cloudflare_token(token: str) -> bool:
|
||||||
|
|||||||
@@ -204,6 +204,9 @@ services:
|
|||||||
profiles: ["core", "full"]
|
profiles: ["core", "full"]
|
||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:${API_PORT:-3000}:3000"
|
- "127.0.0.1:${API_PORT:-3000}:3000"
|
||||||
|
environment:
|
||||||
|
- DDNS_URL=${DDNS_URL:-http://ddns.pic.ngo:8080/api/v1}
|
||||||
|
- DDNS_TOTP_SECRET=${DDNS_TOTP_SECRET:-}
|
||||||
volumes:
|
volumes:
|
||||||
- ./data/api:/app/data
|
- ./data/api:/app/data
|
||||||
- ./data/dns:/app/data/dns
|
- ./data/dns:/app/data/dns
|
||||||
|
|||||||
Reference in New Issue
Block a user