Files
vacuum-wall/webui/api/certs.py
T
mteehan 65741644a3 Fix dashboard template bugs, acme date parsing, wireguard sudoers match, and stale docs
- dashboard.html: Fix zones, leases, wg_status, cert key names, add services var
- server.py: Pass services to dashboard template via _get_service_status()
- lib/acme.py: Fix dead third date format (%Y%m%d%H%M%z) using astimezone(UTC)
- lib/wireguard.py: Add -- separator to cp command to match sudoers rule
- lib/nginx.py: Replace shallow dict.copy() with {**...} for DEFAULT_SSL
- AGENTS.md: Update test count 149 -> 154
- docs/api.md: Rename cert field expiry -> expires_at
2026-05-08 19:11:54 +00:00

131 lines
3.4 KiB
Python

"""
webui/api/certs.py - ACME certificate management API blueprint.
Exposed at /api/certs/* and delegates to lib.acme.
"""
from flask import Blueprint, jsonify, request
from lib.acme import (
get_cert_info,
issue,
list_certs,
remove,
renew,
set_email,
)
bp = Blueprint("certs", __name__)
# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
def _error(msg, code=400):
return jsonify({"ok": False, "error": msg}), code
def _ok(data=None):
return jsonify({"ok": True, "data": data})
# ---------------------------------------------------------------------------
# Certificate listing
# ---------------------------------------------------------------------------
@bp.route("/list", methods=["GET"])
def list_certs_bp():
try:
return _ok(list_certs())
except RuntimeError as exc:
return _error(str(exc), 500)
@bp.route("/<domain>", methods=["GET"])
def cert_details(domain):
try:
info = get_cert_info(domain)
return _ok(info)
except ValueError as exc:
return _error(str(exc), 404)
except RuntimeError as exc:
return _error(str(exc), 500)
# ---------------------------------------------------------------------------
# Issue
# ---------------------------------------------------------------------------
@bp.route("/issue", methods=["POST"])
def issue_bp():
body = request.get_json(silent=True) or {}
domain = body.get("domain", "").strip()
if not domain:
return _error("'domain' is required", 400)
webroot = body.get("webroot")
try:
result = issue(domain, webroot=webroot)
if result.get("success"):
return _ok(None)
return _error(result.get("error", "Unknown error"), 500)
except RuntimeError as exc:
return _error(str(exc), 500)
# ---------------------------------------------------------------------------
# Renew
# ---------------------------------------------------------------------------
@bp.route("/<domain>/renew", methods=["POST"])
def renew_bp(domain):
try:
result = renew(domain)
if result.get("success"):
return _ok(None)
return _error(result.get("error", "Unknown error"), 500)
except RuntimeError as exc:
return _error(str(exc), 500)
# ---------------------------------------------------------------------------
# Remove
# ---------------------------------------------------------------------------
@bp.route("/<domain>", methods=["DELETE"])
def remove_bp(domain):
try:
get_cert_info(domain)
except ValueError as exc:
return _error(str(exc), 404)
except RuntimeError as exc:
return _error(str(exc), 500)
try:
remove(domain)
return _ok(None)
except RuntimeError as exc:
return _error(str(exc), 500)
# ---------------------------------------------------------------------------
# Contact email
# ---------------------------------------------------------------------------
@bp.route("/email", methods=["POST"])
def set_email_bp():
body = request.get_json(silent=True) or {}
email = body.get("email", "").strip()
if not email:
return _error("'email' is required", 400)
try:
set_email(email)
return _ok({"email": email})
except RuntimeError as exc:
return _error(str(exc), 500)