gdrive
diapason.connectors.gdrive
¶
Google Drive connector — bulk file sync via the Drive REST API v3.
Uses OAuth 2.0 tokens stored locally (see :mod:diapason.connectors.oauth).
All network calls are isolated in module-level functions (_gdrive_api_*)
to make them trivially mockable in tests.
GDriveConnector
¶
Bases: BaseConnector
Connector that syncs files from Google Drive via the REST API v3.
Authentication is handled through Google OAuth 2.0. Tokens are stored locally in a JSON credentials file.
Parameters¶
credentials_path:
Path to the JSON file where OAuth tokens are stored. Defaults to
~/.diapason/connectors/gdrive.json.
auth_url()
¶
Return a Google OAuth consent URL requesting drive.readonly scope.
disconnect()
¶
Delete the stored credentials file.
handle_callback(code)
¶
Handle the OAuth callback.
If code looks like a client_id:client_secret pair (containing
.apps.googleusercontent.com), persist the client credentials only.
The actual browser consent + code→token exchange is owned by the
in-process server flow (/v1/connectors/{id}/oauth/start →
/oauth/callback), which writes the real access_token to every
Google credential file.
Previously this spawned a daemon thread that popped a browser and ran
its own localhost:8789 callback server; that thread failed silently
in the bundled desktop context, so the connector never gained an access
token and never appeared in Data Sources (issue #512). The background
flow is intentionally removed here.
Any other code is treated as a raw token / auth code.
is_connected()
¶
Return True if a credentials file with a valid access token exists.
mcp_tools()
¶
Expose three MCP tool specs for real-time Google Drive queries.
sync(*, since=None, cursor=None)
¶
Yield :class:Document objects for Google Drive files.
Paginates through the files.list API. Google Workspace files (Docs, Sheets, Slides) are exported as plain text or CSV. Non-exportable files are stored as metadata-only documents.
Parameters¶
since:
Not yet used (Drive API filtering is done server-side).
cursor:
nextPageToken from a previous sync to resume pagination.
sync_status()
¶
Return sync progress from the most recent :meth:sync call.