aeat.adapters.outbound.google._document_link_resolver module¶
Scope-compatible resolution of recorded document links.
Ledger evidence may start from a recorded
AttachmentSource link, but the link is not
stored as evidence by itself.
resolve_document_link() fetches reachable
Drive content as bytes so the caller can persist those bytes through
add_attachment_bytes(); the original link remains
provenance metadata on that byte-bearing attachment.
list_drive_folder_documents() extends the
same minimal-scope posture to a folder: it lists the PDF/image children of a
drive.file-reachable folder so a caller can bulk-fetch every invoice in one
sweep instead of resolving one document link at a time.
The resolver stays inside the integration’s deliberate minimal-scope posture:
drive.file can download Drive files the app created or the operator picked,
so a GOOGLE_DRIVE reference to such a file resolves. Operator-external
documents, arbitrary Drive files that require drive.readonly, and Gmail
messages that require gmail.readonly are refused with
OutboundStoragePermissionError instead
of being silently stored as links.
- class DriveFolderDocument(**data)[source]¶
Bases:
BaseModelOne PDF/image child of a
drive.file-reachable Drive folder.Returned by
list_drive_folder_documents(); carries just enough metadata for a caller to fetch the file (file_id) and report it to the operator (name,mime_type).- file_id: str¶
- name: str¶
- mime_type: str¶
- class DriveFolderListing(documents, skipped_non_document_count)[source]¶
Bases:
objectThe result of listing one Drive folder’s invoice-shaped children.
documentscarries the PDF/image files the sweep will fetch;skipped_non_document_countrecords how many folder children were filtered out for carrying a non-invoice MIME type (e.g. a nested folder or an unrelated file), so the caller can report an honest total.- Parameters:
documents (tuple[DriveFolderDocument, ...])
skipped_non_document_count (int)
-
documents:
tuple[DriveFolderDocument,...]¶
- parse_drive_file_id(reference)[source]¶
Extract the Drive file id consumed by
resolve_document_link().
- resolve_document_link(*, source, reference, credentials, service=None)[source]¶
Resolve a recorded
AttachmentSourcelink to bytes.- Parameters:
source (
AttachmentSource) – The recorded link source.reference (
str) – The link reference (Drive URL / file id, Gmail link, or URL).credentials (
object) – Google OAuth credentials carrying the granted scopes.service (
_DriveService|None) – Optional pre-built Drivev3service. WhenNone(the production path) the service is built fromcredentials; tests inject a transport-only seam here so the fetch path runs without a live network or real credentials.
- Return type:
- Returns:
The fetched document bytes for
GOOGLE_DRIVElinks thedrive.filescope can reach.- Raises:
OutboundStoragePermissionError – For Gmail links, arbitrary URLs, and Drive files outside the
drive.filescope. The required sensitive scope is named incontext["required_scope"].OutboundStorageValidationError – For sources that are not remote documents, or a Drive reference with no recognisable file id.
- list_drive_folder_documents(*, folder_id, credentials, service=None)[source]¶
List the PDF/image children of a
drive.file-reachable Drive folder.Stays inside the same minimal-scope posture as
resolve_document_link():drive.fileonly lists files the app created or the operator explicitly picked, so a folder the operator has not shared with the app (or does not own under this scope) surfaces no children rather than a permission escalation. A non-existent or unreachablefolder_idmaps Google’s 403/404 to the sameOutboundStoragePermissionErrorscope-named refusalresolve_document_link()uses, so the two fetch surfaces read the same way.- Parameters:
folder_id (
str) – The Drive folder id (parsed the same way a document reference is viaparse_drive_file_id(), or passed as a bare id).credentials (
object) – Google OAuth credentials carrying the granted scopes.service (
_DriveService|None) – Optional pre-built Drivev3service (test seam).
- Return type:
- Returns:
A
DriveFolderListingnaming every PDF/image child plus a count of filtered-out non-document children.- Raises:
OutboundStoragePermissionError – When the folder is not reachable under the
drive.filescope.OutboundStorageNetworkError – On any other transport or unmapped Drive failure.