Source code for cadrumo.application.aggregation.catalogue_read_binding
"""Refuse catalogue read ports bound to a different profile bucket."""from__future__importannotationsfrom...core.i18n.translatableimportTranslatableastrfrom..invoices.catalogue_reads_portsimportBucketBoundCatalogueReader,InvoiceCatalogueReadPortsfrom.errorsimportAggregationValidationError
[docs]defrequire_catalogue_reads_bound_to(ports:InvoiceCatalogueReadPorts,*,bucket_id:str)->None:"""Refuse ports whose readers declare a bucket other than ``bucket_id``. Composition binds both readers to one bucket, but an aggregation entry point is handed the ports and must not trust that: a reader bound to another bucket, or to none, would silently aggregate someone else's ledger. A reader that declares no bucket at all is an in-memory projection with no store behind it and is not checked. """forreader,messagein((ports.transaction_reader,"aggregation.renta_ledger.errors.bucket_mismatch"),(ports.invoice_reader,"aggregation.renta_ledger.errors.invoice_bucket_mismatch"),):ifisinstance(reader,BucketBoundCatalogueReader)andreader.bucket_id!=bucket_id:raiseAggregationValidationError(tr(message),context={"bucket_id":bucket_id,"repository_bucket_id":reader.bucket_id},)