style(services): apply formatter to service registry files

This commit is contained in:
Developer
2026-06-22 14:00:07 +00:00
parent 8cdeadd6dd
commit fd534a816b
3 changed files with 12 additions and 38 deletions
@@ -28,9 +28,7 @@ def _validate_config_keys(config: dict[str, Any]) -> dict[str, Any]:
if isinstance(value, dict):
for key, child in value.items():
if key.lower() in forbidden:
raise ValueError(
f"Credential key '{key}' is not allowed in service config"
)
raise ValueError(f"Credential key '{key}' is not allowed in service config")
_check(child)
elif isinstance(value, list):
for item in value:
@@ -34,16 +34,12 @@ def get_encryption_key() -> bytes:
"""
raw = os.environ.get(ENCRYPTION_KEY_ENV)
if not raw:
raise EncryptionKeyError(
f"{ENCRYPTION_KEY_ENV} is required to store service secrets"
)
raise EncryptionKeyError(f"{ENCRYPTION_KEY_ENV} is required to store service secrets")
key = raw.strip().encode()
try:
Fernet(key)
except (ValueError, TypeError) as exc: # pragma: no cover - validated by tests
raise EncryptionKeyError(
f"{ENCRYPTION_KEY_ENV} must be a valid Fernet key"
) from exc
raise EncryptionKeyError(f"{ENCRYPTION_KEY_ENV} must be a valid Fernet key") from exc
return key
@@ -179,9 +179,7 @@ class SettingsStore:
)
"""
)
conn.execute(
"CREATE INDEX IF NOT EXISTS idx_dashboard_widgets_sort ON dashboard_widgets(sort_order)"
)
conn.execute("CREATE INDEX IF NOT EXISTS idx_dashboard_widgets_sort ON dashboard_widgets(sort_order)")
conn.execute("""
CREATE TABLE IF NOT EXISTS backup_jobs (
id TEXT PRIMARY KEY,
@@ -262,8 +260,7 @@ class SettingsStore:
"ON service_task_runs(service_id, created_at DESC)"
)
conn.execute(
"CREATE INDEX IF NOT EXISTS idx_service_task_runs_task "
"ON service_task_runs(task_id, created_at DESC)"
"CREATE INDEX IF NOT EXISTS idx_service_task_runs_task ON service_task_runs(task_id, created_at DESC)"
)
@staticmethod
@@ -1402,7 +1399,6 @@ class SettingsStore:
(key, value, now),
)
# ------------------------------------------------------------------
# Dashboard widgets
# ------------------------------------------------------------------
@@ -1426,14 +1422,9 @@ class SettingsStore:
widget_id: str | None = None,
) -> dict[str, Any]:
current = self.get_widget(widget_id) if widget_id else None
widget_id = (
str(payload.get("id") or widget_id or uuid.uuid4().hex[:12]).strip()
or uuid.uuid4().hex[:12]
)
widget_id = str(payload.get("id") or widget_id or uuid.uuid4().hex[:12]).strip() or uuid.uuid4().hex[:12]
addon_id = str(payload.get("addon_id") or (current or {}).get("addon_id", "")).strip()
widget_type = str(
payload.get("widget_type") or (current or {}).get("widget_type", "")
).strip()
widget_type = str(payload.get("widget_type") or (current or {}).get("widget_type", "")).strip()
title = str(payload.get("title") or (current or {}).get("title", "") or "").strip()
config = payload.get("config", (current or {}).get("config", {}))
if not isinstance(config, dict):
@@ -1455,9 +1446,7 @@ class SettingsStore:
def list_widgets(self) -> list[dict[str, Any]]:
self.init_schema()
with self.connect() as conn:
rows = conn.execute(
"SELECT * FROM dashboard_widgets ORDER BY sort_order ASC, created_at ASC"
).fetchall()
rows = conn.execute("SELECT * FROM dashboard_widgets ORDER BY sort_order ASC, created_at ASC").fetchall()
return [self._row_to_widget(row) for row in rows]
def get_widget(self, widget_id: str | None) -> dict[str, Any] | None:
@@ -1465,9 +1454,7 @@ class SettingsStore:
return None
self.init_schema()
with self.connect() as conn:
row = conn.execute(
"SELECT * FROM dashboard_widgets WHERE id = ?", (widget_id,)
).fetchone()
row = conn.execute("SELECT * FROM dashboard_widgets WHERE id = ?", (widget_id,)).fetchone()
return self._row_to_widget(row) if row else None
def upsert_widget(self, payload: dict[str, Any], widget_id: str | None = None) -> dict[str, Any]:
@@ -1547,9 +1534,7 @@ class SettingsStore:
def get_service(self, service_id: str) -> dict[str, Any] | None:
self.init_schema()
with self.connect() as conn:
row = conn.execute(
"SELECT * FROM services WHERE id = ?", (service_id,)
).fetchone()
row = conn.execute("SELECT * FROM services WHERE id = ?", (service_id,)).fetchone()
return self._row_to_service(row) if row else None
def _normalize_service_payload(
@@ -1558,13 +1543,8 @@ class SettingsStore:
service_id: str | None = None,
) -> dict[str, Any]:
current = self.get_service(service_id) if service_id else None
service_id = (
str(payload.get("id") or service_id or uuid.uuid4().hex[:12]).strip()
or uuid.uuid4().hex[:12]
)
service_type = str(
payload.get("service_type") or (current or {}).get("service_type", "")
).strip()
service_id = str(payload.get("id") or service_id or uuid.uuid4().hex[:12]).strip() or uuid.uuid4().hex[:12]
service_type = str(payload.get("service_type") or (current or {}).get("service_type", "")).strip()
name = str(payload.get("name") or (current or {}).get("name", "") or "").strip()
config = payload.get("config", (current or {}).get("config", {}))
if not isinstance(config, dict):