refactor(core): route integrations through adapter factory

This commit is contained in:
2026-07-11 20:52:41 +02:00
parent 1e0911bb6a
commit dbbab6d005
8 changed files with 245 additions and 105 deletions
+10 -6
View File
@@ -3,6 +3,8 @@ from pathlib import Path
import typer
from sqlalchemy.exc import OperationalError
from tht.adapters.dwh import ThothRestDwhAdapter
from tht.adapters.factory import build_dwh
from tht.cli.config_cmd import CONFIG_OPT
from tht.config import ConfigError, load_config
from tht.db.connection import can_create_in_schema, make_engine, ping, writable_tables
@@ -11,20 +13,21 @@ from tht.db.fetch_ca import CaFetchError, describe_pem, fetch_chain_pem, parse_h
db_app = typer.Typer(help="Operazioni sul database target")
def _ping_rest(cfg, schema: str) -> None:
def _ping_rest(adapter: ThothRestDwhAdapter, cfg, schema: str) -> None:
"""Health check via REST. Il read-only è garantito strutturalmente dall'API
(ammette solo SELECT/WITH): non serve il controllo dei privilegi di scrittura."""
from tht.rest.client import RestClient, RestError
from tht.rest.client import RestError
try:
info = RestClient(cfg.rest).ping()
info = adapter._client.ping()
except RestError as e:
typer.secho(f"ERRORE di connessione: {e}", fg=typer.colors.RED, err=True)
raise typer.Exit(code=1)
if not info.get("db_connected") or not info.get("schema_accessible"):
typer.secho(
f"ERRORE: DWH non accessibile via REST (risposta: {info}).",
fg=typer.colors.RED, err=True,
fg=typer.colors.RED,
err=True,
)
raise typer.Exit(code=1)
typer.secho(
@@ -44,8 +47,9 @@ def ping_cmd(config: Path = CONFIG_OPT) -> None:
typer.secho(f"ERRORE: {e}", fg=typer.colors.RED, err=True)
raise typer.Exit(code=1)
schema = cfg.database.db_schema
if cfg.database.transport == "rest":
_ping_rest(cfg, schema)
adapter = build_dwh(cfg)
if isinstance(adapter, ThothRestDwhAdapter):
_ping_rest(adapter, cfg, schema)
return
engine = make_engine(cfg.database)
try: