refactor: update lib modules (common, dnsmasq, logging, network, state, nginx)

This commit is contained in:
2026-06-16 03:35:50 +00:00
parent 593dece92b
commit c5813d68b3
6 changed files with 196 additions and 33 deletions
+27
View File
@@ -6,12 +6,38 @@ deep merging, and directory creation used across all subsystem modules.
import json
import os
import re
import subprocess
from copy import deepcopy
from pathlib import Path
from typing import Any
def validate_interface_name(name: str) -> str:
"""Validate a Linux network interface name.
Args:
name: Interface name to validate.
Returns:
The validated (stripped) name.
Raises:
ValueError: When the name is empty, contains path components,
or does not match Linux interface naming rules.
"""
if not name or not isinstance(name, str):
raise ValueError("Interface name must be a non-empty string")
name = name.strip()
if not name:
raise ValueError("Interface name must not be blank")
if "/" in name or ".." in name or " " in name:
raise ValueError(f"Invalid interface name: {name!r}")
if not re.match(r"^[a-zA-Z0-9][a-zA-Z0-9._-]*$", name):
raise ValueError(f"Invalid interface name: {name!r}")
return name
def run(
cmd: list[str],
check: bool = True,
@@ -134,4 +160,5 @@ __all__ = [
"run",
"run_proc",
"save_json",
"validate_interface_name",
]