Hide the passwords
This commit is contained in:
@@ -15,6 +15,8 @@ DASHBOARD_DIR = ROOT_DIR / "dashboard"
|
||||
CONFIG_PATH = ROOT_DIR / "manager" / "config.json"
|
||||
MANAGER_DIR = ROOT_DIR / "manager"
|
||||
RECOVERY_COMMANDS_PATH = PROJECT_DIR / "docker-run-commands.sh"
|
||||
MANAGER_CONTAINER_NAME = os.getenv("FIS_MANAGER_CONTAINER_NAME", "fis_manager")
|
||||
MANAGER_RESTART_TIMEOUT_SECONDS = int(os.getenv("MANAGER_RESTART_TIMEOUT_SECONDS", "30"))
|
||||
|
||||
sys.path.insert(0, str(MANAGER_DIR))
|
||||
|
||||
@@ -116,6 +118,45 @@ def write_recovery_commands_from_disk():
|
||||
write_recovery_commands(json.load(handle))
|
||||
|
||||
|
||||
def restart_manager_container():
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["docker", "restart", MANAGER_CONTAINER_NAME],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=MANAGER_RESTART_TIMEOUT_SECONDS,
|
||||
)
|
||||
except FileNotFoundError:
|
||||
return {
|
||||
"attempted": True,
|
||||
"ok": False,
|
||||
"error": "Docker CLI not found; run manually: docker restart "
|
||||
f"{MANAGER_CONTAINER_NAME}",
|
||||
}
|
||||
except subprocess.TimeoutExpired:
|
||||
return {
|
||||
"attempted": True,
|
||||
"ok": False,
|
||||
"error": f"Timed out restarting {MANAGER_CONTAINER_NAME}",
|
||||
}
|
||||
except subprocess.CalledProcessError as exc:
|
||||
error = (exc.stderr or exc.stdout or str(exc)).strip()
|
||||
return {"attempted": True, "ok": False, "error": error}
|
||||
|
||||
return {"attempted": True, "ok": True, "output": result.stdout.strip()}
|
||||
|
||||
|
||||
def read_compact_config_from_disk():
|
||||
if not CONFIG_PATH.exists():
|
||||
return None
|
||||
try:
|
||||
with CONFIG_PATH.open(encoding="utf-8") as handle:
|
||||
return compact_config(json.load(handle))
|
||||
except (OSError, ValueError, json.JSONDecodeError):
|
||||
return None
|
||||
|
||||
|
||||
def detect_lan_ip():
|
||||
configured_ip = os.getenv("CONFIGURATOR_PUBLIC_IP")
|
||||
if configured_ip:
|
||||
@@ -212,6 +253,7 @@ class ConfiguratorHandler(SimpleHTTPRequestHandler):
|
||||
content_length = int(self.headers.get("Content-Length", "0"))
|
||||
payload = self.rfile.read(content_length)
|
||||
raw = json.loads(payload.decode("utf-8"))
|
||||
previous_compact = read_compact_config_from_disk()
|
||||
normalized = normalize_config(raw)
|
||||
compact = compact_config(raw)
|
||||
CONFIG_PATH.write_text(json.dumps(compact, indent=2) + "\n", encoding="utf-8")
|
||||
@@ -223,7 +265,18 @@ class ConfiguratorHandler(SimpleHTTPRequestHandler):
|
||||
self._send_json({"ok": False, "error": f"Invalid JSON: {exc}"}, status=HTTPStatus.BAD_REQUEST)
|
||||
return
|
||||
|
||||
self._send_json({"ok": True, "config": compact, "normalized": normalized})
|
||||
manager_restart = {"attempted": False, "ok": True}
|
||||
if compact != previous_compact:
|
||||
manager_restart = restart_manager_container()
|
||||
|
||||
self._send_json(
|
||||
{
|
||||
"ok": True,
|
||||
"config": compact,
|
||||
"normalized": normalized,
|
||||
"manager_restart": manager_restart,
|
||||
}
|
||||
)
|
||||
|
||||
def log_message(self, format, *args):
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user