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
59 changes: 59 additions & 0 deletions docs/examples/connectors/azure/azure.vjs.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# connector: azure — Comprehensive Microsoft Azure API integration
#
# Platform connector for Microsoft Azure. Supports multiple operations:
# - Blob Storage (upload, download, list, delete blobs)
# - Service Bus (send messages, receive messages, queues/topics)
# - Azure Functions (invoke functions, list functions)
# - Event Grid (publish events, create topics)
# - Cosmos DB (CRUD operations on documents)
#
# Uses http-out driver for API calls. Azure requires OAuth2 Azure AD authentication.
# Individual operations use flows that consume from subjects and make direct API calls.
#
# Subjects:
# IN: vx.azure.blob.upload (upload blobs to Blob Storage)
# IN: vx.azure.servicebus.send (send messages to Service Bus)
# IN: vx.azure.functions.invoke (invoke Azure Functions)
#
# Secrets:
# azure/storage_account - Azure Storage account name
# azure/storage_key - Azure Storage account access key
# azure/tenant_id - Azure AD tenant ID
# azure/client_id - Azure AD application (client) ID
# azure/client_secret - Azure AD client secret
#
# Rate limits: Varies by service (Blob Storage: 20000 req/s, Service Bus: varies by tier)
# Pagination: Service-specific (continuation tokens)
#
# Authentication: Shared Key for Storage, OAuth2 Bearer token for other services
# API Version: Service-specific (2021-08-06 for Blob Storage, etc.)
#
# Note: Azure authentication varies by service. Storage uses Shared Key,
# other services use OAuth2 tokens from Azure AD. This connector demonstrates
# the structure; actual implementation would need service-specific auth helpers
# or use Azure SDK wrapped in exec-rpc.

driver "http-out"

# Base configuration for Blob Storage operations
SUBJECT = "vx.azure.blob.upload"
BASE_URL = "https://" + secret("azure/storage_account") + ".blob.core.windows.net"
METHOD = "PUT"

# Shared Key authentication for Blob Storage
# In production, this would use an exec-rpc wrapper around Azure SDK
# or a signing service that generates proper Authorization headers
HEADERS = {
"x-ms-date": "${timestamp}",
"x-ms-version": "2021-08-06",
Authorization: "SharedKey " + secret("azure/storage_account") + ":${signature}",
"x-ms-blob-type": "BlockBlob",
"Content-Type": "application/octet-stream"
}

# Note: For production use, consider wrapping Azure SDK in exec-rpc connector
# to handle OAuth2 token generation and service-specific APIs properly.
# Azure AD authentication flow (for non-storage services):
# 1. POST to https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token
# 2. Use client credentials grant (client_id, client_secret, scope)
# 3. Use access token in Authorization: Bearer header
16 changes: 16 additions & 0 deletions docs/examples/connectors/azure/fixture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"Last-Modified": "Mon, 23 Nov 2026 12:00:00 GMT",
"ETag": "\"0x8DCEB1234567890\"",
"Content-Length": "2048",
"Content-Type": "application/octet-stream",
"x-ms-request-id": "12345678-1234-1234-1234-123456789012",
"x-ms-version": "2021-08-06",
"x-ms-blob-type": "BlockBlob",
"x-ms-lease-status": "unlocked",
"x-ms-lease-state": "available",
"x-ms-server-encrypted": "true",
"Date": "Mon, 23 Nov 2026 12:00:00 GMT",
"Container": "uploads",
"Blob": "document.pdf",
"URL": "https://mystorageaccount.blob.core.windows.net/uploads/document.pdf"
}
168 changes: 168 additions & 0 deletions docs/examples/connectors/azure/mock.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
#!/usr/bin/env node
// Mock Azure Blob Storage API server for admission testing
// Simulates /{container}/{blob} endpoint

import http from 'http';

const containers = {
'uploads': {}
};

const server = http.createServer((req, res) => {
// CORS headers
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, PUT, DELETE, HEAD, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Authorization, x-ms-date, x-ms-version, x-ms-blob-type, Content-Type');

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

const url = new URL(req.url, `http://${req.headers.host}`);
const pathParts = url.pathname.split('/').filter(p => p);

// PUT /{container}/{blob} - upload blob
if (req.method === 'PUT' && pathParts.length >= 2) {
const container = pathParts[0];
const blob = pathParts.slice(1).join('/');

if (!containers[container]) {
res.writeHead(404, { 'Content-Type': 'application/xml' });
res.end(`<?xml version="1.0" encoding="utf-8"?>
<Error>
<Code>ContainerNotFound</Code>
<Message>The specified container does not exist.</Message>
</Error>`);
return;
}

let body = '';
req.on('data', chunk => body += chunk);
req.on('end', () => {
containers[container][blob] = body;

const now = new Date().toUTCString();
res.writeHead(201, {
'Content-Length': '0',
'Last-Modified': now,
'ETag': '"0x8DCEB' + Date.now().toString(16).toUpperCase() + '"',
'x-ms-request-id': '12345678-1234-1234-1234-123456789012',
'x-ms-version': '2021-08-06',
'x-ms-blob-type': 'BlockBlob',
'x-ms-server-encrypted': 'true',
'Date': now
});
res.end();
});
return;
}

// GET /{container}/{blob} - get blob
if (req.method === 'GET' && pathParts.length >= 2) {
const container = pathParts[0];
const blob = pathParts.slice(1).join('/');

if (!containers[container]) {
res.writeHead(404, { 'Content-Type': 'application/xml' });
res.end(`<?xml version="1.0" encoding="utf-8"?>
<Error>
<Code>ContainerNotFound</Code>
<Message>The specified container does not exist.</Message>
</Error>`);
return;
}

if (!containers[container][blob]) {
res.writeHead(404, { 'Content-Type': 'application/xml' });
res.end(`<?xml version="1.0" encoding="utf-8"?>
<Error>
<Code>BlobNotFound</Code>
<Message>The specified blob does not exist.</Message>
</Error>`);
return;
}

const now = new Date().toUTCString();
res.writeHead(200, {
'Content-Type': 'application/octet-stream',
'Content-Length': String(containers[container][blob].length),
'Last-Modified': now,
'ETag': '"0x8DCEB' + Date.now().toString(16).toUpperCase() + '"',
'x-ms-request-id': '12345678-1234-1234-1234-123456789012',
'x-ms-version': '2021-08-06',
'x-ms-blob-type': 'BlockBlob',
'Date': now
});
res.end(containers[container][blob]);
return;
}

// DELETE /{container}/{blob} - delete blob
if (req.method === 'DELETE' && pathParts.length >= 2) {
const container = pathParts[0];
const blob = pathParts.slice(1).join('/');

if (containers[container] && containers[container][blob]) {
delete containers[container][blob];
}

const now = new Date().toUTCString();
res.writeHead(202, {
'x-ms-request-id': '12345678-1234-1234-1234-123456789012',
'x-ms-version': '2021-08-06',
'Date': now
});
res.end();
return;
}

// GET /{container}?restype=container&comp=list - list blobs
if (req.method === 'GET' && pathParts.length === 1 && url.searchParams.get('restype') === 'container' && url.searchParams.get('comp') === 'list') {
const container = pathParts[0];

if (!containers[container]) {
res.writeHead(404, { 'Content-Type': 'application/xml' });
res.end(`<?xml version="1.0" encoding="utf-8"?>
<Error>
<Code>ContainerNotFound</Code>
<Message>The specified container does not exist.</Message>
</Error>`);
return;
}

const blobs = Object.keys(containers[container]).map(name => `
<Blob>
<Name>${name}</Name>
<Properties>
<Last-Modified>${new Date().toUTCString()}</Last-Modified>
<Etag>"0x8DCEB${Date.now().toString(16).toUpperCase()}"</Etag>
<Content-Length>${containers[container][name].length}</Content-Length>
<Content-Type>application/octet-stream</Content-Type>
<BlobType>BlockBlob</BlobType>
</Properties>
</Blob>`).join('');

res.writeHead(200, { 'Content-Type': 'application/xml' });
res.end(`<?xml version="1.0" encoding="utf-8"?>
<EnumerationResults>
<Blobs>${blobs}
</Blobs>
</EnumerationResults>`);
return;
}

// 404 for unknown endpoints
res.writeHead(404, { 'Content-Type': 'application/xml' });
res.end(`<?xml version="1.0" encoding="utf-8"?>
<Error>
<Code>ResourceNotFound</Code>
<Message>The specified resource does not exist.</Message>
</Error>`);
});

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