valstorm-plugin-gcp — Google Cloud Platform & BigQuery Plugin (NF-486)
Foundational Google Cloud Platform (GCP) infrastructure and data warehouse plugin for Open Valstorm, mounted at platform.gcp (VALSTORM_PLUGINS=gcp or *).
Provides multi-tenant, encrypted Service Account authentication for:
- Google BigQuery (
platform.gcp.bigquery): Dataset/table discovery, schema inspection, parameterized SQL query execution, and streaming row insertion. - Google Cloud Pub/Sub (
platform.gcp.pubsub): Topic creation, push/pull subscription provisioning (including Gmail push watch topics), and message publishing. - Extensible GCP Service Hooks:
.storage,.compute,.iam, and.billing.
🤖 Agent-Assisted Quick Setup (Let the Valstorm Agent Set It Up)
Instead of clicking through the Google Cloud Console manually, you can authenticate the gcloud CLI once on your machine and let your Valstorm AI Agent provision the APIs, Service Account, IAM bindings, Pub/Sub topic, encrypted Valstorm credentials, and live connection verification automatically.
1. One-Time Human Prerequisite (60 Seconds)
Install the Google Cloud CLI and sign in with your Google Cloud admin account:
# macOS (Homebrew)
brew install --cask google-cloud-sdk
# Authenticate and select your target GCP project
gcloud auth login
gcloud config set project YOUR_GCP_PROJECT_ID2. Copy-Paste Prompt for Your Valstorm Agent
Drop this prompt into Valstorm Chat (or your local agent):
"Set up
valstorm-plugin-gcpfor my GCP project<YOUR_GCP_PROJECT_ID>(default BigQuery dataset:<YOUR_DATASET>). Use the steps inplugins/valstorm-plugin-gcp/README.mdto enable the APIs viagcloud, create thevalstorm-gcp-integrationservice account and IAM bindings, save the encrypted credentials intoplatform.credentialsunder'gcp', delete any temporary key file, and rungcp_verify_connection."
3. Agent Execution Runbook (Instructions for the AI Agent)
When a user asks you to set up valstorm-plugin-gcp, execute this sequence autonomously:
- Verify
gcloudAuth & Project:
- Run
gcloud config get-value projectandgcloud auth list --filter=status:ACTIVE --format="value(account)"to confirm an active authenticated session.
- Enable Required GCP APIs:
- Run
gcloud services enable bigquery.googleapis.com pubsub.googleapis.com iamcredentials.googleapis.com --project=<PROJECT_ID>.
- Idempotently Create Service Account & Bind IAM Roles:
- Create
valstorm-gcp-integration@<PROJECT_ID>.iam.gserviceaccount.com(ignoreALREADY_EXISTS). - Bind
roles/bigquery.dataEditor,roles/bigquery.jobUser, androles/pubsub.editor. - If the user also uses Gmail push sync, create topic
gmail-watch-eventsand bindserviceAccount:[email protected]withroles/pubsub.publisher.
- Provision Key, Save Encrypted Credential, & Shred Temp File:
- Create a temporary key at
/tmp/vst_gcp_sa.json, read and parse the JSON in Python, callawait platform.credentials.save("gcp", {**sa_json, "default_dataset": dataset}), and immediately delete/tmp/vst_gcp_sa.json(os.remove).
- Verify Live Connection:
- Call
gcp_verify_connection(orawait platform.gcp.verify_connection()) andgcp_bigquery_list_datasetsto confirm end-to-end access.
🛠️ End-to-End DIY Setup Guide (Manual / CLI)
Step 1: Enable Required Google Cloud APIs
In the Google Cloud Console, select or create your GCP project and enable:
- BigQuery API (
bigquery.googleapis.com) - Cloud Pub/Sub API (
pubsub.googleapis.com) - IAM Service Account Credentials API (
iamcredentials.googleapis.com)
gcloud services enable \
bigquery.googleapis.com \
pubsub.googleapis.com \
iamcredentials.googleapis.com \
--project=YOUR_GCP_PROJECT_IDStep 2: Create a Service Account & Grant IAM Roles
Create a dedicated service account for Open Valstorm and grant least-privilege roles for BigQuery and Pub/Sub:
# 1. Create the service account
gcloud iam service-accounts create valstorm-gcp-integration \
--display-name="Valstorm GCP Integration" \
--project=YOUR_GCP_PROJECT_ID
# 2. Grant BigQuery Data Editor & Job User roles
gcloud projects add-iam-policy-binding YOUR_GCP_PROJECT_ID \
--member="serviceAccount:valstorm-gcp-integration@YOUR_GCP_PROJECT_ID.iam.gserviceaccount.com" \
--role="roles/bigquery.dataEditor"
gcloud projects add-iam-policy-binding YOUR_GCP_PROJECT_ID \
--member="serviceAccount:valstorm-gcp-integration@YOUR_GCP_PROJECT_ID.iam.gserviceaccount.com" \
--role="roles/bigquery.jobUser"
# 3. Grant Cloud Pub/Sub Editor role (for topic/subscription management & publishing)
gcloud projects add-iam-policy-binding YOUR_GCP_PROJECT_ID \
--member="serviceAccount:valstorm-gcp-integration@YOUR_GCP_PROJECT_ID.iam.gserviceaccount.com" \
--role="roles/pubsub.editor"Step 3: (Optional) Grant Gmail Push Publisher Access to Your Pub/Sub Topic
If you are using valstorm-plugin-gcp together with valstorm-plugin-google-workspace for real-time Gmail push notifications, grant Google's official Gmail push service account ([email protected]) permission to publish to your Pub/Sub topic:
gcloud pubsub topics add-iam-policy-binding gmail-watch-events \
--member="serviceAccount:[email protected]" \
--role="roles/pubsub.publisher" \
--project=YOUR_GCP_PROJECT_IDStep 4: Generate & Download the Service Account JSON Key
gcloud iam service-accounts keys create ./valstorm-gcp-sa.json \
--iam-account="valstorm-gcp-integration@YOUR_GCP_PROJECT_ID.iam.gserviceaccount.com"(Delete the local ./valstorm-gcp-sa.json file immediately after saving it into Open Valstorm's encrypted credential store below.)
2. Configuring Credentials in Open Valstorm
Open Valstorm never reads local JSON key files from disk in production. Credentials are encrypted at rest per tenant in PostgreSQL (auth_credential) using AES-256-CBC / tenant BYOK envelope encryption via platform.credentials.
Option A: Save via Python PlatformContext
await platform.credentials.save(
"gcp",
{
"type": "service_account",
"project_id": "your-gcp-project-id",
"private_key_id": "key-id-from-json",
"private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
"client_email": "valstorm-gcp-integration@your-gcp-project-id.iam.gserviceaccount.com",
"client_id": "1234567890",
"token_uri": "https://oauth2.googleapis.com/token",
"default_dataset": "analytics_warehouse",
},
)Option B: Verify Connection via REST API or AI Tool
Once saved, verify connectivity and IAM permissions:
curl -X POST http://localhost:8000/v1/gcp/verify \
-H "Authorization: Bearer <YOUR_JWT_TOKEN>"Or ask the Valstorm AI Agent to run gcp_verify_connection or gcp_get_setup_guide.
3. Activating the Plugin
Set VALSTORM_PLUGINS in your environment or .env:
# Enable all plugins (default)
VALSTORM_PLUGINS=*
# Or enable explicitly alongside related plugins
VALSTORM_PLUGINS=gcp,google-workspace,google-marketing4. Usage Examples (platform.gcp)
# 1. List BigQuery datasets & tables
datasets = await platform.gcp.bigquery.list_datasets()
tables = await platform.gcp.bigquery.list_tables("analytics_warehouse")
# 2. Inspect a BigQuery table schema
schema = await platform.gcp.bigquery.get_table_schema("analytics_warehouse", "events")
# 3. Execute a parameterized SQL query in BigQuery
rows = await platform.gcp.bigquery.query(
"SELECT event_name, COUNT(*) AS total FROM `analytics_warehouse.events` WHERE org_id = @org_id GROUP BY 1",
params={"org_id": platform.org_id},
)
# 4. Stream rows into BigQuery
await platform.gcp.bigquery.insert_rows(
dataset="analytics_warehouse",
table="events",
rows=[{"event_name": "lead_created", "org_id": platform.org_id}],
)
# 5. Publish a message to Google Cloud Pub/Sub
msg_id = await platform.gcp.pubsub.publish(
topic="crm-events",
data=b'{"event": "deal_closed_won"}',
attributes={"org_id": platform.org_id},
)5. REST API Endpoints (/v1/gcp/*)
| Method | Endpoint | Description |
|---|---|---|
GET | /v1/gcp/setup-guide | Interactive step-by-step GCP setup instructions |
POST | /v1/gcp/verify | Validates GCP Service Account credentials & BigQuery reachability |
GET | /v1/gcp/bigquery/datasets | Lists all BigQuery datasets in the project |
GET | /v1/gcp/bigquery/datasets/{dataset}/tables | Lists tables inside a BigQuery dataset |
GET | /v1/gcp/bigquery/datasets/{dataset}/tables/{table} | Returns column schema for a BigQuery table |
POST | /v1/gcp/bigquery/query | Executes a SQL query against BigQuery |
POST | /v1/gcp/bigquery/insert | Streams JSON rows into a BigQuery table |
POST | /v1/gcp/pubsub/publish | Publishes a message to a Cloud Pub/Sub topic |
6. AI Agent Tools (get_gcp_tools())
gcp_get_setup_guidegcp_verify_connectiongcp_bigquery_list_datasetsgcp_bigquery_list_tablesgcp_bigquery_get_table_schemagcp_bigquery_querygcp_bigquery_insert_rowsgcp_pubsub_publish
7. Running Tests
cd apps/open-api
.venv/bin/pytest tests/test_plugin_gcp.py -v