v2.1.2: list_app_catalog использует GET и расширенный список путей

This commit is contained in:
2026-08-03 00:22:09 +03:00
parent 70314a0097
commit fee69e65b3
+70 -48
View File
@@ -1,48 +1,70 @@
def _rest_request(self, method: str, endpoint: str, payload: Optional[dict] = None, timeout: Optional[int] = None) -> Optional[Any]: payload: Dict[str, Any] = {"catalog_name": catalog, "retrieve_all_trains": True}
method = method.upper() if category:
if method not in ("POST", "PUT", "DELETE", "PATCH", "GET"): payload["categories"] = [category]
self._last_error = f"_rest_request: неподдерживаемый метод {method}" # v2.1.2: TrueNAS 25.10 исторически делал POST /app/available, но в новых билдах
return None # многие эндпоинты переехали на GET. _rest_request сам делает POST→GET fallback
url = f"{self._base}/api/v2.0/{endpoint}" # при 405, поэтому здесь используем _post — он сам разберётся.
t = timeout if timeout is not None else self.valves.request_timeout # Дополнительно пробуем GET напрямую для надёжности.
try: endpoints = [
r = requests.request(method, url, headers=self._headers, json=payload if payload is not None else {}, timeout=t, verify=self.valves.verify_ssl) "app/available", # новый (Electric Eel+)
# v2.1.2: автоматический fallback POST → GET при 405 (Method Not Allowed). "app.available",
# Это часто встречается в TrueNAS 25.10: некоторые эндпоинты каталога "chart/release/names",
# исторически были POST, но в новых версиях стали GET. "chart.release.names",
if r.status_code == 405 and method == "POST": "chart_release/names",
try: "catalog/items", # fallback
r2 = requests.get(url, headers=self._headers, params=payload or {}, timeout=t, verify=self.valves.verify_ssl) "catalog.items",
if r2.status_code in (200, 201, 202, 204): "catalog_items",
if not r2.text: "app/available_apps",
return {"status": "ok", "http_code": r2.status_code, "via": "GET-fallback"} "app/list_apps",
try: ]
data = r2.json() apps: List[Dict[str, Any]] = []
if isinstance(data, dict): used_ep = None
data["_via"] = "GET-fallback" used_method = None
return data for ep in endpoints:
except Exception: # Сначала GET (часто работает на 25.10)
return {"status": "ok", "text": r2.text, "http_code": r2.status_code, "_via": "GET-fallback"} try:
except Exception: r = requests.get(
pass # вернёмся к исходной ошибке ниже f"{self._base}/api/v2.0/{ep}",
if r.status_code in (200, 201, 202, 204): headers=self._headers,
if not r.text: params=payload if payload else None,
return {"status": "ok", "http_code": r.status_code} timeout=self.valves.request_timeout,
try: verify=self.valves.verify_ssl,
return r.json() )
except Exception: if r.status_code == 200:
return {"status": "ok", "text": r.text, "http_code": r.status_code} try:
self._last_error = f"{method} {endpoint} → HTTP {r.status_code}: {r.text[:400]}" data = r.json()
return None if isinstance(data, list):
except requests.exceptions.SSLError as e: apps = data
self._last_error = f"SSL-ошибка {method} {endpoint}: {e}" used_ep = ep
return None used_method = "GET"
except requests.exceptions.ConnectionError as e: break
self._last_error = f"Соединение {method} {endpoint}: {e}" if isinstance(data, dict):
return None for key in ("items", "applications", "releases", "apps"):
except requests.exceptions.Timeout: if key in data and isinstance(data[key], list):
self._last_error = f"Таймаут {method} {endpoint} (> {t}с)" apps = data[key]
return None used_ep = ep
except Exception as e: used_method = "GET"
self._last_error = f"{method} {endpoint}: {type(e).__name__}: {e}" break
return None if apps:
break
except Exception:
pass
except Exception:
pass
# Затем POST (через _rest_request — у него есть fallback на GET при 405)
res = self._post(ep, payload, timeout=self.valves.request_timeout)
if res is not None:
if isinstance(res, list):
apps = res
used_ep = ep
used_method = "POST"
break
if isinstance(res, dict):
for key in ("items", "applications", "releases", "apps"):
if key in res and isinstance(res[key], list):
apps = res[key]
used_ep = ep
used_method = res.get("_via", "POST")
break
if apps:
break