8cdeadd6dd
PR 1 of 4 for the runtime service registry change. - Add Fernet encryption helper (services/secrets.py) with a required MANAGE_ENCRYPTION_KEY; validate it on startup. - Add closed integrations/ registry with Pydantic config + widget-config definitions for grafana, prometheus, jellyfin, nextcloud, and ssh_tasks. - Add services + service_task_runs tables and SettingsStore CRUD with cascade-delete (defensive until widgets carry service_id). - Add /api/services/types and /api/services/instances CRUD (encrypted secrets, secrets_set flags only; never plaintext). - Declare cryptography as a direct dependency. - Require MANAGE_ENCRYPTION_KEY in compose + .env.example + README. - Add 25 backend tests (registry, encryption, CRUD, cascade, task-run history). Verification: ruff clean; pytest 225 passed; frontend lint/build green.
61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
"""SSH task runner service definition.
|
|
|
|
An ``ssh_tasks`` instance is an SSH endpoint that can run reusable saved tasks.
|
|
Tasks themselves stay in the global saved-task registry; the instance only owns
|
|
transport (host/port/user/key). Every run is recorded in ``service_task_runs``
|
|
and shown as history on the instance's service page.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from media_library_viewer_api.integrations.base import (
|
|
SecretField,
|
|
ServiceConfigBase,
|
|
ServiceDefinition,
|
|
WidgetConfigBase,
|
|
widget_kind,
|
|
)
|
|
|
|
|
|
class SshTasksConfig(ServiceConfigBase):
|
|
"""Non-secret SSH task runner config.
|
|
|
|
The SSH key itself lives in the saved SSH-key registry and is referenced by
|
|
``ssh_key_id``. An optional ``passphrase`` is stored as a secret.
|
|
"""
|
|
|
|
host: str
|
|
port: int = 22
|
|
username: str = ""
|
|
ssh_key_id: str = ""
|
|
timeout_seconds: int = 30
|
|
|
|
|
|
class SshTaskOutputWidgetConfig(WidgetConfigBase):
|
|
"""Output of a saved task run on this instance."""
|
|
|
|
task_id: str
|
|
# service_id is implicit (the widget's service); allow overriding per-widget.
|
|
service_id: str | None = None
|
|
|
|
|
|
DEFINITION = ServiceDefinition(
|
|
service_type="ssh_tasks",
|
|
name="SSH task runner",
|
|
description="Run reusable saved tasks over SSH and keep run history.",
|
|
config_model=SshTasksConfig,
|
|
secret_fields=[
|
|
SecretField(key="passphrase", label="Key passphrase", helper="Optional"),
|
|
],
|
|
widget_kinds=[
|
|
widget_kind(
|
|
kind="task_output",
|
|
name="Task output",
|
|
description="Output of a saved task run.",
|
|
model_cls=SshTaskOutputWidgetConfig,
|
|
default_config={"task_id": ""},
|
|
refresh_interval_ms=0,
|
|
),
|
|
],
|
|
)
|