From 5389817d47b6f7e9af15581f84b257e72290b864 Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Tue, 9 Sep 2025 05:57:32 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Add=20docstrings=20to=20`feat/ad?= =?UTF-8?q?d-azure-storage-connector`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docstrings generation was requested by @yogeshselvarajan. * https://github.com/SmythOS/sre/pull/126#issuecomment-3268982558 The following files were modified: * `examples/06-Storage-no-agent/03-AzureBlobStorage.ts` --- .../03-AzureBlobStorage.ts | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 examples/06-Storage-no-agent/03-AzureBlobStorage.ts diff --git a/examples/06-Storage-no-agent/03-AzureBlobStorage.ts b/examples/06-Storage-no-agent/03-AzureBlobStorage.ts new file mode 100644 index 000000000..dc68a4b6e --- /dev/null +++ b/examples/06-Storage-no-agent/03-AzureBlobStorage.ts @@ -0,0 +1,56 @@ +import 'dotenv/config'; +import { Storage } from '@smythos/sdk'; + +/** + * Writes a test blob to Azure Blob Storage, reads it back, and verifies the content matches. + * + * Validates AZURE_STORAGE_ACCOUNT_NAME and AZURE_STORAGE_ACCESS_KEY from environment variables and uses + * AZURE_BLOB_CONTAINER_NAME as the target container. If credentials are missing, the function logs an error and returns early. + * + * @returns A promise that resolves when the example completes. + * @throws Error If the read content does not match the written content. + */ +async function main() { + // Ensure environment variables are loaded + if (!process.env.AZURE_STORAGE_ACCOUNT_NAME || !process.env.AZURE_STORAGE_ACCESS_KEY) { + console.error("Error: Missing Azure credentials in your .env file."); + return; + } + + // Initialize the Azure Blob Storage connector with credentials from the .env file + const azureStorage = Storage.AzureBlobStorage({ + storageAccountName: process.env.AZURE_STORAGE_ACCOUNT_NAME, + storageAccountAccessKey: process.env.AZURE_STORAGE_ACCESS_KEY, + blobContainerName: process.env.AZURE_BLOB_CONTAINER_NAME!, + }); + + const resourceId = 'smythos-azure-test.txt'; + const content = 'Hello, world from Azure!'; + + console.log(`=== Running Azure Blob Storage Example ===`); + + // Write a file to your container. + console.log(`Writing "${content}" to "${resourceId}"...`); + await azureStorage.write(resourceId, content); + console.log('Write operation complete.'); + + // Read the file back. + console.log(`Reading "${resourceId}"...`); + const data = await azureStorage.read(resourceId); + console.log('Read operation complete.'); + + // Log the content to verify it's correct. + const dataAsString = data?.toString(); + console.log(`Content read from blob: "${dataAsString}"`); + + if (dataAsString !== content) { + throw new Error("Verification failed: Read content does not match written content!"); + } + + console.log('Verification successful!'); + console.log(`=== Example Finished ===`); +} + +main().catch(error => { + console.error("An error occurred:", error.message); +}); \ No newline at end of file