feat: add Authentik access widgets
This commit is contained in:
@@ -1,15 +1,11 @@
|
||||
"""Authentik service definition.
|
||||
|
||||
Authentik is the user-directory source (replacing the Jellyfin-backed Users
|
||||
page). Its directory API is queried via :class:`AuthentikClient` and surfaced
|
||||
on the Authentik service page (Users + Messaging tabs). OIDC authentication
|
||||
is unchanged -- this service type is for the directory, not SSO.
|
||||
"""
|
||||
"""Authentik service definition for read-only directory and access metadata."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from media_library_viewer_api.clients.authentik import AuthentikClient
|
||||
from media_library_viewer_api.integrations.base import (
|
||||
SecretField,
|
||||
@@ -17,27 +13,25 @@ from media_library_viewer_api.integrations.base import (
|
||||
ServiceConfigBase,
|
||||
ServiceDefinition,
|
||||
TestResult,
|
||||
WidgetConfigBase,
|
||||
translate_connection_error,
|
||||
widget_kind,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from media_library_viewer_api.services.settings_store import SettingsStore
|
||||
|
||||
|
||||
def test_connection(
|
||||
config: dict[str, Any],
|
||||
secrets: dict[str, str],
|
||||
store: SettingsStore,
|
||||
) -> TestResult:
|
||||
"""Probe AuthentikClient.users(page=1, page_size=1) — lightest directory call."""
|
||||
def test_connection(config: dict[str, Any], secrets: dict[str, str], store: SettingsStore) -> TestResult:
|
||||
"""Probe the least-expensive Authentik directory endpoint."""
|
||||
try:
|
||||
base_url = str(config.get("base_url") or "").rstrip("/")
|
||||
api_token = str(secrets.get("api_token") or "")
|
||||
timeout = float(config.get("timeout_seconds") or 60)
|
||||
client = AuthentikClient(base_url=base_url, api_token=api_token, timeout=timeout)
|
||||
client = AuthentikClient(
|
||||
base_url=str(config.get("base_url") or "").rstrip("/"),
|
||||
api_token=str(secrets.get("api_token") or ""),
|
||||
timeout=float(config.get("timeout_seconds") or 60),
|
||||
)
|
||||
result = client.users(page=1, page_size=1)
|
||||
total = result.get("total", 0) if isinstance(result, dict) else 0
|
||||
return TestResult(ok=True, detail="Connected to Authentik.", evidence=f"{total} users")
|
||||
return TestResult(ok=True, detail="Connected to Authentik.", evidence=f"{result.get('total', 0)} users")
|
||||
except Exception as exc:
|
||||
return translate_connection_error(exc, context="Authentik")
|
||||
|
||||
@@ -46,17 +40,46 @@ class AuthentikConfig(ServiceConfigBase):
|
||||
"""Non-secret Authentik connection config."""
|
||||
|
||||
base_url: ServiceBaseUrl
|
||||
timeout_seconds: int = 60
|
||||
timeout_seconds: int = Field(default=60, ge=1, le=300)
|
||||
|
||||
|
||||
class AuthentikListWidgetConfig(WidgetConfigBase):
|
||||
"""Bounded display count for read-only Authentik list widgets."""
|
||||
|
||||
limit: int = Field(default=10, ge=1, le=50)
|
||||
|
||||
|
||||
DEFINITION = ServiceDefinition(
|
||||
service_type="authentik",
|
||||
name="Authentik",
|
||||
description="User directory and identity provider integration.",
|
||||
description="Read-only user directory, groups, and application access metadata.",
|
||||
config_model=AuthentikConfig,
|
||||
secret_fields=[
|
||||
SecretField(key="api_token", label="API token", required=True),
|
||||
secret_fields=[SecretField(key="api_token", label="API token", required=True)],
|
||||
widget_kinds=[
|
||||
widget_kind(
|
||||
kind="access_summary",
|
||||
name="User access summary",
|
||||
description="User group memberships and explicit staff/superuser status; not effective authorization.",
|
||||
model_cls=AuthentikListWidgetConfig,
|
||||
default_config={"limit": 10},
|
||||
refresh_interval_ms=60_000,
|
||||
),
|
||||
widget_kind(
|
||||
kind="groups",
|
||||
name="Groups",
|
||||
description="Read-only Authentik group list.",
|
||||
model_cls=AuthentikListWidgetConfig,
|
||||
default_config={"limit": 10},
|
||||
refresh_interval_ms=60_000,
|
||||
),
|
||||
widget_kind(
|
||||
kind="applications",
|
||||
name="Applications",
|
||||
description="Read-only Authentik application list.",
|
||||
model_cls=AuthentikListWidgetConfig,
|
||||
default_config={"limit": 10},
|
||||
refresh_interval_ms=60_000,
|
||||
),
|
||||
],
|
||||
widget_kinds=[],
|
||||
test_callable=test_connection,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user