mirror of
https://github.com/idrainformatica/PecFlow.git
synced 2026-06-16 12:45:42 +02:00
71 lines
2.5 KiB
Python
71 lines
2.5 KiB
Python
"""
|
||
Modello TenantSettings – configurazione per-tenant (archiviazione sostitutiva, ecc.).
|
||
"""
|
||
|
||
import uuid
|
||
from datetime import datetime
|
||
|
||
from sqlalchemy import DateTime, Index, String, Text, UniqueConstraint, func
|
||
from sqlalchemy.dialects.postgresql import UUID
|
||
from sqlalchemy.orm import Mapped, mapped_column
|
||
|
||
from app.database import Base
|
||
|
||
|
||
class TenantSettings(Base):
|
||
"""
|
||
Configurazione operativa per tenant.
|
||
|
||
Attualmente gestisce:
|
||
- Modalità archiviazione sostitutiva (mock / production)
|
||
- Credenziali conservatore AgID (cifrate AES-256-GCM)
|
||
|
||
Una riga per tenant, creata al primo accesso (upsert).
|
||
"""
|
||
|
||
__tablename__ = "tenant_settings"
|
||
|
||
id: Mapped[uuid.UUID] = mapped_column(
|
||
UUID(as_uuid=True), primary_key=True, default=uuid.uuid4
|
||
)
|
||
tenant_id: Mapped[uuid.UUID] = mapped_column(
|
||
UUID(as_uuid=True), nullable=False, index=True
|
||
)
|
||
|
||
# ── Archiviazione sostitutiva ─────────────────────────────────────────────
|
||
# 'mock' → conservatore simulato (risposte false, default per dev)
|
||
# 'production' → endpoint reale AgID conservatore
|
||
archival_mode: Mapped[str] = mapped_column(
|
||
String(20), nullable=False, default="mock"
|
||
)
|
||
|
||
# Identificativo conservatore (es. 'aruba-cons', 'docuvision', 'mock')
|
||
conservatore_id: Mapped[str] = mapped_column(
|
||
String(100), nullable=False, default="mock"
|
||
)
|
||
|
||
# URL endpoint API conservatore (None in modalità mock)
|
||
conservatore_endpoint: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||
|
||
# Credenziali cifrate AES-256-GCM (None in modalità mock)
|
||
conservatore_username_enc: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||
conservatore_password_enc: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||
|
||
# Note operative opzionali
|
||
archival_notes: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||
|
||
created_at: Mapped[datetime] = mapped_column(
|
||
DateTime(timezone=True), nullable=False, server_default=func.now()
|
||
)
|
||
updated_at: Mapped[datetime] = mapped_column(
|
||
DateTime(timezone=True), nullable=False, server_default=func.now(), onupdate=func.now()
|
||
)
|
||
|
||
__table_args__ = (
|
||
UniqueConstraint("tenant_id", name="uq_tenant_settings_tenant"),
|
||
Index("idx_tenant_settings_tenant", "tenant_id"),
|
||
)
|
||
|
||
def __repr__(self) -> str:
|
||
return f"<TenantSettings tenant={self.tenant_id} mode={self.archival_mode!r}>"
|