feat: add Authentik access widgets

This commit is contained in:
Developer
2026-07-14 21:41:24 +00:00
parent 4562a9dfca
commit 17976eab80
21 changed files with 1082 additions and 214 deletions
@@ -19,6 +19,7 @@ from typing import Any, Protocol
import requests
from media_library_viewer_api.clients.authentik import AuthentikClient
from media_library_viewer_api.clients.jellyfin import JellyfinClient
from media_library_viewer_api.clients.qbittorrent import QbittorrentClient
from media_library_viewer_api.domain.dashboard import (
@@ -316,6 +317,36 @@ class AlertmanagerWidgetSource:
return {"error": f"Alertmanager query failed: {exc}"}
class AuthentikWidgetSource:
"""Fetch bounded, display-safe Authentik directory metadata."""
async def fetch(self, service: ServiceRecord | None, widget_kind: str, config: dict[str, Any]) -> dict[str, Any]:
try:
if service is None:
return {"error": "Authentik widget is missing its service"}
base_url = str(service.config.get("base_url") or "")
api_token = str(service.secrets.get("api_token") or "")
timeout = _safe_int(service.config.get("timeout_seconds") or 60, 60)
limit = max(1, min(_safe_int(config.get("limit") or 10, 10), 50))
client = await asyncio.wait_for(
asyncio.to_thread(AuthentikClient, base_url, api_token, timeout), timeout=timeout
)
if widget_kind == "access_summary":
return await asyncio.wait_for(
asyncio.to_thread(client.access_summaries, page=1, page_size=limit), timeout=timeout
)
if widget_kind == "groups":
return await asyncio.wait_for(asyncio.to_thread(client.groups, limit=limit), timeout=timeout)
if widget_kind == "applications":
return await asyncio.wait_for(asyncio.to_thread(client.applications, limit=limit), timeout=timeout)
return {"error": f"Unknown Authentik widget kind: {widget_kind}"}
except asyncio.TimeoutError as _timeout_error:
return {"error": "Authentik data fetch timed out"}
except Exception as exc:
logger.exception("authentik adapter failed")
return {"error": f"Authentik data fetch failed: {exc}"}
class JellyfinWidgetSource:
"""Fetch Jellyfin sessions and map them to activity rows."""
@@ -531,6 +562,7 @@ SERVICE_ADAPTERS: dict[str, WidgetSource] = {
"qbittorrent": QbittorrentWidgetSource(),
"alertmanager": AlertmanagerWidgetSource(),
"jellyfin": JellyfinWidgetSource(),
"authentik": AuthentikWidgetSource(),
"remote_machine": SshTaskWidgetSource(),
}