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:
@@ -36,26 +36,31 @@ def _get_state() -> dict[str, Any] | None:
|
||||
|
||||
|
||||
def _ensure_config_file() -> None:
|
||||
"""Initialize config file with defaults if missing."""
|
||||
if not CONFIG_FILE.exists():
|
||||
CONFIG_FILE.parent.mkdir(parents=True, exist_ok=True)
|
||||
save_json(CONFIG_FILE, DEFAULT_CONFIG, indent=2)
|
||||
|
||||
|
||||
def _get_config() -> dict[str, Any]:
|
||||
"""Load the firewall config file."""
|
||||
_ensure_config_file()
|
||||
return load_json(CONFIG_FILE)
|
||||
|
||||
|
||||
def _save_config(cfg: dict[str, Any]) -> None:
|
||||
"""Persist firewall config to disk."""
|
||||
_ensure_config_file()
|
||||
save_json(CONFIG_FILE, cfg, indent=2)
|
||||
|
||||
|
||||
def _reload() -> None:
|
||||
"""Reload firewalld to apply permanent changes."""
|
||||
run(["firewall-cmd", "--reload"], sudo=True)
|
||||
|
||||
|
||||
def _fp_to_str(fp: dict[str, Any]) -> str:
|
||||
"""Convert a forward-port dict to firewall-cmd CLI argument string."""
|
||||
parts = [f"port={fp['port']}", f"proto={fp['proto']}"]
|
||||
if "toaddr" in fp:
|
||||
parts.append(f"toaddr={fp['toaddr']}")
|
||||
@@ -65,6 +70,7 @@ def _fp_to_str(fp: dict[str, Any]) -> str:
|
||||
|
||||
|
||||
def _get_forward_ports(zone_name: str) -> list[str]:
|
||||
"""Return forward-port entries for a zone as CLI-style strings."""
|
||||
with suppress(Exception):
|
||||
fps = _parse_zone_output(
|
||||
zone_name,
|
||||
@@ -255,6 +261,7 @@ def _config_apply() -> dict[str, Any]:
|
||||
|
||||
|
||||
def _get_fw_state() -> dict[str, Any]:
|
||||
"""Return firewall state from the state store, or empty dict if absent."""
|
||||
fw = _get_state()
|
||||
if fw is None:
|
||||
return {}
|
||||
@@ -263,6 +270,7 @@ def _get_fw_state() -> dict[str, Any]:
|
||||
|
||||
@registry.register("GET", "/firewall/interfaces")
|
||||
def get_interfaces(_request: Any, _body: Any) -> list[dict[str, Any]]:
|
||||
"""GET /firewall/interfaces — return active interfaces from state."""
|
||||
fw = _get_fw_state()
|
||||
return fw.get("interfaces", [])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user