eebc86a52b
Add a shared ServiceBaseUrl type (BeforeValidator + Field description) in integrations/base.py and apply it to base_url across all six service configs (grafana, prometheus, alertmanager, jellyfin, jellyseerr, nextcloud). Missing http:// or https:// schema now fails fast with a clear 422 instead of breaking HTTP clients silently. Tests cover reject/accept cases; REQUIREMENTS updated.
48 lines
1.1 KiB
Python
48 lines
1.1 KiB
Python
"""Grafana service definition."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from media_library_viewer_api.integrations.base import (
|
|
SecretField,
|
|
ServiceBaseUrl,
|
|
ServiceConfigBase,
|
|
ServiceDefinition,
|
|
WidgetConfigBase,
|
|
widget_kind,
|
|
)
|
|
|
|
|
|
class GrafanaConfig(ServiceConfigBase):
|
|
"""Non-secret Grafana connection config."""
|
|
|
|
base_url: ServiceBaseUrl
|
|
timeout_seconds: int = 5
|
|
|
|
|
|
class GrafanaLinkWidgetConfig(WidgetConfigBase):
|
|
"""Deep-link to a Grafana dashboard or panel."""
|
|
|
|
dashboard_uid: str
|
|
panel_id: int | None = None
|
|
|
|
|
|
DEFINITION = ServiceDefinition(
|
|
service_type="grafana",
|
|
name="Grafana",
|
|
description="Dashboards, metrics, and logs.",
|
|
config_model=GrafanaConfig,
|
|
secret_fields=[
|
|
SecretField(key="api_key", label="API key", helper="Service account token (optional)"),
|
|
],
|
|
widget_kinds=[
|
|
widget_kind(
|
|
kind="link",
|
|
name="Dashboard link",
|
|
description="Deep-link to a Grafana dashboard or panel.",
|
|
model_cls=GrafanaLinkWidgetConfig,
|
|
default_config={"dashboard_uid": ""},
|
|
refresh_interval_ms=0,
|
|
),
|
|
],
|
|
)
|