From 6fdb0692adc597792d82a43bbb27190e1711d4e8 Mon Sep 17 00:00:00 2001 From: host Date: Mon, 3 Aug 2026 00:22:54 +0300 Subject: [PATCH] =?UTF-8?q?v2.1.2:=20validate=5Fapi=5Fkey=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D1=80=D1=8F=D0=B5=D1=82=20=D1=80=D0=B5=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20=D1=8D=D0=BD=D0=B4=D0=BF=D0=BE?= =?UTF-8?q?=D0=B8=D0=BD=D1=82=D1=8B=20+=20GET=20app/available?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- truenas_tools.py | 58 ++++++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/truenas_tools.py b/truenas_tools.py index 6bb3d02..3a45d5d 100644 --- a/truenas_tools.py +++ b/truenas_tools.py @@ -1,23 +1,39 @@ - info_payload: Dict[str, Any] = {"catalog_name": catalog, "app_name": app_name, "train": train} - # v2.1.2: сначала пробуем GET (TrueNAS 25.10 часто требует GET), - # затем POST через _rest_request (там есть fallback POST→GET при 405) - info: Optional[Dict[str, Any]] = None - for ep in ("app/info", "app.info", "catalog/item", "catalog.item"): + # v2.1.2: проверяем реально работающие эндпоинты TrueNAS 25.10 + # (многие получили новые имена — перебираем варианты) + checks = [ + ("system/info", "GET", None, "базовая информация о системе"), + ("alert/list", "GET", None, "список алертов"), + ("catalog", "GET", None, "список каталогов приложений"), + ("pool/query", "GET", None, "список пулов ZFS (v2)"), + ("pool", "GET", None, "список пулов ZFS (v1)"), + ("disk/query", "GET", None, "список дисков (v2)"), + ("disk", "GET", None, "список дисков (v1)"), + ("app/query", "GET", None, "список приложений (v2)"), + ("app", "GET", None, "список приложений (v1)"), + ("chart/release/query", "GET", None, "helm-релизы"), + ] + ok = 0 + checked: set = set() + for endpoint, method, payload, descr in checks: + if endpoint in checked: + continue + checked.add(endpoint) + url = f"{self._base}/api/v2.0/{endpoint}" try: - r = requests.get( - f"{self._base}/api/v2.0/{ep}", - headers=self._headers, - params=info_payload, - timeout=self.valves.request_timeout, - verify=self.valves.verify_ssl, - ) + if method == "GET": + r = requests.get(url, headers=self._headers, params=payload, timeout=self.valves.request_timeout, verify=self.valves.verify_ssl) + else: + r = requests.post(url, headers=self._headers, json=payload or {}, timeout=self.valves.request_timeout, verify=self.valves.verify_ssl) if r.status_code == 200: - info = r.json() - break - except Exception: - pass - if info is None: - info = self._post("app/info", info_payload, timeout=self.valves.request_timeout) - if info is None: - info = self._post("catalog/item", info_payload, timeout=self.valves.request_timeout) - if info is None: \ No newline at end of file + lines.append(f"✅ {endpoint:30s} — {descr}") + ok += 1 + elif r.status_code in (401, 403): + lines.append(f"🔑 {endpoint:30s} — 401/403 (нет прав)") + elif r.status_code == 404: + lines.append(f"❌ {endpoint:30s} — HTTP 404 (нет такого пути)") + elif r.status_code == 405: + lines.append(f"⚠️ {endpoint:30s} — HTTP 405 (другой метод)") + else: + lines.append(f"⚠️ {endpoint:30s} — HTTP {r.status_code}") + except Exception as e: + lines.append(f"💥 {endpoint:30s} — ошибка: {type(e).__name__}") \ No newline at end of file