Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/examples/connectors/google-cloud/fixture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"kind": "storage#object",
"id": "my-bucket/uploads/document.pdf/1732368000000000",
"selfLink": "https://www.googleapis.com/storage/v1/b/my-bucket/o/uploads%2Fdocument.pdf",
"mediaLink": "https://storage.googleapis.com/download/storage/v1/b/my-bucket/o/uploads%2Fdocument.pdf?generation=1732368000000000&alt=media",
"name": "uploads/document.pdf",
"bucket": "my-bucket",
"generation": "1732368000000000",
"metageneration": "1",
"contentType": "application/pdf",
"storageClass": "STANDARD",
"size": "2048",
"md5Hash": "1B2M2Y8AsgTpgAmY7PhCfg==",
"crc32c": "AAAAAA==",
"etag": "CKiG9oDEhvQCEAE=",
"timeCreated": "2023-11-23T12:00:00.000Z",
"updated": "2023-11-23T12:00:00.000Z",
"timeStorageClassUpdated": "2023-11-23T12:00:00.000Z"
}
53 changes: 53 additions & 0 deletions docs/examples/connectors/google-cloud/google-cloud.vjs.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# connector: google-cloud — Comprehensive Google Cloud Platform API integration
#
# Platform connector for Google Cloud Platform. Supports multiple operations:
# - Cloud Storage (upload, download, list, delete objects)
# - Pub/Sub (publish messages, create topics, subscriptions)
# - Cloud Functions (invoke functions, list functions)
# - Cloud Run (invoke services, list services)
# - Firestore (CRUD operations on documents)
#
# Uses http-out driver for API calls. GCP requires OAuth2 service account authentication.
# Individual operations use flows that consume from subjects and make direct API calls.
#
# Subjects:
# IN: vx.gcp.storage.upload (upload objects to Cloud Storage)
# IN: vx.gcp.pubsub.publish (publish messages to Pub/Sub)
# IN: vx.gcp.functions.invoke (invoke Cloud Functions)
#
# Secrets:
# gcp/service_account_json - Service account JSON key file content
# gcp/project_id - GCP project ID
#
# Rate limits: Varies by service (GCS: 5000 writes/s, Pub/Sub: 10000 msg/s)
# Pagination: Service-specific (pageToken parameter)
#
# Authentication: OAuth2 with service account (JWT bearer token)
# API Version: Service-specific (storage/v1, pubsub/v1, etc.)
#
# Note: GCP authentication requires generating JWT tokens from service account.
# This connector demonstrates the structure; actual implementation would need
# a token generation helper or use GCP SDK wrapped in exec-rpc.

driver "http-out"

# Base configuration for Cloud Storage operations
SUBJECT = "vx.gcp.storage.upload"
BASE_URL = "https://storage.googleapis.com/storage/v1"
METHOD = "POST"

# OAuth2 Bearer token authentication
# In production, this would use an exec-rpc wrapper around GCP SDK
# or a token generation service that exchanges service account JWT for access token
HEADERS = {
Authorization: "Bearer ${access_token}",
"Content-Type": "application/json",
"x-goog-project-id": secret("gcp/project_id")
}

# Note: For production use, consider wrapping GCP SDK in exec-rpc connector
# to handle OAuth2 token generation and service-specific APIs properly.
# Service account authentication flow:
# 1. Create JWT from service account JSON
# 2. Exchange JWT for access token at https://oauth2.googleapis.com/token
# 3. Use access token in Authorization header
160 changes: 160 additions & 0 deletions docs/examples/connectors/google-cloud/mock.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#!/usr/bin/env node
// Mock Google Cloud Storage API server for admission testing
// Simulates /storage/v1/b/{bucket}/o endpoint

import http from 'http';

const buckets = {
'my-bucket': {}
};

const server = http.createServer((req, res) => {
// CORS headers
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, DELETE, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Authorization, Content-Type, x-goog-project-id');

if (req.method === 'OPTIONS') {
res.writeHead(200);
res.end();
return;
}

const url = new URL(req.url, `http://${req.headers.host}`);

// POST /upload/storage/v1/b/{bucket}/o - upload object
if (req.method === 'POST' && url.pathname.match(/^\/upload\/storage\/v1\/b\/[^\/]+\/o$/)) {
const bucket = url.pathname.split('/')[5];
const name = url.searchParams.get('name');

if (!buckets[bucket]) {
res.writeHead(404, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
error: {
code: 404,
message: 'Not Found'
}
}));
return;
}

let body = '';
req.on('data', chunk => body += chunk);
req.on('end', () => {
buckets[bucket][name] = body;

const now = new Date().toISOString();
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
kind: 'storage#object',
id: `${bucket}/${name}/${Date.now()}000000`,
selfLink: `https://www.googleapis.com/storage/v1/b/${bucket}/o/${encodeURIComponent(name)}`,
name: name,
bucket: bucket,
generation: `${Date.now()}000000`,
metageneration: '1',
contentType: 'application/octet-stream',
storageClass: 'STANDARD',
size: String(body.length),
md5Hash: Buffer.from(body).toString('base64').substring(0, 24),
crc32c: 'AAAAAA==',
etag: 'CKiG9oDEhvQCEAE=',
timeCreated: now,
updated: now,
timeStorageClassUpdated: now
}));
});
return;
}

// GET /storage/v1/b/{bucket}/o - list objects
if (req.method === 'GET' && url.pathname.match(/^\/storage\/v1\/b\/[^\/]+\/o$/)) {
const bucket = url.pathname.split('/')[4];

if (!buckets[bucket]) {
res.writeHead(404, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
error: {
code: 404,
message: 'Not Found'
}
}));
return;
}

const items = Object.keys(buckets[bucket]).map(name => ({
kind: 'storage#object',
id: `${bucket}/${name}/${Date.now()}000000`,
name: name,
bucket: bucket,
size: String(buckets[bucket][name].length),
updated: new Date().toISOString()
}));

res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
kind: 'storage#objects',
items: items
}));
return;
}

// GET /storage/v1/b/{bucket}/o/{object} - get object metadata
if (req.method === 'GET' && url.pathname.match(/^\/storage\/v1\/b\/[^\/]+\/o\/[^\/]+$/)) {
const parts = url.pathname.split('/');
const bucket = parts[4];
const object = decodeURIComponent(parts[6]);

if (!buckets[bucket] || !buckets[bucket][object]) {
res.writeHead(404, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
error: {
code: 404,
message: 'Not Found'
}
}));
return;
}

const now = new Date().toISOString();
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
kind: 'storage#object',
id: `${bucket}/${object}/${Date.now()}000000`,
name: object,
bucket: bucket,
size: String(buckets[bucket][object].length),
updated: now
}));
return;
}

// DELETE /storage/v1/b/{bucket}/o/{object} - delete object
if (req.method === 'DELETE' && url.pathname.match(/^\/storage\/v1\/b\/[^\/]+\/o\/[^\/]+$/)) {
const parts = url.pathname.split('/');
const bucket = parts[4];
const object = decodeURIComponent(parts[6]);

if (buckets[bucket] && buckets[bucket][object]) {
delete buckets[bucket][object];
}

res.writeHead(204);
res.end();
return;
}

// 404 for unknown endpoints
res.writeHead(404, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
error: {
code: 404,
message: 'Not Found'
}
}));
});

const PORT = process.env.PORT || 8085;
server.listen(PORT, () => {
console.log(`Mock Google Cloud Storage API listening on port ${PORT}`);
});
4 changes: 4 additions & 0 deletions docs/examples/connectors/google-cloud/overrides.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"BASE_URL": "http://localhost:8085/storage/v1",
"SUBJECT": "vx.gcp.test.upload"
}
Loading