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