docs: add docstrings to all API endpoints and daemon handlers
Add comprehensive docstrings to firewall, DHCP, proxy, wireguard, certs, and logs API endpoints. Document parameters, return values, and error cases for the documentation system.
This commit is contained in:
@@ -21,6 +21,11 @@ bp = Blueprint("dhcp", __name__)
|
||||
|
||||
@bp.route("/config", methods=["GET"])
|
||||
def get_config_bp():
|
||||
"""GET /api/dhcp/config — Retrieve the current dnsmasq configuration.
|
||||
|
||||
Returns:
|
||||
JSON response with the config or an error.
|
||||
"""
|
||||
try:
|
||||
return _ok(get("/dnsmasq/config"))
|
||||
except RuntimeError as exc:
|
||||
@@ -30,6 +35,14 @@ def get_config_bp():
|
||||
|
||||
@bp.route("/config", methods=["POST"])
|
||||
def post_config():
|
||||
"""POST /api/dhcp/config — Save a full replacement dnsmasq configuration.
|
||||
|
||||
Args:
|
||||
request: JSON body containing the complete config object.
|
||||
|
||||
Returns:
|
||||
JSON response with success status or an error.
|
||||
"""
|
||||
body = request.get_json(silent=True) or {}
|
||||
if not isinstance(body, dict):
|
||||
return _error("Request body must be a JSON object", 400)
|
||||
@@ -46,6 +59,14 @@ def post_config():
|
||||
|
||||
@bp.route("/config", methods=["PATCH"])
|
||||
def patch_config():
|
||||
"""PATCH /api/dhcp/config — Partially update the dnsmasq configuration.
|
||||
|
||||
Args:
|
||||
request: JSON body containing the fields to update.
|
||||
|
||||
Returns:
|
||||
JSON response with success status or an error.
|
||||
"""
|
||||
body = request.get_json(silent=True) or {}
|
||||
if not isinstance(body, dict):
|
||||
return _error("Request body must be a JSON object", 400)
|
||||
@@ -62,6 +83,8 @@ def patch_config():
|
||||
|
||||
@bp.route("/apply", methods=["POST"])
|
||||
def apply_bp():
|
||||
"""POST /api/dhcp/apply — Apply the current dnsmasq configuration to the running service."""
|
||||
|
||||
try:
|
||||
post("/dnsmasq/apply")
|
||||
logger.info("dnsmasq config applied via API")
|
||||
@@ -78,6 +101,8 @@ def apply_bp():
|
||||
|
||||
@bp.route("/status", methods=["GET"])
|
||||
def status_bp():
|
||||
"""GET /api/dhcp/status — Retrieve dnsmasq service status."""
|
||||
|
||||
try:
|
||||
return _ok(get("/dnsmasq/status"))
|
||||
except RuntimeError as exc:
|
||||
@@ -92,6 +117,14 @@ def status_bp():
|
||||
|
||||
@bp.route("/ranges", methods=["POST"])
|
||||
def add_range_bp():
|
||||
"""POST /api/dhcp/ranges — Add a DHCP address range for an interface.
|
||||
|
||||
Args:
|
||||
request: JSON body with `interface`, `start`, `end`, and optional `lease_time`.
|
||||
|
||||
Returns:
|
||||
JSON response with success status or an error.
|
||||
"""
|
||||
body = request.get_json(silent=True) or {}
|
||||
iface = body.get("interface", "").strip() or None
|
||||
start = body.get("start", "").strip()
|
||||
@@ -121,6 +154,14 @@ def add_range_bp():
|
||||
|
||||
@bp.route("/ranges", methods=["DELETE"])
|
||||
def remove_range_bp():
|
||||
"""DELETE /api/dhcp/ranges — Remove a DHCP address range.
|
||||
|
||||
Args:
|
||||
request: JSON body with `interface`, `start`, and `end`.
|
||||
|
||||
Returns:
|
||||
JSON response with success status or an error.
|
||||
"""
|
||||
body = request.get_json(silent=True) or {}
|
||||
iface = body.get("interface", "").strip() or ""
|
||||
start = body.get("start", "").strip()
|
||||
@@ -148,6 +189,8 @@ def remove_range_bp():
|
||||
|
||||
@bp.route("/leases", methods=["GET"])
|
||||
def leases_bp():
|
||||
"""GET /api/dhcp/leases — Retrieve the current DHCP lease table."""
|
||||
|
||||
try:
|
||||
return _ok(get("/dnsmasq/leases"))
|
||||
except RuntimeError as exc:
|
||||
@@ -162,6 +205,14 @@ def leases_bp():
|
||||
|
||||
@bp.route("/static-lease", methods=["POST"])
|
||||
def add_static_lease_bp():
|
||||
"""POST /api/dhcp/static-lease — Add a static DHCP lease by MAC address.
|
||||
|
||||
Args:
|
||||
request: JSON body with `mac`, `ip`, and optional `hostname`.
|
||||
|
||||
Returns:
|
||||
JSON response with lease details or an error.
|
||||
"""
|
||||
body = request.get_json(silent=True) or {}
|
||||
mac = body.get("mac", "").strip()
|
||||
ip = body.get("ip", "").strip()
|
||||
@@ -182,6 +233,14 @@ def add_static_lease_bp():
|
||||
|
||||
@bp.route("/static-lease/<mac>", methods=["DELETE"])
|
||||
def remove_static_lease_bp(mac):
|
||||
"""DELETE /api/dhcp/static-lease/<mac> — Remove a static DHCP lease by MAC address.
|
||||
|
||||
Args:
|
||||
mac: MAC address of the static lease to remove.
|
||||
|
||||
Returns:
|
||||
JSON response with success status or an error.
|
||||
"""
|
||||
try:
|
||||
delete("/dnsmasq/static-lease/remove", {"mac": mac})
|
||||
logger.info("Static lease removed via API: %s", mac)
|
||||
@@ -201,6 +260,14 @@ def remove_static_lease_bp(mac):
|
||||
|
||||
@bp.route("/dns-record", methods=["POST"])
|
||||
def add_dns_record_bp():
|
||||
"""POST /api/dhcp/dns-record — Add a DNS record.
|
||||
|
||||
Args:
|
||||
request: JSON body with `name`, `address`, and optional `hostname`.
|
||||
|
||||
Returns:
|
||||
JSON response with record details or an error.
|
||||
"""
|
||||
body = request.get_json(silent=True) or {}
|
||||
name = body.get("name", "").strip()
|
||||
address = body.get("address", "").strip()
|
||||
@@ -224,6 +291,14 @@ def add_dns_record_bp():
|
||||
|
||||
@bp.route("/dns-record/<name>", methods=["DELETE"])
|
||||
def remove_dns_record_bp(name):
|
||||
"""DELETE /api/dhcp/dns-record/<name> — Remove a DNS record by name.
|
||||
|
||||
Args:
|
||||
name: Name of the DNS record to remove.
|
||||
|
||||
Returns:
|
||||
JSON response with success status or an error.
|
||||
"""
|
||||
try:
|
||||
delete("/dnsmasq/dns-record/remove", {"name": name})
|
||||
logger.info("DNS record removed via API: %s", name)
|
||||
|
||||
Reference in New Issue
Block a user