# gcloud

Google Cloud and Google's APIs from the back end: a service account's
key (an RS256 assertion traded for a token), the metadata server on GCP,
a person's own OAuth token, or an API key, behind one `GcloudAuth` that
every call takes first. The whole of it is
[docs/gcloud.md](../../docs/gcloud.md).

```text
use "pkg:gcloud/storage.mote"

let me = gcloudAuth([gcloudStorageScope()])
gcloudStorageUpload(me, "invoices/17.pdf", pdf, "application/pdf")?
let link = gcloudStorageSignGet("invoices/17.pdf", 3600, "invoice.pdf")?.url
```

| File | Covered | Left out, on purpose |
|---|---|---|
| `gcloud.mote` | Service account (key file JSON or its path; domain-wide delegation), metadata server, a person's token, API keys; tokens kept until five minutes before they end; one call, Google's errors as kinds, tries on 429 and 5xx | Workload identity federation (AWS/Azure/OIDC to GCP), impersonation through IAM Credentials, OAuth itself (the oauth extension's) |
| `storage.mote` | Put, get, head, delete, list page by page, resumable uploads in 256 KiB pieces, V4 signed GET and PUT, `gcloudStorageUploadUrl` for a page | Signing through IAM signBlob (needs a key file here), ACLs, object versions, compose, notifications, bucket admin |
| `sheets.mote` | Values get, update, append, clear, batchGet, batchUpdate; rows as records by a header row | Formatting, sheets and charts (spreadsheets.batchUpdate), creating spreadsheets |
| `drive.mote` | List with Drive's query, one-request upload, download and export, delete, permissions add, list, remove | Resumable uploads to Drive, revisions, comments, changes feed |
| `calendar.mote` | Events listed between moments, changes by sync token, made, changed, deleted; free/busy; watch channels with their token checked at `/gcloud/calendar/notify`, stopped | Recurrence rules written (read as single events), calendar lists, ACLs, Meet links |
| `gmail.mote` | Sending as `mailSend`'s provider (MIME made here, attachments), sending as a person, history since a historyId, a message read, a search, `watch` to Pub/Sub | Drafts, labels changed, threads, the Pub/Sub route for Gmail (use pubsub.mote's) |
| `fcm.mote` | FCM v1 sends with notification, data, Android, APNs and web parts; app devices per person (`gcloudPushRegister`); UNREGISTERED forgotten; `gcloudPushApps` after `notify.send` | Topics and condition sends, the legacy API (gone) |
| `apns.mote` | APNs directly, over HTTP/2 (`http2: true`), an ES256 provider token kept fifty minutes, 410 forgotten, sandbox | Certificates (.p12) instead of a key, Live Activities, VoIP pushes |
| `pubsub.mote` | Publish (attributes, ordering keys), pull, acknowledge, extend, a poll for `server every`, a push route checking Google's OIDC token (signature, audience, account) | Topic and subscription admin, exactly-once delivery, schemas |
| `bigquery.mote` | Queries with named parameters, waited for, read page by page, cells typed by the schema; streaming inserts with ids | The Storage Write API, load jobs, DML results, table admin |
| `vertex.mote` | Gemini on Vertex AI behind the ai extension (the Gemini API is the ai extension's own): a turn, a turn streamed, tools | Images, files and audio in a turn, caching, grounding, Imagen |
| `maps.mote` | Geocoding, Places (new) text search, Routes | Autocomplete, place details and photos, distance matrices |
| `tests.mote` | RS256 against RFC 7515 A.2, the assertion, every service with `given net` | |

**Not yet run against Google**: only against a stand-in that checks the
assertion's signature, every token, and every V4 signature for itself
(`tests/all.sh real_svc_gcloud`). The steps to check with real
credentials are in the docs.
