fix: GET /api/settings/ip-allowlist 被 /{key} 路由拦截 → 404
/{key} 路由在 ip-allowlist 之前定义,FastAPI 将 ip-allowlist
当作 setting key 查找,找不到返回 404。
修复:将 GET /ip-allowlist 路由移到 /{key} 之前(FastAPI 路由优先级)。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+26
-26
@@ -48,6 +48,32 @@ async def list_settings(admin: Admin = Depends(get_current_admin), db: AsyncSess
|
||||
return result
|
||||
|
||||
|
||||
@router.get("/ip-allowlist", response_model=dict)
|
||||
async def get_ip_allowlist(
|
||||
admin: Admin = Depends(get_current_admin),
|
||||
):
|
||||
"""Return full allowlist state."""
|
||||
from server.config import settings as _settings
|
||||
from server.background.ip_allowlist_refresh import get_last_refresh_time
|
||||
|
||||
allowlist_on = (_settings.LOGIN_ALLOWLIST_ENABLED or "false").lower() in ("true","1","yes","on")
|
||||
sub_ips_raw = _settings.LOGIN_SUBSCRIPTION_IPS or ""
|
||||
manual_raw = _settings.LOGIN_MANUAL_IPS or ""
|
||||
sub_ips = [ip.strip() for ip in sub_ips_raw.split(",") if ip.strip()]
|
||||
manual_ips = [ip.strip() for ip in manual_raw.split(",") if ip.strip()]
|
||||
|
||||
return {
|
||||
"enabled": allowlist_on,
|
||||
"subscription_url": _settings.LOGIN_SUBSCRIPTION_URL or "",
|
||||
"subscription_ips": sub_ips,
|
||||
"manual_ips": manual_ips,
|
||||
"subscription_count": len(sub_ips),
|
||||
"manual_count": len(manual_ips),
|
||||
"total_count": len(sub_ips) + len(set(manual_ips) - set(sub_ips)),
|
||||
"last_refresh": get_last_refresh_time(),
|
||||
}
|
||||
|
||||
|
||||
@router.get("/{key}", response_model=dict)
|
||||
async def get_setting(key: str, admin: Admin = Depends(get_current_admin), db: AsyncSession = Depends(get_db)):
|
||||
"""Get a single setting by key (sensitive values masked)"""
|
||||
@@ -924,32 +950,6 @@ async def remove_allowlist_ip(
|
||||
return {"success": True, "removed": ip, "remaining": remaining}
|
||||
|
||||
|
||||
@router.get("/ip-allowlist", response_model=dict)
|
||||
async def get_ip_allowlist(
|
||||
admin: Admin = Depends(get_current_admin),
|
||||
):
|
||||
"""Return full allowlist state."""
|
||||
from server.config import settings as _settings
|
||||
from server.background.ip_allowlist_refresh import get_last_refresh_time
|
||||
|
||||
allowlist_on = (_settings.LOGIN_ALLOWLIST_ENABLED or "false").lower() in ("true","1","yes","on")
|
||||
sub_ips_raw = _settings.LOGIN_SUBSCRIPTION_IPS or ""
|
||||
manual_raw = _settings.LOGIN_MANUAL_IPS or ""
|
||||
sub_ips = [ip.strip() for ip in sub_ips_raw.split(",") if ip.strip()]
|
||||
manual_ips = [ip.strip() for ip in manual_raw.split(",") if ip.strip()]
|
||||
|
||||
return {
|
||||
"enabled": allowlist_on,
|
||||
"subscription_url": _settings.LOGIN_SUBSCRIPTION_URL or "",
|
||||
"subscription_ips": sub_ips,
|
||||
"manual_ips": manual_ips,
|
||||
"subscription_count": len(sub_ips),
|
||||
"manual_count": len(manual_ips),
|
||||
"total_count": len(sub_ips) + len(set(manual_ips) - set(sub_ips)),
|
||||
"last_refresh": get_last_refresh_time(),
|
||||
}
|
||||
|
||||
|
||||
# ── Audit Logs ──
|
||||
|
||||
audit_router = APIRouter(prefix="/api/audit", tags=["audit"])
|
||||
|
||||
Reference in New Issue
Block a user