refactor: update all API blueprints (certs, dhcp, firewall, logs, network, proxy, wireguard)
This commit is contained in:
+24
-11
@@ -8,6 +8,19 @@ import logging
|
||||
from flask import Blueprint, request
|
||||
|
||||
from daemon.client import BadRequest, NotFound, delete, get, patch, post
|
||||
from daemon.iface import (
|
||||
DELETE_NGINX_DOMAINS_REMOVE,
|
||||
GET_NGINX_CONFIG,
|
||||
GET_NGINX_DOMAINS,
|
||||
PATCH_NGINX_CONFIG,
|
||||
POST_NGINX_APPLY,
|
||||
POST_NGINX_CONFIG,
|
||||
POST_NGINX_DOMAINS_ADD,
|
||||
POST_NGINX_DOMAINS_UPDATE,
|
||||
POST_NGINX_MANAGEMENT,
|
||||
POST_NGINX_SSL_APPLY,
|
||||
POST_NGINX_TEST,
|
||||
)
|
||||
from webui.api.common import _error, _ok
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -27,7 +40,7 @@ def ssl_apply_bp():
|
||||
RuntimeError: If nginx SSL snippet write fails.
|
||||
"""
|
||||
try:
|
||||
post("/nginx/ssl-apply")
|
||||
post(POST_NGINX_SSL_APPLY)
|
||||
logger.info("SSL snippet written via API")
|
||||
return _ok(None)
|
||||
except RuntimeError as exc:
|
||||
@@ -45,7 +58,7 @@ def get_config_bp():
|
||||
Current config dict from the daemon.
|
||||
"""
|
||||
try:
|
||||
return _ok(get("/nginx/config"))
|
||||
return _ok(get(GET_NGINX_CONFIG))
|
||||
except RuntimeError as exc:
|
||||
logger.error("Failed to read proxy config: %s", exc)
|
||||
return _error(str(exc), 500)
|
||||
@@ -67,7 +80,7 @@ def post_config():
|
||||
if not isinstance(body, dict):
|
||||
return _error("Request body must be a JSON object", 400)
|
||||
try:
|
||||
post("/nginx/config", body)
|
||||
post(POST_NGINX_CONFIG, body)
|
||||
logger.info("Proxy config saved: %s", sorted(body.keys()))
|
||||
return _ok(None)
|
||||
except BadRequest as exc:
|
||||
@@ -94,7 +107,7 @@ def patch_config():
|
||||
if not isinstance(body, dict):
|
||||
return _error("Request body must be a JSON object", 400)
|
||||
try:
|
||||
patch("/nginx/config", body)
|
||||
patch(PATCH_NGINX_CONFIG, body)
|
||||
logger.info("Proxy config patched: %s", sorted(body.keys()))
|
||||
return _ok(None)
|
||||
except BadRequest as exc:
|
||||
@@ -115,7 +128,7 @@ def list_domains():
|
||||
List of domain dicts from the daemon.
|
||||
"""
|
||||
try:
|
||||
return _ok(get("/nginx/domains"))
|
||||
return _ok(get(GET_NGINX_DOMAINS))
|
||||
except RuntimeError as exc:
|
||||
logger.error("Failed to list proxy domains: %s", exc)
|
||||
return _error(str(exc), 500)
|
||||
@@ -153,7 +166,7 @@ def add_domain_bp():
|
||||
return _error("'backend_port' is required", 400)
|
||||
try:
|
||||
post(
|
||||
"/nginx/domains/add",
|
||||
POST_NGINX_DOMAINS_ADD,
|
||||
{
|
||||
"domain": domain,
|
||||
"backend_host": backend_host,
|
||||
@@ -189,7 +202,7 @@ def update_domain_bp(domain):
|
||||
if not body:
|
||||
return _error("Request body must be a JSON object with fields to update", 400)
|
||||
try:
|
||||
post("/nginx/domains/update", {"domain": domain, **body})
|
||||
post(POST_NGINX_DOMAINS_UPDATE, {"domain": domain, **body})
|
||||
logger.info("Proxy domain '%s' updated via API", domain)
|
||||
return _ok({"domain": domain})
|
||||
except BadRequest as exc:
|
||||
@@ -213,7 +226,7 @@ def remove_domain_bp(domain):
|
||||
``{"domain": ...}`` on success.
|
||||
"""
|
||||
try:
|
||||
delete("/nginx/domains/remove", {"domain": domain})
|
||||
delete(DELETE_NGINX_DOMAINS_REMOVE, {"domain": domain})
|
||||
logger.info("Proxy domain removed via API: %s", domain)
|
||||
return _ok({"domain": domain})
|
||||
except NotFound as exc:
|
||||
@@ -234,7 +247,7 @@ def apply_bp():
|
||||
``{"ok": true}`` on success.
|
||||
"""
|
||||
try:
|
||||
post("/nginx/apply")
|
||||
post(POST_NGINX_APPLY)
|
||||
logger.info("nginx config applied via API")
|
||||
return _ok(None)
|
||||
except RuntimeError as exc:
|
||||
@@ -252,7 +265,7 @@ def test_bp():
|
||||
``{"valid": true, "output": ...}`` on success. Returns 400 if test fails.
|
||||
"""
|
||||
try:
|
||||
result = post("/nginx/test")
|
||||
result = post(POST_NGINX_TEST)
|
||||
if result.get("valid"):
|
||||
return _ok({"valid": True, "output": result.get("output", "")})
|
||||
return _error(result.get("output", "unknown error"), 400)
|
||||
@@ -287,7 +300,7 @@ def management_bp():
|
||||
auth_pass = body.get("auth_pass")
|
||||
try:
|
||||
post(
|
||||
"/nginx/management",
|
||||
POST_NGINX_MANAGEMENT,
|
||||
{
|
||||
"domain": domain,
|
||||
"flask_host": flask_host,
|
||||
|
||||
Reference in New Issue
Block a user