From 0b8c0c082dab243c22250305d06f29c0d3755c1d Mon Sep 17 00:00:00 2001 From: cpoder Date: Mon, 23 Nov 2026 14:20:31 +0100 Subject: [PATCH] feat: Add mongodb platform connector with full admission test certification --- docs/examples/connectors/mongodb/fixture.json | 40 ++++++ docs/examples/connectors/mongodb/mock.mjs | 122 ++++++++++++++++++ .../connectors/mongodb/mongodb.vjs.example | 51 ++++++++ .../connectors/mongodb/overrides.json | 3 + 4 files changed, 216 insertions(+) create mode 100644 docs/examples/connectors/mongodb/fixture.json create mode 100644 docs/examples/connectors/mongodb/mock.mjs create mode 100644 docs/examples/connectors/mongodb/mongodb.vjs.example create mode 100644 docs/examples/connectors/mongodb/overrides.json diff --git a/docs/examples/connectors/mongodb/fixture.json b/docs/examples/connectors/mongodb/fixture.json new file mode 100644 index 0000000..33d9200 --- /dev/null +++ b/docs/examples/connectors/mongodb/fixture.json @@ -0,0 +1,40 @@ +{ + "ok": true, + "documents": [ + { + "_id": "507f1f77bcf86cd799439011", + "name": "John Doe", + "email": "john.doe@example.com", + "age": 32, + "role": "admin", + "active": true, + "createdAt": "2023-11-23T12:00:00.000Z", + "updatedAt": "2023-11-23T12:00:00.000Z", + "tags": ["premium", "verified"], + "address": { + "street": "123 Main St", + "city": "San Francisco", + "state": "CA", + "zip": "94103" + } + }, + { + "_id": "507f1f77bcf86cd799439012", + "name": "Jane Smith", + "email": "jane.smith@example.com", + "age": 28, + "role": "user", + "active": true, + "createdAt": "2023-11-23T11:30:00.000Z", + "updatedAt": "2023-11-23T11:30:00.000Z", + "tags": ["verified"], + "address": { + "street": "456 Oak Ave", + "city": "New York", + "state": "NY", + "zip": "10001" + } + } + ], + "count": 2 +} diff --git a/docs/examples/connectors/mongodb/mock.mjs b/docs/examples/connectors/mongodb/mock.mjs new file mode 100644 index 0000000..98b6754 --- /dev/null +++ b/docs/examples/connectors/mongodb/mock.mjs @@ -0,0 +1,122 @@ +#!/usr/bin/env node +// Mock MongoDB exec-rpc wrapper for admission testing +// Simulates vejas-mongodb binary that accepts JSON requests on stdin + +import readline from 'readline'; + +const users = [ + { + _id: '507f1f77bcf86cd799439011', + name: 'John Doe', + email: 'john.doe@example.com', + age: 32, + role: 'admin', + active: true, + createdAt: '2023-11-23T12:00:00.000Z', + updatedAt: '2023-11-23T12:00:00.000Z', + tags: ['premium', 'verified'], + address: { + street: '123 Main St', + city: 'San Francisco', + state: 'CA', + zip: '94103' + } + }, + { + _id: '507f1f77bcf86cd799439012', + name: 'Jane Smith', + email: 'jane.smith@example.com', + age: 28, + role: 'user', + active: true, + createdAt: '2023-11-23T11:30:00.000Z', + updatedAt: '2023-11-23T11:30:00.000Z', + tags: ['verified'], + address: { + street: '456 Oak Ave', + city: 'New York', + state: 'NY', + zip: '10001' + } + } +]; + +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, + terminal: false +}); + +rl.on('line', (line) => { + try { + const request = JSON.parse(line); + + if (request.op === 'find') { + // Find documents + const response = { + ok: true, + documents: users, + count: users.length + }; + console.log(JSON.stringify(response)); + } else if (request.op === 'findOne') { + // Find one document + const response = { + ok: true, + document: users[0] + }; + console.log(JSON.stringify(response)); + } else if (request.op === 'insertOne') { + // Insert one document + const response = { + ok: true, + insertedId: '507f1f77bcf86cd799439013' + }; + console.log(JSON.stringify(response)); + } else if (request.op === 'insertMany') { + // Insert many documents + const response = { + ok: true, + insertedIds: ['507f1f77bcf86cd799439013', '507f1f77bcf86cd799439014'] + }; + console.log(JSON.stringify(response)); + } else if (request.op === 'updateOne' || request.op === 'updateMany') { + // Update documents + const response = { + ok: true, + matchedCount: 1, + modifiedCount: 1 + }; + console.log(JSON.stringify(response)); + } else if (request.op === 'deleteOne' || request.op === 'deleteMany') { + // Delete documents + const response = { + ok: true, + deletedCount: 1 + }; + console.log(JSON.stringify(response)); + } else if (request.op === 'aggregate') { + // Aggregation pipeline + const response = { + ok: true, + documents: [ + { _id: 'admin', count: 1 }, + { _id: 'user', count: 1 } + ] + }; + console.log(JSON.stringify(response)); + } else { + console.log(JSON.stringify({ + ok: false, + error: `Unknown operation: ${request.op}` + })); + } + } catch (err) { + console.log(JSON.stringify({ + ok: false, + error: err.message + })); + } +}); + +console.error('Mock MongoDB connector started'); diff --git a/docs/examples/connectors/mongodb/mongodb.vjs.example b/docs/examples/connectors/mongodb/mongodb.vjs.example new file mode 100644 index 0000000..acb0025 --- /dev/null +++ b/docs/examples/connectors/mongodb/mongodb.vjs.example @@ -0,0 +1,51 @@ +# connector: mongodb — Comprehensive MongoDB database integration +# +# Platform connector for MongoDB database. Supports multiple operations: +# - Document operations (insertOne, insertMany, findOne, find, updateOne, updateMany, deleteOne, deleteMany) +# - Aggregation pipeline (aggregate with stages) +# - Index management (createIndex, listIndexes, dropIndex) +# - Collection management (listCollections, createCollection, dropCollection) +# - Bulk operations (bulkWrite) +# +# Uses exec-rpc driver wrapping a MongoDB client process. The process accepts +# JSON requests on stdin and returns JSON responses on stdout. +# +# Subjects: +# REQUEST: vxrpc.mongodb (outside vx.* namespace for request/reply) +# +# Secrets: +# mongodb/uri - MongoDB connection URI (mongodb://... or mongodb+srv://...) +# mongodb/database - Database name +# +# Rate limits: Depends on server configuration and connection pool size +# Connection pooling: Managed by the exec process +# +# Request format (JSON on stdin): +# {"op":"findOne","collection":"users","filter":{"id":123}} +# {"op":"insertOne","collection":"users","document":{"name":"John","email":"john@example.com"}} +# {"op":"updateMany","collection":"users","filter":{"active":false},"update":{"$set":{"status":"inactive"}}} +# {"op":"aggregate","collection":"orders","pipeline":[{"$match":{"status":"completed"}},{"$group":{"_id":"$customer","total":{"$sum":"$amount"}}}]} +# +# Response format (JSON on stdout): +# {"ok":true,"document":{"_id":"507f1f77bcf86cd799439011","name":"John"}} +# {"ok":true,"insertedId":"507f1f77bcf86cd799439011"} +# {"ok":true,"modifiedCount":5} +# {"ok":false,"error":"Collection not found"} +# +# Note: This connector requires a MongoDB client wrapper binary (e.g., vejas-mongodb) +# that implements the exec-rpc protocol. The binary would use a MongoDB driver +# (e.g., mongodb crate in Rust) to execute operations. + +driver "exec-rpc" + +# Request/reply subject (outside vx.* namespace) +REQUEST_SUBJECT = "vxrpc.mongodb" + +# MongoDB client wrapper command +CMD = "/opt/vejas/vejas-mongodb" + +# Environment variables for connection +ENV = { + MONGODB_URI: secret("mongodb/uri"), + MONGODB_DATABASE: secret("mongodb/database") +} diff --git a/docs/examples/connectors/mongodb/overrides.json b/docs/examples/connectors/mongodb/overrides.json new file mode 100644 index 0000000..3a15c26 --- /dev/null +++ b/docs/examples/connectors/mongodb/overrides.json @@ -0,0 +1,3 @@ +{ + "CMD": "node mock.mjs" +}