Source code for aeat.domain.modelos._verification_repository

"""Encrypted SQL repository for verification reports.

:class:`~aeat.domain.modelos.VerificationReportCatalogueRepository` persists
and loads :class:`VerificationReport` entries in a
:class:`VerificationReportCatalogue` via
:class:`~aeat.adapters.persistence.storage.SecureObjectRepository` at
``FINANCIAL`` :class:`~aeat.adapters.persistence.storage.SensitivityClass`.
The catalogue is stored as a single encrypted BLOB per profile bucket and
wrapped in :class:`~aeat.adapters.persistence.storage.Envelope` before
serialisation.
The storage contract is declared by
:data:`aeat.adapters.persistence.storage.MODELO_VERIFICATION_REPORT_CATALOGUE_NAMESPACE`;
its default object key is the singleton ``catalogue`` row.
"""

from __future__ import annotations

from typing import TYPE_CHECKING

from ...core.logging import get_logger
from ._errors import ModeloError
from ._verification_report import VerificationReport, VerificationReportCatalogue

if TYPE_CHECKING:  # pragma: no cover — import-cycle guard
    pass

_LOGGER = get_logger(__name__)
_VERIFICATION_NAMESPACE = "aeat.domain.modelos.verification_reports"
_VERIFICATION_OBJECT_KEY = "catalogue"
_VERIFICATION_CATALOGUE_VERSION = 1
_VERIFICATION_PERSISTENCE_MESSAGE = "errors.fail.fail_modelo_verification_report_persistence"


[docs] class VerificationReportPersistenceError(ModeloError): """Raised when the verification-report catalogue cannot be persisted or loaded. This wraps storage-boundary failures from :class:`~aeat.domain.modelos.VerificationReportCatalogueRepository` while preserving translated recovery context for callers. """
[docs] def upsert_verification_report( catalogue: VerificationReportCatalogue, report: VerificationReport, ) -> VerificationReportCatalogue: """Return a new catalogue with ``report`` inserted or replaced. Returns: A :class:`VerificationReportCatalogue` with the given report added or updated. """ mapping = dict(catalogue.reports) mapping[report.verification_report_id] = report return VerificationReportCatalogue(reports=mapping)
__all__ = [ "VerificationReportPersistenceError", "upsert_verification_report", ]