From 2a5230b523062b7dda0021520b13fc9c3b901896 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Mon, 9 Dec 2019 15:47:34 -0800 Subject: [PATCH 01/39] [storage-file-share] updated samples --- common/scripts/prep-samples.js | 2 +- .../samples/typescript/README.md | 20 +++++----- .../samples/typescript/package.json | 5 ++- .../samples/typescript/run.ts | 38 +++++++++++++++++++ .../samples/typescript/{ => src}/advanced.ts | 20 +++++----- .../typescript/{ => src}/anonymousCred.ts | 18 +++++---- .../samples/typescript/{ => src}/basic.ts | 18 +++++---- .../typescript/{ => src}/customPipeline.ts | 18 +++++---- .../iterators-files-and-directories.ts | 18 +++++---- .../typescript/{ => src}/iterators-handles.ts | 18 +++++---- .../typescript/{ => src}/iterators-shares.ts | 18 +++++---- .../samples/typescript/{ => src}/proxyAuth.ts | 18 +++++---- .../typescript/{ => src}/sharedKeyCred.ts | 18 +++++---- .../typescript/{ => src}/withConnString.ts | 18 +++++---- .../samples/typescript/tsconfig.json | 7 +++- 15 files changed, 159 insertions(+), 95 deletions(-) create mode 100644 sdk/storage/storage-file-share/samples/typescript/run.ts rename sdk/storage/storage-file-share/samples/typescript/{ => src}/advanced.ts (93%) rename sdk/storage/storage-file-share/samples/typescript/{ => src}/anonymousCred.ts (85%) rename sdk/storage/storage-file-share/samples/typescript/{ => src}/basic.ts (93%) rename sdk/storage/storage-file-share/samples/typescript/{ => src}/customPipeline.ts (88%) rename sdk/storage/storage-file-share/samples/typescript/{ => src}/iterators-files-and-directories.ts (96%) rename sdk/storage/storage-file-share/samples/typescript/{ => src}/iterators-handles.ts (95%) rename sdk/storage/storage-file-share/samples/typescript/{ => src}/iterators-shares.ts (93%) rename sdk/storage/storage-file-share/samples/typescript/{ => src}/proxyAuth.ts (87%) rename sdk/storage/storage-file-share/samples/typescript/{ => src}/sharedKeyCred.ts (85%) rename sdk/storage/storage-file-share/samples/typescript/{ => src}/withConnString.ts (87%) diff --git a/common/scripts/prep-samples.js b/common/scripts/prep-samples.js index 77813256b68e..9fbd37e89da1 100644 --- a/common/scripts/prep-samples.js +++ b/common/scripts/prep-samples.js @@ -132,7 +132,7 @@ async function main() { baseDir = process.cwd(); } - const tsDir = path.join(baseDir, "samples", "typescript"); + const tsDir = path.join(baseDir, "samples", "typescript", "src"); const package = require(path.join(baseDir, "package.json")); console.log( diff --git a/sdk/storage/storage-file-share/samples/typescript/README.md b/sdk/storage/storage-file-share/samples/typescript/README.md index acda221d2f6c..c8682a7086d3 100644 --- a/sdk/storage/storage-file-share/samples/typescript/README.md +++ b/sdk/storage/storage-file-share/samples/typescript/README.md @@ -65,16 +65,16 @@ npx cross-env ACCOUNT_NAME="" ACCOUNT_KEY="" node dis Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients. -[basic]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-file-share/samples/typescript/basic.ts -[proxyauth]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-file-share/samples/typescript/proxyAuth.ts -[withconnstring]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-file-share/samples/typescript/withConnString.ts -[iterators-files-and-directories]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-file-share/samples/typescript/iterators-files-and-directories.ts -[sharedkeycred]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-file-share/samples/typescript/sharedKeyCred.ts -[anonymouscred]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-file-share/samples/typescript/anonymousCred.ts -[iterators-handles]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-file-share/samples/typescript/iterators-handles.ts -[custompipeline]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-file-share/samples/typescript/customPipeline.ts -[advanced]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-file-share/samples/typescript/advanced.ts -[iterators-shares]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-file-share/samples/typescript/iterators-shares.ts +[basic]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-file-share/samples/typescript/src/basic.ts +[proxyauth]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts +[withconnstring]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-file-share/samples/typescript/src/withConnString.ts +[iterators-files-and-directories]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-file-share/samples/typescript/src/iterators-files-and-directories.ts +[sharedkeycred]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-file-share/samples/typescript/src/sharedKeyCred.ts +[anonymouscred]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-file-share/samples/typescript/src/anonymousCred.ts +[iterators-handles]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts +[custompipeline]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-file-share/samples/typescript/src/customPipeline.ts +[advanced]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-file-share/samples/typescript/src/advanced.ts +[iterators-shares]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-file-share/samples/typescript/src/iterators-shares.ts [apiref]: https://docs.microsoft.com/javascript/api/@azure/storage-file-share [azstorage]: https://docs.microsoft.com/azure/storage/common/storage-account-overview [freesub]: https://azure.microsoft.com/free/ diff --git a/sdk/storage/storage-file-share/samples/typescript/package.json b/sdk/storage/storage-file-share/samples/typescript/package.json index 295096d98ba0..d14c49e0f6c9 100644 --- a/sdk/storage/storage-file-share/samples/typescript/package.json +++ b/sdk/storage/storage-file-share/samples/typescript/package.json @@ -8,7 +8,8 @@ }, "scripts": { "build": "tsc", - "prebuild": "rimraf dist/" + "prebuild": "rimraf dist/", + "run:all": "cross-env BATCH_SAMPLES=true ts-node run.ts" }, "repository": { "type": "git", @@ -34,7 +35,9 @@ }, "devDependencies": { "@types/node": "^8.0.0", + "cross-env": "^6.0.3", "rimraf": "^3.0.0", + "ts-node": "^8.3.0", "typescript": "~3.6.4" } } diff --git a/sdk/storage/storage-file-share/samples/typescript/run.ts b/sdk/storage/storage-file-share/samples/typescript/run.ts new file mode 100644 index 000000000000..b5c9a2ffa7a7 --- /dev/null +++ b/sdk/storage/storage-file-share/samples/typescript/run.ts @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { main as advancedMain } from "./dist/advanced"; +import { main as anonymousCredMain } from "./dist/anonymousCred"; +import { main as basicMain } from "./dist/basic"; +import { main as customPipelineMain } from "./dist/customPipeline"; +import { main as iteratorsFilesAndDirectoriesMain } from "./dist/iterators-files-and-directories"; +// import { main as iteratorsHandlesMain } from "./dist/iterators-handles"; +import { main as iteratorsSharesMain } from "./dist/iterators-shares"; +// import { main as proxyAuthMain } from "./dist/proxyAuth"; +import { main as sharedKeyCredMain } from "./dist/sharedKeyCred"; +import { main as withConnStringMain } from "./dist/withConnString"; + +const samples: Array<[string, () => Promise]> = [ + ["advanced", advancedMain], + ["anonymousCred", anonymousCredMain], + ["basic", basicMain], + ["customPipeline", customPipelineMain], + ["iterators-files-and-directories", iteratorsFilesAndDirectoriesMain], + // ["iterators-handles", iteratorsHandlesMain], + ["iterators-shares", iteratorsSharesMain], + // ["proxyAuth", proxyAuthMain], + ["sharedKeyCred", sharedKeyCredMain], + ["withConnString", withConnStringMain] +]; + +async function main() { + for (let [sampleName, sampleMain] of samples) { + console.log("[samples] Running sample", sampleName); + await sampleMain(); + } +} + +main().catch((error) => { + console.error("[samples] An error occurred:", error); + process.exit(1); +}); diff --git a/sdk/storage/storage-file-share/samples/typescript/advanced.ts b/sdk/storage/storage-file-share/samples/typescript/src/advanced.ts similarity index 93% rename from sdk/storage/storage-file-share/samples/typescript/advanced.ts rename to sdk/storage/storage-file-share/samples/typescript/src/advanced.ts index b430f6713667..aaae3649f3fa 100644 --- a/sdk/storage/storage-file-share/samples/typescript/advanced.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/advanced.ts @@ -2,11 +2,11 @@ Setup: Enter your storage account name, SAS and a path pointing to local file in main() */ -import fs from "fs"; +import * as fs from "fs"; import { AbortController } from "@azure/abort-controller"; import { AnonymousCredential, ShareServiceClient, newPipeline } from "@azure/storage-file-share"; -async function main() { +export async function main() { // Fill in following settings before running this sample const account = process.env.ACCOUNT_NAME || ""; const accountSas = process.env.ACCOUNT_SAS || ""; @@ -89,10 +89,12 @@ async function main() { } // An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +if (!process.env["BATCH_SAMPLES"]) { + main() + .then(() => { + console.log("Successfully executed sample."); + }) + .catch((err) => { + console.log(err.message); + }); +} diff --git a/sdk/storage/storage-file-share/samples/typescript/anonymousCred.ts b/sdk/storage/storage-file-share/samples/typescript/src/anonymousCred.ts similarity index 85% rename from sdk/storage/storage-file-share/samples/typescript/anonymousCred.ts rename to sdk/storage/storage-file-share/samples/typescript/src/anonymousCred.ts index 8ae5342a6e60..ef69f1f47571 100644 --- a/sdk/storage/storage-file-share/samples/typescript/anonymousCred.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/anonymousCred.ts @@ -4,7 +4,7 @@ import { ShareServiceClient, AnonymousCredential } from "@azure/storage-file-share"; -async function main() { +export async function main() { // Enter your storage account name and SAS const account = process.env.ACCOUNT_NAME || ""; const accountSas = process.env.ACCOUNT_SAS || ""; @@ -37,10 +37,12 @@ async function main() { } // An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +if (!process.env["BATCH_SAMPLES"]) { + main() + .then(() => { + console.log("Successfully executed sample."); + }) + .catch((err) => { + console.log(err.message); + }); +} diff --git a/sdk/storage/storage-file-share/samples/typescript/basic.ts b/sdk/storage/storage-file-share/samples/typescript/src/basic.ts similarity index 93% rename from sdk/storage/storage-file-share/samples/typescript/basic.ts rename to sdk/storage/storage-file-share/samples/typescript/src/basic.ts index 0206878e81e6..c94079d556c0 100644 --- a/sdk/storage/storage-file-share/samples/typescript/basic.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/basic.ts @@ -4,7 +4,7 @@ import { ShareServiceClient, StorageSharedKeyCredential } from "@azure/storage-file-share"; -async function main() { +export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; @@ -91,10 +91,12 @@ async function streamToString(readableStream: NodeJS.ReadableStream) { } // An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +if (!process.env["BATCH_SAMPLES"]) { + main() + .then(() => { + console.log("Successfully executed sample."); + }) + .catch((err) => { + console.log(err.message); + }); +} diff --git a/sdk/storage/storage-file-share/samples/typescript/customPipeline.ts b/sdk/storage/storage-file-share/samples/typescript/src/customPipeline.ts similarity index 88% rename from sdk/storage/storage-file-share/samples/typescript/customPipeline.ts rename to sdk/storage/storage-file-share/samples/typescript/src/customPipeline.ts index ee8bf0b0d880..b20ee3bd1537 100644 --- a/sdk/storage/storage-file-share/samples/typescript/customPipeline.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/customPipeline.ts @@ -8,7 +8,7 @@ import { StorageSharedKeyCredential } from "@azure/storage-file-share"; -async function main() { +export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; @@ -48,10 +48,12 @@ async function main() { } // An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +if (!process.env["BATCH_SAMPLES"]) { + main() + .then(() => { + console.log("Successfully executed sample."); + }) + .catch((err) => { + console.log(err.message); + }); +} diff --git a/sdk/storage/storage-file-share/samples/typescript/iterators-files-and-directories.ts b/sdk/storage/storage-file-share/samples/typescript/src/iterators-files-and-directories.ts similarity index 96% rename from sdk/storage/storage-file-share/samples/typescript/iterators-files-and-directories.ts rename to sdk/storage/storage-file-share/samples/typescript/src/iterators-files-and-directories.ts index 10741181a4b7..2f050ea22b75 100644 --- a/sdk/storage/storage-file-share/samples/typescript/iterators-files-and-directories.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/iterators-files-and-directories.ts @@ -4,7 +4,7 @@ import { ShareServiceClient, StorageSharedKeyCredential } from "@azure/storage-file-share"; -async function main() { +export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; @@ -158,10 +158,12 @@ async function main() { } // An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +if (!process.env["BATCH_SAMPLES"]) { + main() + .then(() => { + console.log("Successfully executed sample."); + }) + .catch((err) => { + console.log(err.message); + }); +} diff --git a/sdk/storage/storage-file-share/samples/typescript/iterators-handles.ts b/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts similarity index 95% rename from sdk/storage/storage-file-share/samples/typescript/iterators-handles.ts rename to sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts index 9671d418b4a6..78f446775d66 100644 --- a/sdk/storage/storage-file-share/samples/typescript/iterators-handles.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts @@ -4,7 +4,7 @@ import { ShareServiceClient, StorageSharedKeyCredential } from "@azure/storage-file-share"; -async function main() { +export async function main() { // Enter your storage account name, shared key, share name, and directory name. // Please ensure your directory is mounted // https://docs.microsoft.com/en-us/azure/storage/files/storage-how-to-use-files-windows @@ -151,10 +151,12 @@ async function main() { } // An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +if (!process.env["BATCH_SAMPLES"]) { + main() + .then(() => { + console.log("Successfully executed sample."); + }) + .catch((err) => { + console.log(err.message); + }); +} diff --git a/sdk/storage/storage-file-share/samples/typescript/iterators-shares.ts b/sdk/storage/storage-file-share/samples/typescript/src/iterators-shares.ts similarity index 93% rename from sdk/storage/storage-file-share/samples/typescript/iterators-shares.ts rename to sdk/storage/storage-file-share/samples/typescript/src/iterators-shares.ts index 7bd7f80908df..ed52312f97ec 100644 --- a/sdk/storage/storage-file-share/samples/typescript/iterators-shares.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/iterators-shares.ts @@ -4,7 +4,7 @@ import { ShareServiceClient, StorageSharedKeyCredential } from "@azure/storage-file-share"; -async function main() { +export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; @@ -103,10 +103,12 @@ async function main() { } // An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +if (!process.env["BATCH_SAMPLES"]) { + main() + .then(() => { + console.log("Successfully executed sample."); + }) + .catch((err) => { + console.log(err.message); + }); +} diff --git a/sdk/storage/storage-file-share/samples/typescript/proxyAuth.ts b/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts similarity index 87% rename from sdk/storage/storage-file-share/samples/typescript/proxyAuth.ts rename to sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts index ee67036c2793..86ba0d99ad56 100644 --- a/sdk/storage/storage-file-share/samples/typescript/proxyAuth.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts @@ -4,7 +4,7 @@ import { StorageSharedKeyCredential, ShareServiceClient } from "@azure/storage-file-share"; -async function main() { +export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; @@ -42,10 +42,12 @@ async function main() { } // An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed the sample."); - }) - .catch((err) => { - console.log(err.message); - }); +if (!process.env["BATCH_SAMPLES"]) { + main() + .then(() => { + console.log("Successfully executed the sample."); + }) + .catch((err) => { + console.log(err.message); + }); +} diff --git a/sdk/storage/storage-file-share/samples/typescript/sharedKeyCred.ts b/sdk/storage/storage-file-share/samples/typescript/src/sharedKeyCred.ts similarity index 85% rename from sdk/storage/storage-file-share/samples/typescript/sharedKeyCred.ts rename to sdk/storage/storage-file-share/samples/typescript/src/sharedKeyCred.ts index 09e478a223e3..42280de8e76a 100644 --- a/sdk/storage/storage-file-share/samples/typescript/sharedKeyCred.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/sharedKeyCred.ts @@ -4,7 +4,7 @@ import { ShareServiceClient, StorageSharedKeyCredential } from "@azure/storage-file-share"; -async function main() { +export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; @@ -37,10 +37,12 @@ async function main() { } // An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +if (!process.env["BATCH_SAMPLES"]) { + main() + .then(() => { + console.log("Successfully executed sample."); + }) + .catch((err) => { + console.log(err.message); + }); +} diff --git a/sdk/storage/storage-file-share/samples/typescript/withConnString.ts b/sdk/storage/storage-file-share/samples/typescript/src/withConnString.ts similarity index 87% rename from sdk/storage/storage-file-share/samples/typescript/withConnString.ts rename to sdk/storage/storage-file-share/samples/typescript/src/withConnString.ts index 006f6fc1996e..1fb6250c2677 100644 --- a/sdk/storage/storage-file-share/samples/typescript/withConnString.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/withConnString.ts @@ -4,7 +4,7 @@ import { ShareServiceClient } from "@azure/storage-file-share"; -async function main() { +export async function main() { // Create File Service Client from Account connection string or SAS connection string // Account connection string example - `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net` // SAS connection string example - `BlobEndpoint=https://myaccount.blob.core.windows.net/;QueueEndpoint=https://myaccount.queue.core.windows.net/;FileEndpoint=https://myaccount.file.core.windows.net/;TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sasString` @@ -30,10 +30,12 @@ async function main() { } // An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +if (!process.env["BATCH_SAMPLES"]) { + main() + .then(() => { + console.log("Successfully executed sample."); + }) + .catch((err) => { + console.log(err.message); + }); +} diff --git a/sdk/storage/storage-file-share/samples/typescript/tsconfig.json b/sdk/storage/storage-file-share/samples/typescript/tsconfig.json index 639c5d296a23..4332663bf7b7 100644 --- a/sdk/storage/storage-file-share/samples/typescript/tsconfig.json +++ b/sdk/storage/storage-file-share/samples/typescript/tsconfig.json @@ -7,6 +7,9 @@ "allowSyntheticDefaultImports": true, - "outDir": "dist" - } + "outDir": "dist", + "rootDir": "src" + }, + "include": ["src/**.ts"], + "exclude": ["node_modules"] } From dd98eb2af683a50896e37dccbbe3e2af398cc7c5 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Tue, 10 Dec 2019 12:32:35 -0800 Subject: [PATCH 02/39] [prep-samples] allow files that don't have a matching import and just skip them --- common/scripts/prep-samples.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/scripts/prep-samples.js b/common/scripts/prep-samples.js index 9fbd37e89da1..2059c843d694 100644 --- a/common/scripts/prep-samples.js +++ b/common/scripts/prep-samples.js @@ -101,7 +101,12 @@ async function enableLocalRun(fileName, baseDir, pkgName) { ); if (!importRegex.exec(fileContents)) { - throw new Error(`Sample ${fileName} did not contain an import statement!`); + // With the newer methods of using helper files and batch running, this + // should be a warning + console.warn( + `[prep-samples] skipping ${fileName} because it did not contain a matching import` + ); + return; } const relativeDir = path.dirname(fileName.replace(baseDir, "")); From 2fe35d96cdbbd41a6b5b2e2392215be2c5f5190b Mon Sep 17 00:00:00 2001 From: Will Temple Date: Tue, 10 Dec 2019 12:58:30 -0800 Subject: [PATCH 03/39] [storage-file-share] typescript samples in shape --- .../samples/typescript/package.json | 2 +- .../samples/typescript/run.ts | 38 ------------------- .../samples/typescript/src/advanced.ts | 18 ++++----- .../samples/typescript/src/anonymousCred.ts | 18 ++++----- .../samples/typescript/src/basic.ts | 18 ++++----- .../samples/typescript/src/customPipeline.ts | 18 ++++----- .../src/iterators-files-and-directories.ts | 18 ++++----- .../typescript/src/iterators-handles.ts | 18 ++++----- .../typescript/src/iterators-shares.ts | 18 ++++----- .../samples/typescript/src/proxyAuth.ts | 18 ++++----- .../samples/typescript/src/run.ts | 38 +++++++++++++++++++ .../samples/typescript/src/sampleHelpers.ts | 10 +++++ .../samples/typescript/src/sharedKeyCred.ts | 18 ++++----- .../samples/typescript/src/withConnString.ts | 18 ++++----- 14 files changed, 129 insertions(+), 139 deletions(-) delete mode 100644 sdk/storage/storage-file-share/samples/typescript/run.ts create mode 100644 sdk/storage/storage-file-share/samples/typescript/src/run.ts create mode 100644 sdk/storage/storage-file-share/samples/typescript/src/sampleHelpers.ts diff --git a/sdk/storage/storage-file-share/samples/typescript/package.json b/sdk/storage/storage-file-share/samples/typescript/package.json index d14c49e0f6c9..efeb194d6963 100644 --- a/sdk/storage/storage-file-share/samples/typescript/package.json +++ b/sdk/storage/storage-file-share/samples/typescript/package.json @@ -9,7 +9,7 @@ "scripts": { "build": "tsc", "prebuild": "rimraf dist/", - "run:all": "cross-env BATCH_SAMPLES=true ts-node run.ts" + "execute:all": "npm run build && cross-env BATCH_RUN_SAMPLES=true node dist/run.js" }, "repository": { "type": "git", diff --git a/sdk/storage/storage-file-share/samples/typescript/run.ts b/sdk/storage/storage-file-share/samples/typescript/run.ts deleted file mode 100644 index b5c9a2ffa7a7..000000000000 --- a/sdk/storage/storage-file-share/samples/typescript/run.ts +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -import { main as advancedMain } from "./dist/advanced"; -import { main as anonymousCredMain } from "./dist/anonymousCred"; -import { main as basicMain } from "./dist/basic"; -import { main as customPipelineMain } from "./dist/customPipeline"; -import { main as iteratorsFilesAndDirectoriesMain } from "./dist/iterators-files-and-directories"; -// import { main as iteratorsHandlesMain } from "./dist/iterators-handles"; -import { main as iteratorsSharesMain } from "./dist/iterators-shares"; -// import { main as proxyAuthMain } from "./dist/proxyAuth"; -import { main as sharedKeyCredMain } from "./dist/sharedKeyCred"; -import { main as withConnStringMain } from "./dist/withConnString"; - -const samples: Array<[string, () => Promise]> = [ - ["advanced", advancedMain], - ["anonymousCred", anonymousCredMain], - ["basic", basicMain], - ["customPipeline", customPipelineMain], - ["iterators-files-and-directories", iteratorsFilesAndDirectoriesMain], - // ["iterators-handles", iteratorsHandlesMain], - ["iterators-shares", iteratorsSharesMain], - // ["proxyAuth", proxyAuthMain], - ["sharedKeyCred", sharedKeyCredMain], - ["withConnString", withConnStringMain] -]; - -async function main() { - for (let [sampleName, sampleMain] of samples) { - console.log("[samples] Running sample", sampleName); - await sampleMain(); - } -} - -main().catch((error) => { - console.error("[samples] An error occurred:", error); - process.exit(1); -}); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/advanced.ts b/sdk/storage/storage-file-share/samples/typescript/src/advanced.ts index aaae3649f3fa..a577182c1fde 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/advanced.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/advanced.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name, SAS and a path pointing to local file in main() */ @@ -6,6 +9,8 @@ import * as fs from "fs"; import { AbortController } from "@azure/abort-controller"; import { AnonymousCredential, ShareServiceClient, newPipeline } from "@azure/storage-file-share"; +import { runSample } from "./sampleHelpers"; + export async function main() { // Fill in following settings before running this sample const account = process.env.ACCOUNT_NAME || ""; @@ -88,13 +93,6 @@ export async function main() { console.log("deleted share"); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -if (!process.env["BATCH_SAMPLES"]) { - main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); -} +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/anonymousCred.ts b/sdk/storage/storage-file-share/samples/typescript/src/anonymousCred.ts index ef69f1f47571..8d54a363e06a 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/anonymousCred.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/anonymousCred.ts @@ -1,9 +1,14 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and SAS in main() */ import { ShareServiceClient, AnonymousCredential } from "@azure/storage-file-share"; +import { runSample } from "./sampleHelpers"; + export async function main() { // Enter your storage account name and SAS const account = process.env.ACCOUNT_NAME || ""; @@ -36,13 +41,6 @@ export async function main() { console.log(`deleted share ${shareName}`); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -if (!process.env["BATCH_SAMPLES"]) { - main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); -} +runSample(main).catch((err) => { + console.log(err.message); +}); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/basic.ts b/sdk/storage/storage-file-share/samples/typescript/src/basic.ts index c94079d556c0..2411db606e71 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/basic.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/basic.ts @@ -1,9 +1,14 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ import { ShareServiceClient, StorageSharedKeyCredential } from "@azure/storage-file-share"; +import { runSample } from "./sampleHelpers"; + export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -90,13 +95,6 @@ async function streamToString(readableStream: NodeJS.ReadableStream) { }); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -if (!process.env["BATCH_SAMPLES"]) { - main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); -} +runSample(main).catch((err) => { + console.log(err.message); +}); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/customPipeline.ts b/sdk/storage/storage-file-share/samples/typescript/src/customPipeline.ts index b20ee3bd1537..f0f35fa3f205 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/customPipeline.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/customPipeline.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ @@ -8,6 +11,8 @@ import { StorageSharedKeyCredential } from "@azure/storage-file-share"; +import { runSample } from "./sampleHelpers"; + export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -47,13 +52,6 @@ export async function main() { console.log(`deleted share ${shareName}`); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -if (!process.env["BATCH_SAMPLES"]) { - main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); -} +runSample(main).catch((err) => { + console.log(err.message); +}); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/iterators-files-and-directories.ts b/sdk/storage/storage-file-share/samples/typescript/src/iterators-files-and-directories.ts index 2f050ea22b75..e117d6edc08d 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/iterators-files-and-directories.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/iterators-files-and-directories.ts @@ -1,9 +1,14 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ import { ShareServiceClient, StorageSharedKeyCredential } from "@azure/storage-file-share"; +import { runSample } from "./sampleHelpers"; + export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -157,13 +162,6 @@ export async function main() { console.log(`deleted share ${shareName}`); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -if (!process.env["BATCH_SAMPLES"]) { - main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); -} +runSample(main).catch((err) => { + console.log(err.message); +}); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts b/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts index 78f446775d66..1195547e0428 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts @@ -1,9 +1,14 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ import { ShareServiceClient, StorageSharedKeyCredential } from "@azure/storage-file-share"; +import { runSample } from "./sampleHelpers"; + export async function main() { // Enter your storage account name, shared key, share name, and directory name. // Please ensure your directory is mounted @@ -150,13 +155,6 @@ export async function main() { } } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -if (!process.env["BATCH_SAMPLES"]) { - main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); -} +runSample(main).catch((err) => { + console.log(err.message); +}); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/iterators-shares.ts b/sdk/storage/storage-file-share/samples/typescript/src/iterators-shares.ts index ed52312f97ec..91227a58d616 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/iterators-shares.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/iterators-shares.ts @@ -1,9 +1,14 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ import { ShareServiceClient, StorageSharedKeyCredential } from "@azure/storage-file-share"; +import { runSample } from "./sampleHelpers"; + export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -102,13 +107,6 @@ export async function main() { } } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -if (!process.env["BATCH_SAMPLES"]) { - main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); -} +runSample(main).catch((err) => { + console.log(err.message); +}); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts b/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts index 86ba0d99ad56..b84f9509c156 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts @@ -1,9 +1,14 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ import { StorageSharedKeyCredential, ShareServiceClient } from "@azure/storage-file-share"; +import { runSample } from "./sampleHelpers"; + export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -41,13 +46,6 @@ export async function main() { console.log(`deleted share ${shareName}`); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -if (!process.env["BATCH_SAMPLES"]) { - main() - .then(() => { - console.log("Successfully executed the sample."); - }) - .catch((err) => { - console.log(err.message); - }); -} +runSample(main).catch((err) => { + console.log(err.message); +}); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/run.ts b/sdk/storage/storage-file-share/samples/typescript/src/run.ts new file mode 100644 index 000000000000..417a9bdf9973 --- /dev/null +++ b/sdk/storage/storage-file-share/samples/typescript/src/run.ts @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { main as advancedMain } from "./advanced"; +import { main as anonymousCredMain } from "./anonymousCred"; +import { main as basicMain } from "./basic"; +import { main as customPipelineMain } from "./customPipeline"; +import { main as iteratorsFilesAndDirectoriesMain } from "./iterators-files-and-directories"; +// import { main as iteratorsHandlesMain } from "./iterators-handles"; +import { main as iteratorsSharesMain } from "./iterators-shares"; +// import { main as proxyAuthMain } from "./proxyAuth"; +import { main as sharedKeyCredMain } from "./sharedKeyCred"; +import { main as withConnStringMain } from "./withConnString"; + +const samples: Array<[string, () => Promise]> = [ + ["advanced", advancedMain], + ["anonymousCred", anonymousCredMain], + ["basic", basicMain], + ["customPipeline", customPipelineMain], + ["iterators-files-and-directories", iteratorsFilesAndDirectoriesMain], + // ["iterators-handles", iteratorsHandlesMain], // Must be populated with a pre-existing share/directory name to run + ["iterators-shares", iteratorsSharesMain], + // ["proxyAuth", proxyAuthMain], // Requires a proxy + ["sharedKeyCred", sharedKeyCredMain], + ["withConnString", withConnStringMain] +]; + +async function main() { + for (let [sampleName, sampleMain] of samples) { + console.log("[samples] Running sample", sampleName); + await sampleMain(); + } +} + +main().catch((error) => { + console.error("[samples] An error occurred:", error); + process.exit(1); +}); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/sampleHelpers.ts b/sdk/storage/storage-file-share/samples/typescript/src/sampleHelpers.ts new file mode 100644 index 000000000000..3cd362525b38 --- /dev/null +++ b/sdk/storage/storage-file-share/samples/typescript/src/sampleHelpers.ts @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +export function runSample(sampleMain: () => Promise) { + if (!process.env["BATCH_RUN_SAMPLES"]) { + return sampleMain(); + } else { + return Promise.resolve(); + } +} diff --git a/sdk/storage/storage-file-share/samples/typescript/src/sharedKeyCred.ts b/sdk/storage/storage-file-share/samples/typescript/src/sharedKeyCred.ts index 42280de8e76a..9d7f81194faa 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/sharedKeyCred.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/sharedKeyCred.ts @@ -1,9 +1,14 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ import { ShareServiceClient, StorageSharedKeyCredential } from "@azure/storage-file-share"; +import { runSample } from "./sampleHelpers"; + export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -36,13 +41,6 @@ export async function main() { console.log(`deleted share ${shareName}`); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -if (!process.env["BATCH_SAMPLES"]) { - main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); -} +runSample(main).catch((err) => { + console.log(err.message); +}); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/withConnString.ts b/sdk/storage/storage-file-share/samples/typescript/src/withConnString.ts index 1fb6250c2677..84a552761c18 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/withConnString.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/withConnString.ts @@ -1,9 +1,14 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ import { ShareServiceClient } from "@azure/storage-file-share"; +import { runSample } from "./sampleHelpers"; + export async function main() { // Create File Service Client from Account connection string or SAS connection string // Account connection string example - `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net` @@ -29,13 +34,6 @@ export async function main() { console.log(`deleted share ${shareName}`); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -if (!process.env["BATCH_SAMPLES"]) { - main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); -} +runSample(main).catch((err) => { + console.log(err.message); +}); From 0d68724335310183a1988fde5c21fc50aff413c2 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Tue, 10 Dec 2019 13:21:18 -0800 Subject: [PATCH 04/39] [storage-file-share] made clean samples step clean up package locks if they exist --- sdk/storage/storage-file-share/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/storage/storage-file-share/package.json b/sdk/storage/storage-file-share/package.json index c318ce500e48..564596fa715c 100644 --- a/sdk/storage/storage-file-share/package.json +++ b/sdk/storage/storage-file-share/package.json @@ -29,7 +29,7 @@ "build": "npm run build:es6 && npm run build:nodebrowser && api-extractor run --local", "check-format": "prettier --list-different --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", "clean": "rimraf dist dist-esm dist-test typings temp browser/*.js* browser/*.zip statistics.html coverage coverage-browser .nyc_output *.tgz *.log test*.xml TEST*.xml", - "clean:samples": "rimraf samples/javascript/node_modules samples/typescript/node_modules samples/typescript/dist", + "clean:samples": "rimraf samples/javascript/node_modules samples/typescript/node_modules samples/typescript/dist samples/typescript/package-lock.json samples/javascript/package-lock.json", "extract-api": "tsc -p . && api-extractor run --local", "execute:samples": "echo skipped for now due to https://github.com/Azure/azure-sdk-for-js/issues/6362", "format": "prettier --write --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", From 72e49cba7f244465deaa892c507bbe27d7264006 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Tue, 10 Dec 2019 14:01:49 -0800 Subject: [PATCH 05/39] [prep-samples] added support for javascript samples --- common/scripts/prep-samples.js | 57 ++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/common/scripts/prep-samples.js b/common/scripts/prep-samples.js index 2059c843d694..3db3d6921533 100644 --- a/common/scripts/prep-samples.js +++ b/common/scripts/prep-samples.js @@ -42,9 +42,10 @@ const fs = * Breadth-first search for files ending in .ts, starting from `tsDir` * * @param {string} tsDir The root of the sample tree to search + * @param {(fs.Entry) => boolean} Predicate that decides whether or not a file entry is included * @returns */ -async function* findAllTsFiles(tsDir) { +async function* findMatchingFiles(tsDir, matches) { const initialFiles = await fs.readdir(tsDir, { withFileTypes: true }); // BFS Queue and queue index @@ -61,11 +62,7 @@ async function* findAllTsFiles(tsDir) { for (const child of children) { q.push([child, fullPath]); } - } else if ( - entry.isFile() && - entry.name.endsWith(".ts") && - !entry.name.endsWith(".d.ts") - ) { + } else if (matches(entry)) { yield fullPath; } else if ( entry.isBlockDevice() || @@ -87,24 +84,24 @@ async function* findAllTsFiles(tsDir) { } /** - * Replaces package imports with relative imports for CI + * Replaces package require/import statements with relative pathsfor CI * - * @param {string} file the name of the file to open and process - * @param {string} baseDir The base directory of the package + * @param {string} fileName the name of the file to open and process + * @param {string} baseDir the base directory of the package * @param {string} pkgName name of the package to use when looking for package-local imports */ async function enableLocalRun(fileName, baseDir, pkgName) { const fileContents = await fs.readFile(fileName, { encoding: "utf-8" }); - const importRegex = new RegExp( - `import\\s+(.*)\\s+from\\s+"${pkgName}";?\\s?`, - "s" - ); + const isTs = fileName.endsWith(".ts"); + const importRegex = isTs + ? new RegExp(`import\\s+(.*)\\s+from\\s+"${pkgName}";?\\s?`, "s") + : new RegExp(`const\\s+(.*)\\s*=\\s*require\\("${pkgName}"\\);?\\s?`, "s"); if (!importRegex.exec(fileContents)) { // With the newer methods of using helper files and batch running, this // should be a warning console.warn( - `[prep-samples] skipping ${fileName} because it did not contain a matching import` + `[prep-samples] skipping ${fileName} because it did not contain a matching import/require` ); return; } @@ -117,10 +114,18 @@ async function enableLocalRun(fileName, baseDir, pkgName) { const depth = relativeDir.length - relativeDir.split(path.sep).join("").length; - const relativeImportPath = new Array(depth).fill("..").join("/") + "/src"; + let relativePath = new Array(depth).fill("..").join("/"); + + if (isTs) { + // TypeScript imports should use src directly + relativePath += "/src"; + } + const updatedContents = fileContents.replace( importRegex, - `import $1 from "${relativeImportPath}";` + isTs + ? `import $1 from "${relativePath}";` + : `const $1 = require("${relativePath}");` ); return fs.writeFile(fileName, updatedContents, { encoding: "utf-8" }); @@ -137,15 +142,29 @@ async function main() { baseDir = process.cwd(); } - const tsDir = path.join(baseDir, "samples", "typescript", "src"); const package = require(path.join(baseDir, "package.json")); - console.log( "[prep-samples] Preparing samples for package:", `${package.name}@${package.version}` ); - for await (const fileName of findAllTsFiles(tsDir)) { + const tsDir = path.join(baseDir, "samples", "typescript", "src"); + for await (const fileName of findMatchingFiles( + tsDir, + entry => + entry.isFile() && + entry.name.endsWith(".ts") && + !entry.name.endsWith(".d.ts") + )) { + console.log("[prep-samples] Updating imports in", fileName); + await enableLocalRun(fileName, baseDir, package.name); + } + + const jsDir = path.join(baseDir, "samples", "javascript"); + for await (const fileName of findMatchingFiles( + jsDir, + entry => entry.isFile() && entry.name.endsWith(".js") + )) { console.log("[prep-samples] Updating imports in", fileName); await enableLocalRun(fileName, baseDir, package.name); } From adb764c249fe8f557deec4f631df52ab06794667 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Tue, 10 Dec 2019 14:49:49 -0800 Subject: [PATCH 06/39] [storage-file-share] Added dotenv and updated instructions --- .../samples/typescript/README.md | 22 +++++++++++++++---- .../samples/typescript/package.json | 5 +++-- .../samples/typescript/sample.env | 9 ++++++++ .../samples/typescript/src/anonymousCred.ts | 2 +- .../samples/typescript/src/basic.ts | 2 +- .../samples/typescript/src/customPipeline.ts | 2 +- .../src/iterators-files-and-directories.ts | 2 +- .../typescript/src/iterators-handles.ts | 2 +- .../typescript/src/iterators-shares.ts | 2 +- .../samples/typescript/src/proxyAuth.ts | 2 +- .../samples/typescript/src/run.ts | 3 +++ .../samples/typescript/src/sampleHelpers.ts | 5 ++++- .../samples/typescript/src/sharedKeyCred.ts | 2 +- .../samples/typescript/src/withConnString.ts | 2 +- 14 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 sdk/storage/storage-file-share/samples/typescript/sample.env diff --git a/sdk/storage/storage-file-share/samples/typescript/README.md b/sdk/storage/storage-file-share/samples/typescript/README.md index c8682a7086d3..6bb9aa52bf0f 100644 --- a/sdk/storage/storage-file-share/samples/typescript/README.md +++ b/sdk/storage/storage-file-share/samples/typescript/README.md @@ -18,10 +18,10 @@ These sample programs show how to use the TypeScript client libraries for Azure | [withConnString.ts][withconnstring] | connect to and authenticate with the service using a connection string | | [sharedKeyCred.ts][sharedkeycred] | authenticate with the service using an account name and a shared key | | [anonymousCred.ts][anonymouscred] | authenticate with the service anonymously using a SAS URL | -| [proxyAuth.ts][proxyauth] | connect to the service using a proxy and authenticate with an account name & key | +| [proxyAuth.ts][proxyauth] | connect to the service using a proxy and authenticate with an account name & key (requires a proxy configuration) | | [iterators-shares.ts][iterators-shares] | connect to the service and iterate through the shares in the account | | [iterators-files-and-directories.ts][iterators-files-and-directories] | create a few directories and iterate through them individually (using async `for await` syntax), by page, and resume paging using a marker | -| [iterators-handles.ts][iterators-handles] | connect to the service and iterate through open handles | +| [iterators-handles.ts][iterators-handles] | connect to the service and iterate through open handles (requires a pre-existing share and directory) | | [customPipeline.ts][custompipeline] | use custom HTTP pipeline options when connecting to the service | | [advanced.ts][advanced] | use custom logging and pipeline options, then upload a local file to a share | @@ -35,7 +35,7 @@ Before running the samples in Node, they must be compiled to JavaScript using th npm install -g typescript ``` -You need [an Azure subscription][freesub] and [an Azure Storage account][azstorage] to run these sample programs. Samples retrieve credentials to access the storage account from environment variables. See each individual sample for details on which environment variables it requires to function. +You need [an Azure subscription][freesub] and [an Azure Storage account][azstorage] to run these sample programs. Samples retrieve credentials to access the storage account from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function. Adapting the samples to run in the browser requires some additional consideration. For details, please see the [package README][package]. @@ -55,12 +55,26 @@ npm install npm run build ``` -3. Run the sample with the correct environment variables set, for example (cross-platform): +3. Edit the file `sample.env`, adding the correct credentials to access the Azure service and run the samples. Then rename the file from `sample.env` to just `.env`. The sample programs will read this file automatically. + +4. Run whichever samples you like (note that some samples may require additional setup, see the table above): + +```bash +node dist/basic.js +``` + +Alternatively, run a single sample with the correct environment variables set (step 3 is not required if you do this), for example (cross-platform): ```bash npx cross-env ACCOUNT_NAME="" ACCOUNT_KEY="" node dist/basic.js ``` +Or, to run all of the samples, use the following npm command: + +```bash +npm run execute:all +``` + ## Next Steps Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients. diff --git a/sdk/storage/storage-file-share/samples/typescript/package.json b/sdk/storage/storage-file-share/samples/typescript/package.json index efeb194d6963..faaaaecfe448 100644 --- a/sdk/storage/storage-file-share/samples/typescript/package.json +++ b/sdk/storage/storage-file-share/samples/typescript/package.json @@ -30,8 +30,9 @@ "homepage": "https://github.com/Azure/azure-sdk-for-js#readme", "sideEffects": false, "dependencies": { - "@azure/abort-controller": "^1.0.0", - "@azure/storage-file-share": "latest" + "@azure/abort-controller": "next", + "@azure/storage-file-share": "next", + "dotenv": "^8.2.0" }, "devDependencies": { "@types/node": "^8.0.0", diff --git a/sdk/storage/storage-file-share/samples/typescript/sample.env b/sdk/storage/storage-file-share/samples/typescript/sample.env new file mode 100644 index 000000000000..deb48f817cf6 --- /dev/null +++ b/sdk/storage/storage-file-share/samples/typescript/sample.env @@ -0,0 +1,9 @@ +# Used in most samples. Retrieve these values from a storage account in the Azure Portal. +ACCOUNT_NAME= +ACCOUNT_KEY= + +# Used for withConnString +STORAGE_CONNECTION_STRING= + +# Used for the advanced and anonymousCred tests. Create a SAS token for a storage account in the Azure Portal. +ACCOUNT_SAS= diff --git a/sdk/storage/storage-file-share/samples/typescript/src/anonymousCred.ts b/sdk/storage/storage-file-share/samples/typescript/src/anonymousCred.ts index 8d54a363e06a..641d127b8fa2 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/anonymousCred.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/anonymousCred.ts @@ -42,5 +42,5 @@ export async function main() { } runSample(main).catch((err) => { - console.log(err.message); + console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/basic.ts b/sdk/storage/storage-file-share/samples/typescript/src/basic.ts index 2411db606e71..c3bc8173f8ee 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/basic.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/basic.ts @@ -96,5 +96,5 @@ async function streamToString(readableStream: NodeJS.ReadableStream) { } runSample(main).catch((err) => { - console.log(err.message); + console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/customPipeline.ts b/sdk/storage/storage-file-share/samples/typescript/src/customPipeline.ts index f0f35fa3f205..8aac3de2c2c9 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/customPipeline.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/customPipeline.ts @@ -53,5 +53,5 @@ export async function main() { } runSample(main).catch((err) => { - console.log(err.message); + console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/iterators-files-and-directories.ts b/sdk/storage/storage-file-share/samples/typescript/src/iterators-files-and-directories.ts index e117d6edc08d..df8d78e7859e 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/iterators-files-and-directories.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/iterators-files-and-directories.ts @@ -163,5 +163,5 @@ export async function main() { } runSample(main).catch((err) => { - console.log(err.message); + console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts b/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts index 1195547e0428..951aa742d6cb 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts @@ -156,5 +156,5 @@ export async function main() { } runSample(main).catch((err) => { - console.log(err.message); + console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/iterators-shares.ts b/sdk/storage/storage-file-share/samples/typescript/src/iterators-shares.ts index 91227a58d616..3e914b568843 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/iterators-shares.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/iterators-shares.ts @@ -108,5 +108,5 @@ export async function main() { } runSample(main).catch((err) => { - console.log(err.message); + console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts b/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts index b84f9509c156..6a92e17e7b34 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts @@ -47,5 +47,5 @@ export async function main() { } runSample(main).catch((err) => { - console.log(err.message); + console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/run.ts b/sdk/storage/storage-file-share/samples/typescript/src/run.ts index 417a9bdf9973..6ed649b99556 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/run.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/run.ts @@ -12,6 +12,9 @@ import { main as iteratorsSharesMain } from "./iterators-shares"; import { main as sharedKeyCredMain } from "./sharedKeyCred"; import { main as withConnStringMain } from "./withConnString"; +import { config as dotenv } from "dotenv"; +dotenv(); + const samples: Array<[string, () => Promise]> = [ ["advanced", advancedMain], ["anonymousCred", anonymousCredMain], diff --git a/sdk/storage/storage-file-share/samples/typescript/src/sampleHelpers.ts b/sdk/storage/storage-file-share/samples/typescript/src/sampleHelpers.ts index 3cd362525b38..841754c05a42 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/sampleHelpers.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/sampleHelpers.ts @@ -1,7 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -export function runSample(sampleMain: () => Promise) { +import * as dotenv from "dotenv"; +dotenv.config(); + +export function runSample(sampleMain: () => Promise): Promise { if (!process.env["BATCH_RUN_SAMPLES"]) { return sampleMain(); } else { diff --git a/sdk/storage/storage-file-share/samples/typescript/src/sharedKeyCred.ts b/sdk/storage/storage-file-share/samples/typescript/src/sharedKeyCred.ts index 9d7f81194faa..7ca67399531e 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/sharedKeyCred.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/sharedKeyCred.ts @@ -42,5 +42,5 @@ export async function main() { } runSample(main).catch((err) => { - console.log(err.message); + console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/withConnString.ts b/sdk/storage/storage-file-share/samples/typescript/src/withConnString.ts index 84a552761c18..dba1bee16952 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/withConnString.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/withConnString.ts @@ -35,5 +35,5 @@ export async function main() { } runSample(main).catch((err) => { - console.log(err.message); + console.error("Error running sample:", err.message); }); From 160ab8450d2c45a716d5709842e87ab6758b8c99 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Tue, 10 Dec 2019 15:26:18 -0800 Subject: [PATCH 07/39] [storage-file-share] Brought js samples in line with ts samples --- .../samples/javascript/README.md | 18 +++++++- .../samples/javascript/advanced.js | 20 +++++---- .../samples/javascript/anonymousCred.js | 18 ++++---- .../samples/javascript/basic.js | 18 ++++---- .../samples/javascript/customPipeline.js | 18 ++++---- .../iterators-files-and-directories.js | 18 ++++---- .../samples/javascript/iterators-handles.js | 18 ++++---- .../samples/javascript/iterators-shares.js | 18 ++++---- .../samples/javascript/package.json | 13 +++--- .../samples/javascript/proxyAuth.js | 18 ++++---- .../samples/javascript/run.js | 41 +++++++++++++++++++ .../samples/javascript/sampleHelpers.js | 15 +++++++ .../samples/javascript/sharedKeyCred.js | 18 ++++---- .../samples/javascript/withConnString.js | 18 ++++---- 14 files changed, 179 insertions(+), 90 deletions(-) create mode 100644 sdk/storage/storage-file-share/samples/javascript/run.js create mode 100644 sdk/storage/storage-file-share/samples/javascript/sampleHelpers.js diff --git a/sdk/storage/storage-file-share/samples/javascript/README.md b/sdk/storage/storage-file-share/samples/javascript/README.md index 98bff075ab3a..3458a827f2a1 100644 --- a/sdk/storage/storage-file-share/samples/javascript/README.md +++ b/sdk/storage/storage-file-share/samples/javascript/README.md @@ -29,7 +29,7 @@ These sample programs show how to use the JavaScript client libraries for Azure The sample are compatible with Node.js >= 8.0.0, except for the samples that use the async `for await` syntax, which require Node.js >= 10.0.0. -You need [an Azure subscription][freesub] and [an Azure Storage account][azstorage] to run these sample programs. Samples retrieve credentials to access the storage account from environment variables. See each individual sample for details on which environment variables it requires to function. +You need [an Azure subscription][freesub] and [an Azure Storage account][azstorage] to run these sample programs. Samples retrieve credentials to access the storage account from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function. Adapting the samples to run in the browser requires some additional consideration. For details, please see the [package README][package]. @@ -43,12 +43,26 @@ To run the samples using the published version of the package: npm install ``` -2. Run the sample with the correct environment variables set, for example (cross-platform): +2. Edit the file `sample.env`, adding the correct credentials to access the Azure service and run the samples. Then rename the file from `sample.env` to just `.env`. The sample programs will read this file automatically. + +3. Run whichever samples you like (note that some samples may require additional setup, see the table above): + +```bash +node basic.js +``` + +Alternatively, run a single sample with the correct environment variables set (step 3 is not required if you do this), for example (cross-platform): ```bash npx cross-env ACCOUNT_NAME="" ACCOUNT_KEY="" node basic.js ``` +Or, to run all of the samples, use the following npm command: + +```bash +npm run execute:all +``` + ## Next Steps Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients. diff --git a/sdk/storage/storage-file-share/samples/javascript/advanced.js b/sdk/storage/storage-file-share/samples/javascript/advanced.js index 50f11b81f0e5..cd8a82a8b431 100644 --- a/sdk/storage/storage-file-share/samples/javascript/advanced.js +++ b/sdk/storage/storage-file-share/samples/javascript/advanced.js @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name, SAS and a path pointing to local file in main() */ @@ -10,6 +13,8 @@ const { newPipeline } = require("@azure/storage-file-share"); +const { runSample } = require("./sampleHelpers"); + // Enabling logging may help uncover useful information about failures. // In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. // Alternatively, logging can be enabled at runtime by calling `setLogLevel("info");` @@ -21,7 +26,7 @@ async function main() { // Fill in following settings before running this sample const account = process.env.ACCOUNT_NAME || ""; const accountSas = process.env.ACCOUNT_SAS || ""; - const localFilePath = "../README.md"; + const localFilePath = "README.md"; const pipeline = newPipeline(new AnonymousCredential(), { // httpClient: MyHTTPClient, // A customized HTTP client implementing IHttpClient interface @@ -99,11 +104,8 @@ async function main() { console.log("deleted share"); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-file-share/samples/javascript/anonymousCred.js b/sdk/storage/storage-file-share/samples/javascript/anonymousCred.js index 5b129ffd90bd..bd43b34e5ede 100644 --- a/sdk/storage/storage-file-share/samples/javascript/anonymousCred.js +++ b/sdk/storage/storage-file-share/samples/javascript/anonymousCred.js @@ -1,9 +1,14 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and SAS in main() */ const { ShareServiceClient, AnonymousCredential } = require("@azure/storage-file-share"); +const { runSample } = require("./sampleHelpers"); + async function main() { // Enter your storage account name and SAS const account = process.env.ACCOUNT_NAME || ""; @@ -36,11 +41,8 @@ async function main() { console.log(`deleted share ${shareName}`); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-file-share/samples/javascript/basic.js b/sdk/storage/storage-file-share/samples/javascript/basic.js index 9a454e33cd8b..b6724e17ef0b 100644 --- a/sdk/storage/storage-file-share/samples/javascript/basic.js +++ b/sdk/storage/storage-file-share/samples/javascript/basic.js @@ -1,9 +1,14 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ const { ShareServiceClient, StorageSharedKeyCredential } = require("@azure/storage-file-share"); +const { runSample } = require("./sampleHelpers"); + async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -90,11 +95,8 @@ async function streamToString(readableStream) { }); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-file-share/samples/javascript/customPipeline.js b/sdk/storage/storage-file-share/samples/javascript/customPipeline.js index 977d9b19ae49..9f95ede4ed78 100644 --- a/sdk/storage/storage-file-share/samples/javascript/customPipeline.js +++ b/sdk/storage/storage-file-share/samples/javascript/customPipeline.js @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ @@ -8,6 +11,8 @@ const { newPipeline } = require("@azure/storage-file-share"); +const { runSample } = require("./sampleHelpers"); + async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -47,11 +52,8 @@ async function main() { console.log(`deleted share ${shareName}`); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-file-share/samples/javascript/iterators-files-and-directories.js b/sdk/storage/storage-file-share/samples/javascript/iterators-files-and-directories.js index a18648ccb2bd..e1dea5d48545 100644 --- a/sdk/storage/storage-file-share/samples/javascript/iterators-files-and-directories.js +++ b/sdk/storage/storage-file-share/samples/javascript/iterators-files-and-directories.js @@ -1,9 +1,14 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ const { ShareServiceClient, StorageSharedKeyCredential } = require("@azure/storage-file-share"); +const { runSample } = require("./sampleHelpers"); + async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -157,11 +162,8 @@ async function main() { console.log(`deleted share ${shareName}`); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-file-share/samples/javascript/iterators-handles.js b/sdk/storage/storage-file-share/samples/javascript/iterators-handles.js index b7a55898b2ae..c3a810a7e8b4 100644 --- a/sdk/storage/storage-file-share/samples/javascript/iterators-handles.js +++ b/sdk/storage/storage-file-share/samples/javascript/iterators-handles.js @@ -1,9 +1,14 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ const { ShareServiceClient, StorageSharedKeyCredential } = require("@azure/storage-file-share"); +const { runSample } = require("./sampleHelpers"); + async function main() { // Enter your storage account name, shared key, share name, and directory name. // Please ensure your directory is mounted @@ -150,11 +155,8 @@ async function main() { } } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-file-share/samples/javascript/iterators-shares.js b/sdk/storage/storage-file-share/samples/javascript/iterators-shares.js index 13c7deaedb5a..f01b1fcadbd4 100644 --- a/sdk/storage/storage-file-share/samples/javascript/iterators-shares.js +++ b/sdk/storage/storage-file-share/samples/javascript/iterators-shares.js @@ -1,9 +1,14 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ const { ShareServiceClient, StorageSharedKeyCredential } = require("@azure/storage-file-share"); +const { runSample } = require("./sampleHelpers"); + async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -102,11 +107,8 @@ async function main() { } } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-file-share/samples/javascript/package.json b/sdk/storage/storage-file-share/samples/javascript/package.json index aa33f87c82c2..1592104110be 100644 --- a/sdk/storage/storage-file-share/samples/javascript/package.json +++ b/sdk/storage/storage-file-share/samples/javascript/package.json @@ -7,8 +7,7 @@ "node": ">=8.0.0" }, "scripts": { - "build": "tsc", - "prebuild": "rimraf dist/" + "execute:all": "cross-env BATCH_RUN_SAMPLES=true node run.js" }, "repository": { "type": "git", @@ -29,12 +28,12 @@ "homepage": "https://github.com/Azure/azure-sdk-for-js#readme", "sideEffects": false, "dependencies": { - "@azure/abort-controller": "^1.0.0", - "@azure/storage-file-share": "latest" + "@azure/abort-controller": "latest", + "@azure/storage-file-share": "latest", + "dotenv": "^8.2.0" }, "devDependencies": { - "@types/node": "^8.0.0", - "rimraf": "^3.0.0", - "typescript": "~3.6.4" + "cross-env": "^6.0.3", + "rimraf": "^3.0.0" } } diff --git a/sdk/storage/storage-file-share/samples/javascript/proxyAuth.js b/sdk/storage/storage-file-share/samples/javascript/proxyAuth.js index 10e765978cae..d2ff7b39bad7 100644 --- a/sdk/storage/storage-file-share/samples/javascript/proxyAuth.js +++ b/sdk/storage/storage-file-share/samples/javascript/proxyAuth.js @@ -1,9 +1,14 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ const { ShareServiceClient, StorageSharedKeyCredential } = require("@azure/storage-file-share"); +const { runSample } = require("./sampleHelpers"); + async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -41,11 +46,8 @@ async function main() { console.log(`deleted share ${shareName}`); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed the sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-file-share/samples/javascript/run.js b/sdk/storage/storage-file-share/samples/javascript/run.js new file mode 100644 index 000000000000..fe3a2c361536 --- /dev/null +++ b/sdk/storage/storage-file-share/samples/javascript/run.js @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +const { main: advancedMain } = require("./advanced"); +const { main: anonymousCredMain } = require("./anonymousCred"); +const { main: basicMain } = require("./basic"); +const { main: customPipelineMain } = require("./customPipeline"); +const { main: iteratorsFilesAndDirectoriesMain } = require("./iterators-files-and-directories"); +// const { main: iteratorsHandlesMain } = require("./iterators-handles"); +const { main: iteratorsSharesMain } = require("./iterators-shares"); +// const { main: proxyAuthMain } = require("./proxyAuth"); +const { main: sharedKeyCredMain } = require("./sharedKeyCred"); +const { main: withConnStringMain } = require("./withConnString"); + +const { config: dotenv } = require("dotenv"); +dotenv(); + +const samples = [ + ["advanced", advancedMain], + ["anonymousCred", anonymousCredMain], + ["basic", basicMain], + ["customPipeline", customPipelineMain], + ["iterators-files-and-directories", iteratorsFilesAndDirectoriesMain], + // ["iterators-handles", iteratorsHandlesMain], // Must be populated with a pre-existing share/directory name to run + ["iterators-shares", iteratorsSharesMain], + // ["proxyAuth", proxyAuthMain], // Requires a proxy + ["sharedKeyCred", sharedKeyCredMain], + ["withConnString", withConnStringMain] +]; + +async function main() { + for (let [sampleName, sampleMain] of samples) { + console.log("[samples] Running sample", sampleName); + await sampleMain(); + } +} + +main().catch((error) => { + console.error("[samples] An error occurred:", error); + process.exit(1); +}); diff --git a/sdk/storage/storage-file-share/samples/javascript/sampleHelpers.js b/sdk/storage/storage-file-share/samples/javascript/sampleHelpers.js new file mode 100644 index 000000000000..4b68987083ea --- /dev/null +++ b/sdk/storage/storage-file-share/samples/javascript/sampleHelpers.js @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +const dotenv = require("dotenv"); +dotenv.config(); + +module.exports = { + runSample(sampleMain) { + if (!process.env["BATCH_RUN_SAMPLES"]) { + return sampleMain(); + } else { + return Promise.resolve(); + } + } +}; diff --git a/sdk/storage/storage-file-share/samples/javascript/sharedKeyCred.js b/sdk/storage/storage-file-share/samples/javascript/sharedKeyCred.js index 54d0e497c77c..0f00205d57c9 100644 --- a/sdk/storage/storage-file-share/samples/javascript/sharedKeyCred.js +++ b/sdk/storage/storage-file-share/samples/javascript/sharedKeyCred.js @@ -1,9 +1,14 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ const { ShareServiceClient, StorageSharedKeyCredential } = require("@azure/storage-file-share"); +const { runSample } = require("./sampleHelpers"); + async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -36,11 +41,8 @@ async function main() { console.log(`deleted share ${shareName}`); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-file-share/samples/javascript/withConnString.js b/sdk/storage/storage-file-share/samples/javascript/withConnString.js index 43d394582cb6..0f4d31cead14 100644 --- a/sdk/storage/storage-file-share/samples/javascript/withConnString.js +++ b/sdk/storage/storage-file-share/samples/javascript/withConnString.js @@ -1,9 +1,14 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ const { ShareServiceClient } = require("@azure/storage-file-share"); +const { runSample } = require("./sampleHelpers"); + async function main() { // Create File Service Client from Account connection string or SAS connection string // Account connection string example - `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net` @@ -29,11 +34,8 @@ async function main() { console.log(`deleted share ${shareName}`); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; From 8d1070dcca4e501a99cf0d9ffefd363ee0349926 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Tue, 10 Dec 2019 15:27:52 -0800 Subject: [PATCH 08/39] [storage-file-share] bugfixes to ts samples packages --- .../storage-file-share/samples/typescript/package.json | 4 ++-- .../storage-file-share/samples/typescript/src/advanced.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/storage/storage-file-share/samples/typescript/package.json b/sdk/storage/storage-file-share/samples/typescript/package.json index faaaaecfe448..bd442cc914ce 100644 --- a/sdk/storage/storage-file-share/samples/typescript/package.json +++ b/sdk/storage/storage-file-share/samples/typescript/package.json @@ -30,8 +30,8 @@ "homepage": "https://github.com/Azure/azure-sdk-for-js#readme", "sideEffects": false, "dependencies": { - "@azure/abort-controller": "next", - "@azure/storage-file-share": "next", + "@azure/abort-controller": "latest", + "@azure/storage-file-share": "latest", "dotenv": "^8.2.0" }, "devDependencies": { diff --git a/sdk/storage/storage-file-share/samples/typescript/src/advanced.ts b/sdk/storage/storage-file-share/samples/typescript/src/advanced.ts index a577182c1fde..23cb97ba6925 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/advanced.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/advanced.ts @@ -15,7 +15,7 @@ export async function main() { // Fill in following settings before running this sample const account = process.env.ACCOUNT_NAME || ""; const accountSas = process.env.ACCOUNT_SAS || ""; - const localFilePath = "../README.md"; + const localFilePath = "README.md"; const pipeline = newPipeline(new AnonymousCredential(), { // httpClient: MyHTTPClient, // A customized HTTP client implementing IHttpClient interface From 7951b5a74c9ab7dcd7f5e7a0e2f2db8b4c7874c9 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Tue, 10 Dec 2019 15:39:00 -0800 Subject: [PATCH 09/39] [storage-file-share] NPM scripts to run samples --- sdk/storage/storage-file-share/package.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sdk/storage/storage-file-share/package.json b/sdk/storage/storage-file-share/package.json index 564596fa715c..ab72b8c02606 100644 --- a/sdk/storage/storage-file-share/package.json +++ b/sdk/storage/storage-file-share/package.json @@ -23,15 +23,17 @@ "build:autorest": "autorest ./swagger/README.md --typescript --package-version=12.0.0-preview.7 --use=@microsoft.azure/autorest.typescript@5.0.1", "build:es6": "tsc -p tsconfig.json", "build:nodebrowser": "rollup -c 2>&1", - "build:js-samples": "npm run clean && npm run build:es6 && cross-env ONLY_NODE=true rollup -c 2>&1", - "build:ts-samples": "npm run clean && node ../../../common/scripts/prep-samples.js && cd samples && tsc -p . ", + "build:samples": "npm run clean && npm run build:es6 && cross-env ONLY_NODE=true rollup -c 2>&1", + "build:ts-samples": "npm run build:samples && node ../../../common/scripts/prep-samples.js && cd samples && tsc -p . ", "build:test": "npm run build:es6 && rollup -c rollup.test.config.js 2>&1", "build": "npm run build:es6 && npm run build:nodebrowser && api-extractor run --local", "check-format": "prettier --list-different --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", "clean": "rimraf dist dist-esm dist-test typings temp browser/*.js* browser/*.zip statistics.html coverage coverage-browser .nyc_output *.tgz *.log test*.xml TEST*.xml", "clean:samples": "rimraf samples/javascript/node_modules samples/typescript/node_modules samples/typescript/dist samples/typescript/package-lock.json samples/javascript/package-lock.json", "extract-api": "tsc -p . && api-extractor run --local", - "execute:samples": "echo skipped for now due to https://github.com/Azure/azure-sdk-for-js/issues/6362", + "execute:js-samples": "npm run build:samples && cross-env BATCH_RUN_SAMPLES=true node samples/javascript/run.js", + "execute:ts-samples": "npm run build:ts-samples && cross-env BATCH_RUN_SAMPLES=true node samples/typescript/dist/run.js", + "execute:samples": "npm run execute:js-samples && npm run execute:ts-samples", "format": "prettier --write --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", "integration-test:browser": "karma start --single-run", "integration-test:node": "nyc mocha --require source-map-support/register --reporter mocha-multi --reporter-options spec=-,mocha-junit-reporter=- --full-trace -t 120000 --retries 2 dist-test/index.node.js", From 03c7b22b1f64319b52ae7f4a966afa40092679f4 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Tue, 10 Dec 2019 15:56:05 -0800 Subject: [PATCH 10/39] [storage-file-share] remove execute-samples.js and use new runners --- .../storage-file-share/execute-samples.js | 80 ------------------- sdk/storage/storage-file-share/package.json | 10 +-- .../storage-file-share/samples/tsconfig.json | 5 +- 3 files changed, 8 insertions(+), 87 deletions(-) delete mode 100644 sdk/storage/storage-file-share/execute-samples.js diff --git a/sdk/storage/storage-file-share/execute-samples.js b/sdk/storage/storage-file-share/execute-samples.js deleted file mode 100644 index aa77c71f12be..000000000000 --- a/sdk/storage/storage-file-share/execute-samples.js +++ /dev/null @@ -1,80 +0,0 @@ -const execa = require("execa"); -const fs = require("fs"); -require("dotenv").config({ path: "../.env" }); - -// Samples can be skipped by mentioning them in the skipSamples Array. -// Suppose skipSamples = ["some-entry", "sample-2"], -// some-entry.ts, sample-2.ts, some-entry.js and sample-2.js will be skipped. -const skipSamples = ["proxyAuth"]; - -const bDel = `!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`; -const del = `${bDel}------------------------------${bDel}`; - -// Colours - green, yellow, red and blue - for console logs. -const { g, y, r, b } = [["r", 1], ["g", 2], ["b", 4], ["y", 3]].reduce( - (cols, col) => ({ - ...cols, - [col[0]]: (f) => `\x1b[3${col[1]}m${f}\x1b[0m` - }), - {} -); - -// Executes `cmd` in `cwd`(directory). -async function exec(cmd, cwd) { - let command = execa(cmd, { - cwd, - shell: true - }); - command.stderr.pipe(process.stderr); - command.stdout.pipe(process.stdout); - return command; -} - -async function runSamples(language) { - let cmd; - // Tries to execute all the samples in the `directory`. - const directory = `./samples/${language}`; - - if (language === "typescript") { - cmd = "ts-node"; - } else { - cmd = "node"; - await exec(`npm run build:js-samples`, directory); - } - - console.log(`Running ${language} samples...`); - - const files = fs.readdirSync(directory); - - for (var i = 0; i < files.length; i++) { - if (!skipSamples.includes(files[i].split(".")[0])) { - try { - console.log(`\n\n${b(del)}\n${del}`); - console.log(`${bDel}\t${files[i]} \t `); - console.log(`${del}\n${b(del)} \n`); - - console.log(`${g("Running")} ${y(files[i])} ${g("...")}`); - // Executing a sample - Example: (`ts-node samplefilename.ts`, `./samples/typescript`). - await exec(`${cmd} ${files[i]}`, directory); - console.log(`${g(files[i] + " is done..!")}`); - } catch (error) { - console.log(error.message); - console.log(`${r(del)}\n${del}`); - console.log(`${bDel}\t${files[i]} Sample - FAILED\t `); - console.log(`${del}\n${r(del)}`); - } - } - } -} - -(async () => { - try { - await runSamples("typescript"); - await runSamples("javascript"); - process.exit(0); - } catch (error) { - console.log("Samples failed!"); - console.log(error); - process.exit(1); - } -})(); diff --git a/sdk/storage/storage-file-share/package.json b/sdk/storage/storage-file-share/package.json index ab72b8c02606..4d64b462b2ee 100644 --- a/sdk/storage/storage-file-share/package.json +++ b/sdk/storage/storage-file-share/package.json @@ -23,17 +23,17 @@ "build:autorest": "autorest ./swagger/README.md --typescript --package-version=12.0.0-preview.7 --use=@microsoft.azure/autorest.typescript@5.0.1", "build:es6": "tsc -p tsconfig.json", "build:nodebrowser": "rollup -c 2>&1", - "build:samples": "npm run clean && npm run build:es6 && cross-env ONLY_NODE=true rollup -c 2>&1", - "build:ts-samples": "npm run build:samples && node ../../../common/scripts/prep-samples.js && cd samples && tsc -p . ", + "build:samples": "npm run clean && npm run build:es6 && cross-env ONLY_NODE=true rollup -c 2>&1 && npm run build:prep-samples", + "build:prep-samples": "node ../../../common/scripts/prep-samples.js && cd samples && tsc", "build:test": "npm run build:es6 && rollup -c rollup.test.config.js 2>&1", "build": "npm run build:es6 && npm run build:nodebrowser && api-extractor run --local", "check-format": "prettier --list-different --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", "clean": "rimraf dist dist-esm dist-test typings temp browser/*.js* browser/*.zip statistics.html coverage coverage-browser .nyc_output *.tgz *.log test*.xml TEST*.xml", "clean:samples": "rimraf samples/javascript/node_modules samples/typescript/node_modules samples/typescript/dist samples/typescript/package-lock.json samples/javascript/package-lock.json", "extract-api": "tsc -p . && api-extractor run --local", - "execute:js-samples": "npm run build:samples && cross-env BATCH_RUN_SAMPLES=true node samples/javascript/run.js", - "execute:ts-samples": "npm run build:ts-samples && cross-env BATCH_RUN_SAMPLES=true node samples/typescript/dist/run.js", - "execute:samples": "npm run execute:js-samples && npm run execute:ts-samples", + "execute:js-samples": "cross-env BATCH_RUN_SAMPLES=true node samples/javascript/run.js", + "execute:ts-samples": "cross-env BATCH_RUN_SAMPLES=true node samples/typescript/dist/samples/typescript/src/run.js", + "execute:samples": "npm run build:samples && npm run execute:js-samples && npm run execute:ts-samples", "format": "prettier --write --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", "integration-test:browser": "karma start --single-run", "integration-test:node": "nyc mocha --require source-map-support/register --reporter mocha-multi --reporter-options spec=-,mocha-junit-reporter=- --full-trace -t 120000 --retries 2 dist-test/index.node.js", diff --git a/sdk/storage/storage-file-share/samples/tsconfig.json b/sdk/storage/storage-file-share/samples/tsconfig.json index 375ae59feb0b..3a37abdb0902 100644 --- a/sdk/storage/storage-file-share/samples/tsconfig.json +++ b/sdk/storage/storage-file-share/samples/tsconfig.json @@ -1,8 +1,9 @@ { "extends": "../tsconfig.json", "compilerOptions": { - "module": "commonjs" + "module": "commonjs", + "outDir": "typescript/dist" }, - "include": ["typescript/**/*.ts"], + "include": ["typescript/src/**.ts"], "exclude": ["typescript/*.json", "**/node_modules/", "../node_modules", "../typings"] } From 6adcb5d54ce10afcffcfc3bd8cc53c6246bd4ac8 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Tue, 10 Dec 2019 16:17:56 -0800 Subject: [PATCH 11/39] [storage-file-share] added missing sample.env to js samples --- .../storage-file-share/samples/javascript/sample.env | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 sdk/storage/storage-file-share/samples/javascript/sample.env diff --git a/sdk/storage/storage-file-share/samples/javascript/sample.env b/sdk/storage/storage-file-share/samples/javascript/sample.env new file mode 100644 index 000000000000..deb48f817cf6 --- /dev/null +++ b/sdk/storage/storage-file-share/samples/javascript/sample.env @@ -0,0 +1,9 @@ +# Used in most samples. Retrieve these values from a storage account in the Azure Portal. +ACCOUNT_NAME= +ACCOUNT_KEY= + +# Used for withConnString +STORAGE_CONNECTION_STRING= + +# Used for the advanced and anonymousCred tests. Create a SAS token for a storage account in the Azure Portal. +ACCOUNT_SAS= From 9a793e67852bab203835b5cb9357b473fd13149b Mon Sep 17 00:00:00 2001 From: Will Temple Date: Tue, 10 Dec 2019 16:25:03 -0800 Subject: [PATCH 12/39] [storage-file-share] Fixed sample package names --- sdk/storage/storage-file-share/samples/javascript/package.json | 2 +- sdk/storage/storage-file-share/samples/typescript/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/storage/storage-file-share/samples/javascript/package.json b/sdk/storage/storage-file-share/samples/javascript/package.json index 1592104110be..1f90cdb174a6 100644 --- a/sdk/storage/storage-file-share/samples/javascript/package.json +++ b/sdk/storage/storage-file-share/samples/javascript/package.json @@ -1,5 +1,5 @@ { - "name": "azure-file-share-samples-js", + "name": "azure-storage-file-share-samples-js", "private": true, "version": "0.1.0", "description": "Azure Storage File Share client library samples for TypeScript", diff --git a/sdk/storage/storage-file-share/samples/typescript/package.json b/sdk/storage/storage-file-share/samples/typescript/package.json index bd442cc914ce..e25c49ddeb86 100644 --- a/sdk/storage/storage-file-share/samples/typescript/package.json +++ b/sdk/storage/storage-file-share/samples/typescript/package.json @@ -1,5 +1,5 @@ { - "name": "azure-file-share-samples-ts", + "name": "azure-storage-file-share-samples-ts", "private": true, "version": "0.1.0", "description": "Azure Storage File Share client library samples for TypeScript", From ef9a3d4061517be6f73c2cb9f899f494f01cc359 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Tue, 10 Dec 2019 17:43:48 -0800 Subject: [PATCH 13/39] [storage-blob] update samples to be like storage-file-share --- sdk/storage/storage-blob/package.json | 8 +- .../storage-blob/samples/javascript/README.md | 91 +++++++++++++++ .../samples/javascript/advanced.js | 22 ++-- .../samples/javascript/anonymousCred.js | 20 ++-- .../samples/javascript/azureAdAuth.js | 20 ++-- .../storage-blob/samples/javascript/basic.js | 20 ++-- .../samples/javascript/customPipeline.js | 24 ++-- .../javascript/customizedClientHeaders.js | 32 ++++-- .../samples/javascript/errorsAndResponses.js | 20 ++-- .../javascript/iterators-blobs-hierarchy.js | 20 ++-- .../samples/javascript/iterators-blobs.js | 20 ++-- .../javascript/iterators-containers.js | 20 ++-- .../samples/javascript/package.json | 40 +++++++ .../samples/javascript/proxyAuth.js | 20 ++-- .../samples/javascript/readingSnapshot.js | 20 ++-- .../storage-blob/samples/javascript/run.js | 49 +++++++++ .../samples/javascript/sample.env | 14 +++ .../samples/javascript/sampleHelpers.js | 15 +++ .../samples/javascript/sharedKeyCred.js | 20 ++-- .../samples/javascript/withConnString.js | 20 ++-- .../storage-blob/samples/tsconfig.json | 20 ++-- .../storage-blob/samples/typescript/README.md | 104 ++++++++++++++++++ .../samples/typescript/package.json | 45 ++++++++ .../samples/typescript/sample.env | 14 +++ .../samples/typescript/{ => src}/advanced.ts | 24 ++-- .../typescript/{ => src}/anonymousCred.ts | 20 ++-- .../typescript/{ => src}/azureAdAuth.ts | 20 ++-- .../samples/typescript/{ => src}/basic.ts | 24 ++-- .../typescript/{ => src}/customPipeline.ts | 20 ++-- .../{ => src}/customizedClientHeaders.ts | 27 +++-- .../{ => src}/errorsAndResponses.ts | 20 ++-- .../{ => src}/iterators-blobs-hierarchy.ts | 20 ++-- .../typescript/{ => src}/iterators-blobs.ts | 20 ++-- .../{ => src}/iterators-containers.ts | 20 ++-- .../samples/typescript/{ => src}/proxyAuth.ts | 20 ++-- .../typescript/{ => src}/readingSnapshot.ts | 20 ++-- .../samples/typescript/src/run.ts | 49 +++++++++ .../samples/typescript/src/sampleHelpers.ts | 13 +++ .../typescript/{ => src}/sharedKeyCred.ts | 20 ++-- .../typescript/{ => src}/withConnString.ts | 20 ++-- .../samples/typescript/tsconfig.json | 15 +++ 41 files changed, 784 insertions(+), 286 deletions(-) create mode 100644 sdk/storage/storage-blob/samples/javascript/README.md create mode 100644 sdk/storage/storage-blob/samples/javascript/package.json create mode 100644 sdk/storage/storage-blob/samples/javascript/run.js create mode 100644 sdk/storage/storage-blob/samples/javascript/sample.env create mode 100644 sdk/storage/storage-blob/samples/javascript/sampleHelpers.js create mode 100644 sdk/storage/storage-blob/samples/typescript/README.md create mode 100644 sdk/storage/storage-blob/samples/typescript/package.json create mode 100644 sdk/storage/storage-blob/samples/typescript/sample.env rename sdk/storage/storage-blob/samples/typescript/{ => src}/advanced.ts (92%) rename sdk/storage/storage-blob/samples/typescript/{ => src}/anonymousCred.ts (75%) rename sdk/storage/storage-blob/samples/typescript/{ => src}/azureAdAuth.ts (89%) rename sdk/storage/storage-blob/samples/typescript/{ => src}/basic.ts (90%) rename sdk/storage/storage-blob/samples/typescript/{ => src}/customPipeline.ts (83%) rename sdk/storage/storage-blob/samples/typescript/{ => src}/customizedClientHeaders.ts (86%) rename sdk/storage/storage-blob/samples/typescript/{ => src}/errorsAndResponses.ts (94%) rename sdk/storage/storage-blob/samples/typescript/{ => src}/iterators-blobs-hierarchy.ts (92%) rename sdk/storage/storage-blob/samples/typescript/{ => src}/iterators-blobs.ts (91%) rename sdk/storage/storage-blob/samples/typescript/{ => src}/iterators-containers.ts (89%) rename sdk/storage/storage-blob/samples/typescript/{ => src}/proxyAuth.ts (77%) rename sdk/storage/storage-blob/samples/typescript/{ => src}/readingSnapshot.ts (89%) create mode 100644 sdk/storage/storage-blob/samples/typescript/src/run.ts create mode 100644 sdk/storage/storage-blob/samples/typescript/src/sampleHelpers.ts rename sdk/storage/storage-blob/samples/typescript/{ => src}/sharedKeyCred.ts (75%) rename sdk/storage/storage-blob/samples/typescript/{ => src}/withConnString.ts (79%) create mode 100644 sdk/storage/storage-blob/samples/typescript/tsconfig.json diff --git a/sdk/storage/storage-blob/package.json b/sdk/storage/storage-blob/package.json index dba760e7faee..9adc2c5016e3 100644 --- a/sdk/storage/storage-blob/package.json +++ b/sdk/storage/storage-blob/package.json @@ -24,14 +24,16 @@ "build:autorest": "autorest ./swagger/README.md --typescript --package-version=12.0.1 --use=@microsoft.azure/autorest.typescript@5.0.1", "build:es6": "tsc -p tsconfig.json", "build:nodebrowser": "rollup -c 2>&1", - "build:js-samples": "npm run clean && npm run build:es6 && cross-env ONLY_NODE=true rollup -c 2>&1", - "build:ts-samples": "npm run clean && cd samples && tsc -p . ", + "build:samples": "npm run clean && npm run build:es6 && cross-env ONLY_NODE=true rollup -c 2>&1 && npm run build:prep-samples", + "build:prep-samples": "node ../../../common/scripts/prep-samples.js && cd samples && tsc", "build:test": "npm run build:es6 && rollup -c rollup.test.config.js 2>&1", "build": "npm run build:es6 && npm run build:nodebrowser && api-extractor run --local", "check-format": "prettier --list-different --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", "clean": "rimraf dist dist-esm dist-test typings temp browser/*.js* browser/*.zip statistics.html coverage coverage-browser .nyc_output *.tgz *.log test*.xml TEST*.xml", "extract-api": "tsc -p . && api-extractor run --local", - "execute:samples": "node execute-samples.js", + "execute:js-samples": "cross-env BATCH_RUN_SAMPLES=true node samples/javascript/run.js", + "execute:ts-samples": "cross-env BATCH_RUN_SAMPLES=true node samples/typescript/dist/samples/typescript/src/run.js", + "execute:samples": "npm run build:samples && npm run execute:js-samples && npm run execute:ts-samples", "format": "prettier --write --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", "integration-test:browser": "karma start --single-run", "integration-test:node": "nyc mocha --require source-map-support/register --reporter mocha-multi --reporter-options spec=-,mocha-junit-reporter=- --full-trace -t 120000 --retries 2 dist-test/index.node.js", diff --git a/sdk/storage/storage-blob/samples/javascript/README.md b/sdk/storage/storage-blob/samples/javascript/README.md new file mode 100644 index 000000000000..2885cdb5a22f --- /dev/null +++ b/sdk/storage/storage-blob/samples/javascript/README.md @@ -0,0 +1,91 @@ +--- +page_type: sample +languages: + - javascript +products: + - azure + - azure-storage +urlFragment: storage-blob-javascript +--- + +# Azure Storage Blob client library samples for JavaScript + +These sample programs show how to use the JavaScript client libraries for Azure Storage Blobs in some common scenarios. + +| **File Name** | **Description** | +| --------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [basic.js][basic] | authenticate with the service using an account name & key (or anonymously with a SAS URL); create and delete containers; create, list, and download a blob | +| [withConnString.js][withconnstring] | connect to and authenticate with the service using a connection string | +| [sharedKeyCred.js][sharedkeycred] | authenticate with the service using an account name and a shared key | +| [anonymousCred.js][anonymouscred] | authenticate with the service anonymously using a SAS URL | +| [azureAdAuth.js][azureadauth] | authenticate with the service using Azure Active Directory | +| [proxyAuth.js][proxyauth] | connect to the service using a proxy and authenticate with an account name & key | +| [iterators-blobs.js][iterators-blobs] | different methods for iterating over blobs in a container, showing options for paging, resuming paging, etc. | +| [iterators-containers.js][iterators-containers] | different methods for iterating over containers in an account, showing options for paging, resuming paging, etc. | +| [iterators-blobs-hierarchy.js][iterators-blobs-hierarchy] | iterating over blobs by hierarchy, using separators in the blob names, showing options for paging, resuming paging, etc. | +| [customPipeline.js][custompipeline] | use custom HTTP pipeline options when connecting to the service | +| [customizedClientHeaders.js][customizedclientheaders] | use a custom request policy to add metadata to requests, in this case through the custom x-ms-client-request-id header | +| [errorsAndResponses.js][errorsandresponses] | demonstrate various errors and responses | +| [readingSnapshot.js][readingsnapshot] | create a blob snapshot and read from that snapshot | +| [advanced.js][advanced] | use custom logging and pipeline options, then shows some example advanced options when creating containers, listing and downloading blobs, etc. | + +## Prerequisites + +The sample are compatible with Node.js >= 8.0.0, except for the samples that use the async `for await` syntax, which require Node.js >= 10.0.0. + +You need [an Azure subscription][freesub] and [an Azure Storage account][azstorage] to run these sample programs. Samples retrieve credentials to access the storage account from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function. + +Adapting the samples to run in the browser requires some additional consideration. For details, please see the [package README][package]. + +## Setup + +To run the samples using the published version of the package: + +1. Install the dependencies using `npm`: + +```bash +npm install +``` + +2. Edit the file `sample.env`, adding the correct credentials to access the Azure service and run the samples. Then rename the file from `sample.env` to just `.env`. The sample programs will read this file automatically. + +3. Run whichever samples you like (note that some samples may require additional setup, see the table above): + +```bash +node basic.js +``` + +Alternatively, run a single sample with the correct environment variables set (step 3 is not required if you do this), for example (cross-platform): + +```bash +npx cross-env ACCOUNT_NAME="" ACCOUNT_KEY="" node basic.js +``` + +Or, to run all of the samples, use the following npm command: + +```bash +npm run execute:all +``` + +## Next Steps + +Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients. + +[advanced]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/javascript/advanced.js +[anonymouscred]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/javascript/anonymousCred.js +[azureadauth]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/javascript/azureAdAuth.js +[basic]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/javascript/basic.js +[customizedclientheaders]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/javascript/customizedClientHeaders.js +[custompipeline]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/javascript/customPipeline.js +[errorsandresponses]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/javascript/errorsAndResponses.js +[iterators-blobs-hierarchy]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/javascript/iterators-blobs-hierarchy.js +[iterators-blobs]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/javascript/iterators-blobs.js +[iterators-containers]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/javascript/iterators-containers.js +[proxyauth]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/javascript/proxyAuth.js +[readingsnapshot]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/javascript/readingSnapshot.js +[sharedkeycred]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/javascript/sharedKeyCred.js +[withconnstring]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/javascript/withConnString.js +[apiref]: https://docs.microsoft.com/javascript/api/@azure/storage-blob +[azstorage]: https://docs.microsoft.com/azure/storage/common/storage-account-overview +[freesub]: https://azure.microsoft.com/free/ +[package]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/README.md diff --git a/sdk/storage/storage-blob/samples/javascript/advanced.js b/sdk/storage/storage-blob/samples/javascript/advanced.js index 475f09a1e9a9..614cd816134d 100644 --- a/sdk/storage/storage-blob/samples/javascript/advanced.js +++ b/sdk/storage/storage-blob/samples/javascript/advanced.js @@ -1,10 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name, SAS and a path pointing to local file in main() */ const fs = require("fs"); const { AbortController } = require("@azure/abort-controller"); -const { AnonymousCredential, BlobServiceClient, newPipeline } = require("../.."); // Change to "@azure/storage-blob" in your package +const { AnonymousCredential, BlobServiceClient, newPipeline } = require("@azure/storage-blob"); + +const { runSample } = require("./sampleHelpers"); // Enabling logging may help uncover useful information about failures. // In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. @@ -17,7 +22,7 @@ async function main() { // Fill in following settings before running this sample const account = process.env.ACCOUNT_NAME || ""; const accountSas = process.env.ACCOUNT_SAS || ""; - const localFilePath = "../README.md"; + const localFilePath = "README.md"; const pipeline = newPipeline(new AnonymousCredential(), { // httpClient: MyHTTPClient, // A customized HTTP client implementing IHttpClient interface @@ -127,11 +132,8 @@ async function main() { console.log("deleted container"); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/anonymousCred.js b/sdk/storage/storage-blob/samples/javascript/anonymousCred.js index 0b1b53d15464..428afc880e06 100644 --- a/sdk/storage/storage-blob/samples/javascript/anonymousCred.js +++ b/sdk/storage/storage-blob/samples/javascript/anonymousCred.js @@ -1,8 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and SAS in main() */ -const { BlobServiceClient, AnonymousCredential } = require("../.."); // Change to "@azure/storage-blob" in your package +const { BlobServiceClient, AnonymousCredential } = require("@azure/storage-blob"); + +const { runSample } = require("./sampleHelpers"); async function main() { // Enter your storage account name and SAS @@ -37,11 +42,8 @@ async function main() { console.log("deleted container"); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/azureAdAuth.js b/sdk/storage/storage-blob/samples/javascript/azureAdAuth.js index 2f2d81db6808..6e6d2d457d3c 100644 --- a/sdk/storage/storage-blob/samples/javascript/azureAdAuth.js +++ b/sdk/storage/storage-blob/samples/javascript/azureAdAuth.js @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* ONLY AVAILABLE IN NODE.JS RUNTIME @@ -18,9 +21,11 @@ - Make sure you have AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET as environment variables to successfully execute the sample(Can leverage process.env). */ -const { BlobServiceClient } = require("../.."); // Change to "@azure/storage-blob" in your package +const { BlobServiceClient } = require("@azure/storage-blob"); const { DefaultAzureCredential } = require("@azure/identity"); +const { runSample } = require("./sampleHelpers"); + async function main() { // Enter your storage account name const account = process.env.ACCOUNT_NAME || ""; @@ -51,11 +56,8 @@ async function main() { console.log(`Created container ${containerName} successfully`, createContainerResponse.requestId); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed the sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/basic.js b/sdk/storage/storage-blob/samples/javascript/basic.js index 5ac24138fafb..51cde552ddb4 100644 --- a/sdk/storage/storage-blob/samples/javascript/basic.js +++ b/sdk/storage/storage-blob/samples/javascript/basic.js @@ -1,8 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -const { BlobServiceClient, StorageSharedKeyCredential } = require("../.."); // Change to "@azure/storage-blob" in your package +const { BlobServiceClient, StorageSharedKeyCredential } = require("@azure/storage-blob"); + +const { runSample } = require("./sampleHelpers"); async function main() { // Enter your storage account name and shared key @@ -94,11 +99,8 @@ async function streamToString(readableStream) { }); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/customPipeline.js b/sdk/storage/storage-blob/samples/javascript/customPipeline.js index 86788560fb50..be7944457a74 100644 --- a/sdk/storage/storage-blob/samples/javascript/customPipeline.js +++ b/sdk/storage/storage-blob/samples/javascript/customPipeline.js @@ -1,8 +1,17 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -const { BlobServiceClient, StorageSharedKeyCredential, newPipeline } = require("../.."); // Change to "@azure/storage-blob" in your package +const { + BlobServiceClient, + StorageSharedKeyCredential, + newPipeline +} = require("@azure/storage-blob"); + +const { runSample } = require("./sampleHelpers"); async function main() { // Enter your storage account name and shared key @@ -44,11 +53,8 @@ async function main() { console.log("deleted container"); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/customizedClientHeaders.js b/sdk/storage/storage-blob/samples/javascript/customizedClientHeaders.js index b0185af6682f..00a4efba5f1f 100644 --- a/sdk/storage/storage-blob/samples/javascript/customizedClientHeaders.js +++ b/sdk/storage/storage-blob/samples/javascript/customizedClientHeaders.js @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* You can create your own policy and inject it into the default pipeline, or create your own Pipeline. A request policy is a filter triggered before and after a HTTP request. With a filter, we can tweak HTTP requests and responses. @@ -9,7 +12,14 @@ Setup: Enter your storage account name and shared key in main() */ -const { newPipeline, AnonymousCredential, BlobServiceClient, BaseRequestPolicy } = require("../.."); // Change to "@azure/storage-blob" in your package +const { + newPipeline, + AnonymousCredential, + BlobServiceClient, + BaseRequestPolicy +} = require("@azure/storage-blob"); + +const { runSample } = require("./sampleHelpers"); // Create a policy factory with create() method provided class RequestIDPolicyFactory { @@ -64,17 +74,19 @@ async function main() { `https://${account}.blob.core.windows.net${accountSas}`, pipeline ); - const response = (await blobServiceClient - .listContainers() - .byPage() - .next()).value; + const response = ( + await blobServiceClient + .listContainers() + .byPage() + .next() + ).value; // Check customized client request ID console.log(response._response.request.headers.get("x-ms-client-request-id")); } -main() - .then(() => { - console.log("Successfully executed sample"); - }) - .catch(console.error); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/errorsAndResponses.js b/sdk/storage/storage-blob/samples/javascript/errorsAndResponses.js index f21c3be43482..024b6e0c9ec3 100644 --- a/sdk/storage/storage-blob/samples/javascript/errorsAndResponses.js +++ b/sdk/storage/storage-blob/samples/javascript/errorsAndResponses.js @@ -1,8 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter connection string of your storage account name in main() */ -const { BlobServiceClient } = require("../.."); // Change to "@azure/storage-blob" in your package +const { BlobServiceClient } = require("@azure/storage-blob"); + +const { runSample } = require("./sampleHelpers"); async function main() { // Create Blob Service Client from Account connection string or SAS connection string @@ -145,11 +150,8 @@ async function streamToString(readableStream) { }); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("\n\nSuccessfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/iterators-blobs-hierarchy.js b/sdk/storage/storage-blob/samples/javascript/iterators-blobs-hierarchy.js index 1f87715de689..cdc5c21da6c5 100644 --- a/sdk/storage/storage-blob/samples/javascript/iterators-blobs-hierarchy.js +++ b/sdk/storage/storage-blob/samples/javascript/iterators-blobs-hierarchy.js @@ -1,8 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -const { BlobServiceClient, StorageSharedKeyCredential } = require("../.."); // Change to "@azure/storage-blob" in your package +const { BlobServiceClient, StorageSharedKeyCredential } = require("@azure/storage-blob"); + +const { runSample } = require("./sampleHelpers"); async function main() { // Enter your storage account name and shared key @@ -131,11 +136,8 @@ async function main() { console.log("deleted container"); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed the sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/iterators-blobs.js b/sdk/storage/storage-blob/samples/javascript/iterators-blobs.js index f0de7a795926..fee6c48847f1 100644 --- a/sdk/storage/storage-blob/samples/javascript/iterators-blobs.js +++ b/sdk/storage/storage-blob/samples/javascript/iterators-blobs.js @@ -1,8 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -const { BlobServiceClient, StorageSharedKeyCredential } = require("../.."); // Change to "@azure/storage-blob" in your package +const { BlobServiceClient, StorageSharedKeyCredential } = require("@azure/storage-blob"); + +const { runSample } = require("./sampleHelpers"); async function main() { // Enter your storage account name and shared key @@ -122,11 +127,8 @@ async function main() { console.log("deleted container"); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed the sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/iterators-containers.js b/sdk/storage/storage-blob/samples/javascript/iterators-containers.js index d8f86c089bf0..12ff311f3894 100644 --- a/sdk/storage/storage-blob/samples/javascript/iterators-containers.js +++ b/sdk/storage/storage-blob/samples/javascript/iterators-containers.js @@ -1,8 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -const { BlobServiceClient, StorageSharedKeyCredential } = require("../.."); // Change to "@azure/storage-blob" in your package +const { BlobServiceClient, StorageSharedKeyCredential } = require("@azure/storage-blob"); + +const { runSample } = require("./sampleHelpers"); async function main() { // Enter your storage account name and shared key @@ -111,11 +116,8 @@ async function main() { } } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed the sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/package.json b/sdk/storage/storage-blob/samples/javascript/package.json new file mode 100644 index 000000000000..b1576d7301ad --- /dev/null +++ b/sdk/storage/storage-blob/samples/javascript/package.json @@ -0,0 +1,40 @@ +{ + "name": "azure-storage-blob-samples-js", + "private": true, + "version": "0.1.0", + "description": "Azure Storage Blob client library samples for TypeScript", + "engine": { + "node": ">=8.0.0" + }, + "scripts": { + "execute:all": "cross-env BATCH_RUN_SAMPLES=true node run.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Azure/azure-sdk-for-js.git" + }, + "keywords": [ + "Azure", + "Storage", + "File", + "Node.js", + "JavaScript" + ], + "author": "Microsoft Corporation", + "license": "MIT", + "bugs": { + "url": "https://github.com/Azure/azure-sdk-for-js/issues" + }, + "homepage": "https://github.com/Azure/azure-sdk-for-js#readme", + "sideEffects": false, + "dependencies": { + "@azure/abort-controller": "latest", + "@azure/identity": "latest", + "@azure/storage-blob": "latest", + "dotenv": "^8.2.0" + }, + "devDependencies": { + "cross-env": "^6.0.3", + "rimraf": "^3.0.0" + } +} diff --git a/sdk/storage/storage-blob/samples/javascript/proxyAuth.js b/sdk/storage/storage-blob/samples/javascript/proxyAuth.js index 424af6251cdf..6d06e59c3518 100644 --- a/sdk/storage/storage-blob/samples/javascript/proxyAuth.js +++ b/sdk/storage/storage-blob/samples/javascript/proxyAuth.js @@ -1,8 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -const { BlobServiceClient, StorageSharedKeyCredential } = require("../.."); // Change to "@azure/storage-blob" in your package +const { BlobServiceClient, StorageSharedKeyCredential } = require("@azure/storage-blob"); + +const { runSample } = require("./sampleHelpers"); async function main() { // Enter your storage account name and shared key @@ -38,11 +43,8 @@ async function main() { console.log(`Created container ${containerName} successfully`, createContainerResponse.requestId); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed the sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/readingSnapshot.js b/sdk/storage/storage-blob/samples/javascript/readingSnapshot.js index 20d4a2a03b71..c34483abd9f7 100644 --- a/sdk/storage/storage-blob/samples/javascript/readingSnapshot.js +++ b/sdk/storage/storage-blob/samples/javascript/readingSnapshot.js @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* If you use BlobClient.download() to download an append blob which is being actively appended, you may get a 412 HTTP error, just like this issue: https://github.com/Azure/azure-storage-js/issues/51 @@ -18,7 +21,9 @@ Setup: Enter your storage account name and shared key in main() */ -const { BlobServiceClient, StorageSharedKeyCredential } = require("../.."); // Change to "@azure/storage-blob" in your package +const { BlobServiceClient, StorageSharedKeyCredential } = require("@azure/storage-blob"); + +const { runSample } = require("./sampleHelpers"); async function main() { // Enter your storage account name and shared key @@ -82,11 +87,8 @@ async function streamToString(readableStream) { }); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/run.js b/sdk/storage/storage-blob/samples/javascript/run.js new file mode 100644 index 000000000000..221c8d84f141 --- /dev/null +++ b/sdk/storage/storage-blob/samples/javascript/run.js @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +const { main: advancedMain } = require("./advanced"); +const { main: anonymousCredMain } = require("./anonymousCred"); +const { main: azureAdAuthMain } = require("./azureAdAuth"); +const { main: basicMain } = require("./basic"); +const { main: customizedClientHeadersMain } = require("./customizedClientHeaders"); +const { main: customPipelineMain } = require("./customPipeline"); +const { main: errorsAndResponsesMain } = require("./errorsAndResponses"); +const { main: iteratorsBlobsHierarchyMain } = require("./iterators-blobs-hierarchy"); +const { main: iteratorsBlobsMain } = require("./iterators-blobs"); +const { main: iteratorsContainersMain } = require("./iterators-containers"); +// const { main: proxyAuthMain } = require("./proxyAuth"); +const { main: readingSnapshotMain } = require("./readingSnapshot"); +const { main: sharedKeyCredMain } = require("./sharedKeyCred"); +const { main: withConnStringMain } = require("./withConnString"); + +const { config: dotenv } = require("dotenv"); +dotenv(); + +const samples = [ + ["advanced", advancedMain], + ["anonymousCred", anonymousCredMain], + ["azureAdAuth", azureAdAuthMain], + ["basic", basicMain], + ["customizedClientHeaders", customizedClientHeadersMain], + ["customPipeline", customPipelineMain], + ["errorsAndResponses", errorsAndResponsesMain], + ["iterators-blobs-hierarchy", iteratorsBlobsHierarchyMain], + ["iterators-blobs", iteratorsBlobsMain], + ["iterators-containers", iteratorsContainersMain], + // ["proxyAuth", proxyAuthMain], // Requires a proxy + ["readingSnapshot", readingSnapshotMain], + ["sharedKeyCred", sharedKeyCredMain], + ["withConnString", withConnStringMain] +]; + +async function main() { + for (let [sampleName, sampleMain] of samples) { + console.log("[samples] Running sample", sampleName); + await sampleMain(); + } +} + +main().catch((error) => { + console.error("[samples] An error occurred:", error); + process.exit(1); +}); diff --git a/sdk/storage/storage-blob/samples/javascript/sample.env b/sdk/storage/storage-blob/samples/javascript/sample.env new file mode 100644 index 000000000000..81e1cbbbd071 --- /dev/null +++ b/sdk/storage/storage-blob/samples/javascript/sample.env @@ -0,0 +1,14 @@ +# Used in most samples. Retrieve these values from a storage account in the Azure Portal. +ACCOUNT_NAME= +ACCOUNT_KEY= + +# Used for withConnString +STORAGE_CONNECTION_STRING= + +# Used for the advanced and anonymousCred tests. Create a SAS token for a storage account in the Azure Portal. +ACCOUNT_SAS= + +# Used to authenticate using Azure AD +AZURE_TENANT_ID= +AZURE_CLIENT_ID= +AZURE_CLIENT_SECRET= diff --git a/sdk/storage/storage-blob/samples/javascript/sampleHelpers.js b/sdk/storage/storage-blob/samples/javascript/sampleHelpers.js new file mode 100644 index 000000000000..4b68987083ea --- /dev/null +++ b/sdk/storage/storage-blob/samples/javascript/sampleHelpers.js @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +const dotenv = require("dotenv"); +dotenv.config(); + +module.exports = { + runSample(sampleMain) { + if (!process.env["BATCH_RUN_SAMPLES"]) { + return sampleMain(); + } else { + return Promise.resolve(); + } + } +}; diff --git a/sdk/storage/storage-blob/samples/javascript/sharedKeyCred.js b/sdk/storage/storage-blob/samples/javascript/sharedKeyCred.js index e6f25bc36463..f0a9b2dc1e23 100644 --- a/sdk/storage/storage-blob/samples/javascript/sharedKeyCred.js +++ b/sdk/storage/storage-blob/samples/javascript/sharedKeyCred.js @@ -1,8 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -const { BlobServiceClient, StorageSharedKeyCredential } = require("../.."); // Change to "@azure/storage-blob" in your package +const { BlobServiceClient, StorageSharedKeyCredential } = require("@azure/storage-blob"); + +const { runSample } = require("./sampleHelpers"); async function main() { // Enter your storage account name and shared key @@ -37,11 +42,8 @@ async function main() { console.log("deleted container"); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/withConnString.js b/sdk/storage/storage-blob/samples/javascript/withConnString.js index 08ebb18c5fa2..6244d986b614 100644 --- a/sdk/storage/storage-blob/samples/javascript/withConnString.js +++ b/sdk/storage/storage-blob/samples/javascript/withConnString.js @@ -1,8 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -const { BlobServiceClient } = require("../.."); // Change to "@azure/storage-blob" in your package +const { BlobServiceClient } = require("@azure/storage-blob"); + +const { runSample } = require("./sampleHelpers"); async function main() { // Create Blob Service Client from Account connection string or SAS connection string @@ -30,11 +35,8 @@ async function main() { console.log("deleted container"); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/tsconfig.json b/sdk/storage/storage-blob/samples/tsconfig.json index c01d1f002034..3a37abdb0902 100644 --- a/sdk/storage/storage-blob/samples/tsconfig.json +++ b/sdk/storage/storage-blob/samples/tsconfig.json @@ -1,13 +1,9 @@ { - "extends": "../tsconfig.json", - "compilerOptions": { - "module": "commonjs" - }, - "include": [ - "**/*.ts" - ], - "exclude": [ - "../node_modules", - "../typings/**", - ] -} \ No newline at end of file + "extends": "../tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "typescript/dist" + }, + "include": ["typescript/src/**.ts"], + "exclude": ["typescript/*.json", "**/node_modules/", "../node_modules", "../typings"] +} diff --git a/sdk/storage/storage-blob/samples/typescript/README.md b/sdk/storage/storage-blob/samples/typescript/README.md new file mode 100644 index 000000000000..f4a5b816995f --- /dev/null +++ b/sdk/storage/storage-blob/samples/typescript/README.md @@ -0,0 +1,104 @@ +--- +page_type: sample +languages: + - typescript +products: + - azure + - azure-storage +urlFragment: storage-blob-typescript +--- + +# Azure Storage Blob client library samples for TypeScript + +These sample programs show how to use the TypeScript client libraries for Azure Storage Blobs in some common scenarios. + +| **File Name** | **Description** | +| --------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [basic.ts][basic] | authenticate with the service using an account name & key (or anonymously with a SAS URL); create and delete containers; create, list, and download a blob | +| [withConnString.ts][withconnstring] | connect to and authenticate with the service using a connection string | +| [sharedKeyCred.ts][sharedkeycred] | authenticate with the service using an account name and a shared key | +| [anonymousCred.ts][anonymouscred] | authenticate with the service anonymously using a SAS URL | +| [azureAdAuth.ts][azureadauth] | authenticate with the service using Azure Active Directory | +| [proxyAuth.ts][proxyauth] | connect to the service using a proxy and authenticate with an account name & key | +| [iterators-blobs.ts][iterators-blobs] | different methods for iterating over blobs in a container, showing options for paging, resuming paging, etc. | +| [iterators-containers.ts][iterators-containers] | different methods for iterating over containers in an account, showing options for paging, resuming paging, etc. | +| [iterators-blobs-hierarchy.ts][iterators-blobs-hierarchy] | iterating over blobs by hierarchy, using separators in the blob names, showing options for paging, resuming paging, etc. | +| [customPipeline.ts][custompipeline] | use custom HTTP pipeline options when connecting to the service | +| [customizedClientHeaders.ts][customizedclientheaders] | use a custom request policy to add metadata to requests, in this case through the custom x-ms-client-request-id header | +| [errorsAndResponses.ts][errorsandresponses] | demonstrate various errors and responses | +| [readingSnapshot.ts][readingsnapshot] | create a blob snapshot and read from that snapshot | +| [advanced.ts][advanced] | use custom logging and pipeline options, then shows some example advanced options when creating containers, listing and downloading blobs, etc. | + +## Prerequisites + +The samples are compatible with Node.js >= 8.0.0, except for the samples that use the async `for await` syntax, which require a Node.js >= 10.0.0. + +Before running the samples in Node, they must be compiled to JavaScript using the TypeScript compiler. For more information on TypeScript, see the [TypeScript documentation][typescript]. Install the TypeScript compiler using + +```bash +npm install -g typescript +``` + +You need [an Azure subscription][freesub] and [an Azure Storage account][azstorage] to run these sample programs. Samples retrieve credentials to access the storage account from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function. + +Adapting the samples to run in the browser requires some additional consideration. For details, please see the [package README][package]. + +## Setup + +To run the samples using the published version of the package: + +1. Install the dependencies using `npm`: + +```bash +npm install +``` + +2. Compile the samples + +```bash +npm run build +``` + +3. Edit the file `sample.env`, adding the correct credentials to access the Azure service and run the samples. Then rename the file from `sample.env` to just `.env`. The sample programs will read this file automatically. + +4. Run whichever samples you like (note that some samples may require additional setup, see the table above): + +```bash +node dist/basic.js +``` + +Alternatively, run a single sample with the correct environment variables set (step 3 is not required if you do this), for example (cross-platform): + +```bash +npx cross-env ACCOUNT_NAME="" ACCOUNT_KEY="" node dist/basic.js +``` + +Or, to run all of the samples, use the following npm command: + +```bash +npm run execute:all +``` + +## Next Steps + +Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients. + +[advanced]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/typescript/src/advanced.ts +[anonymouscred]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/typescript/src/anonymousCred.ts +[azureadauth]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/typescript/src/azureAdAuth.ts +[basic]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/typescript/src/basic.ts +[customizedclientheaders]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/typescript/src/customizedClientHeaders.ts +[custompipeline]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/typescript/src/customPipeline.ts +[errorsandresponses]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/typescript/src/errorsAndResponses.ts +[iterators-blobs-hierarchy]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/typescript/src/iterators-blobs-hierarchy.ts +[iterators-blobs]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/typescript/src/iterators-blobs.ts +[iterators-containers]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/typescript/src/iterators-containers.ts +[proxyauth]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/typescript/src/proxyAuth.ts +[readingsnapshot]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/typescript/src/readingSnapshot.ts +[sharedkeycred]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/typescript/src/sharedKeyCred.ts +[withconnstring]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/typescript/src/withConnString.ts +[apiref]: https://docs.microsoft.com/javascript/api/@azure/storage-file-share +[azstorage]: https://docs.microsoft.com/azure/storage/common/storage-account-overview +[freesub]: https://azure.microsoft.com/free/ +[package]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-file-share/README.md +[typescript]: https://www.typescriptlang.org/docs/home.html diff --git a/sdk/storage/storage-blob/samples/typescript/package.json b/sdk/storage/storage-blob/samples/typescript/package.json new file mode 100644 index 000000000000..3b947a61a8ed --- /dev/null +++ b/sdk/storage/storage-blob/samples/typescript/package.json @@ -0,0 +1,45 @@ +{ + "name": "azure-storage-blob-samples-ts", + "private": true, + "version": "0.1.0", + "description": "Azure Storage Blob client library samples for TypeScript", + "engine": { + "node": ">=8.0.0" + }, + "scripts": { + "build": "tsc", + "prebuild": "rimraf dist/", + "execute:all": "npm run build && cross-env BATCH_RUN_SAMPLES=true node dist/run.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Azure/azure-sdk-for-js.git" + }, + "keywords": [ + "Azure", + "Storage", + "Blob", + "Node.js", + "TypeScript" + ], + "author": "Microsoft Corporation", + "license": "MIT", + "bugs": { + "url": "https://github.com/Azure/azure-sdk-for-js/issues" + }, + "homepage": "https://github.com/Azure/azure-sdk-for-js#readme", + "sideEffects": false, + "dependencies": { + "@azure/abort-controller": "latest", + "@azure/identity": "latest", + "@azure/storage-blob": "latest", + "dotenv": "^8.2.0" + }, + "devDependencies": { + "@types/node": "^8.0.0", + "cross-env": "^6.0.3", + "rimraf": "^3.0.0", + "ts-node": "^8.3.0", + "typescript": "~3.6.4" + } +} diff --git a/sdk/storage/storage-blob/samples/typescript/sample.env b/sdk/storage/storage-blob/samples/typescript/sample.env new file mode 100644 index 000000000000..81e1cbbbd071 --- /dev/null +++ b/sdk/storage/storage-blob/samples/typescript/sample.env @@ -0,0 +1,14 @@ +# Used in most samples. Retrieve these values from a storage account in the Azure Portal. +ACCOUNT_NAME= +ACCOUNT_KEY= + +# Used for withConnString +STORAGE_CONNECTION_STRING= + +# Used for the advanced and anonymousCred tests. Create a SAS token for a storage account in the Azure Portal. +ACCOUNT_SAS= + +# Used to authenticate using Azure AD +AZURE_TENANT_ID= +AZURE_CLIENT_ID= +AZURE_CLIENT_SECRET= diff --git a/sdk/storage/storage-blob/samples/typescript/advanced.ts b/sdk/storage/storage-blob/samples/typescript/src/advanced.ts similarity index 92% rename from sdk/storage/storage-blob/samples/typescript/advanced.ts rename to sdk/storage/storage-blob/samples/typescript/src/advanced.ts index 2c0a12859f13..a5b17b39d924 100644 --- a/sdk/storage/storage-blob/samples/typescript/advanced.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/advanced.ts @@ -1,10 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name, SAS and a path pointing to local file in main() */ -import fs from "fs"; +import * as fs from "fs"; import { AbortController } from "@azure/abort-controller"; -import { AnonymousCredential, BlobServiceClient, newPipeline } from "../../src"; // Change to "@azure/storage-blob" in your package +import { AnonymousCredential, BlobServiceClient, newPipeline } from "@azure/storage-blob"; // Enabling logging may help uncover useful information about failures. // In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. @@ -13,11 +16,13 @@ import { AnonymousCredential, BlobServiceClient, newPipeline } from "../../src"; import { setLogLevel } from "@azure/logger"; setLogLevel("info"); -async function main() { +import { runSample } from "./sampleHelpers"; + +export async function main() { // Fill in following settings before running this sample const account = process.env.ACCOUNT_NAME || ""; const accountSas = process.env.ACCOUNT_SAS || ""; - const localFilePath = "../README.md"; + const localFilePath = "README.md"; const pipeline = newPipeline(new AnonymousCredential(), { // httpClient: MyHTTPClient, // A customized HTTP client implementing IHttpClient interface @@ -127,11 +132,6 @@ async function main() { console.log("deleted container"); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-blob/samples/typescript/anonymousCred.ts b/sdk/storage/storage-blob/samples/typescript/src/anonymousCred.ts similarity index 75% rename from sdk/storage/storage-blob/samples/typescript/anonymousCred.ts rename to sdk/storage/storage-blob/samples/typescript/src/anonymousCred.ts index f8919c17eafb..22873ba7b1ff 100644 --- a/sdk/storage/storage-blob/samples/typescript/anonymousCred.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/anonymousCred.ts @@ -1,10 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and SAS in main() */ -import { BlobServiceClient, AnonymousCredential } from "../../src"; // Change to "@azure/storage-blob" in your package +import { BlobServiceClient, AnonymousCredential } from "@azure/storage-blob"; + +import { runSample } from "./sampleHelpers"; -async function main() { +export async function main() { // Enter your storage account name and SAS const account = process.env.ACCOUNT_NAME || ""; const accountSas = process.env.ACCOUNT_SAS || ""; @@ -37,11 +42,6 @@ async function main() { console.log("deleted container"); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-blob/samples/typescript/azureAdAuth.ts b/sdk/storage/storage-blob/samples/typescript/src/azureAdAuth.ts similarity index 89% rename from sdk/storage/storage-blob/samples/typescript/azureAdAuth.ts rename to sdk/storage/storage-blob/samples/typescript/src/azureAdAuth.ts index e159ae373d70..ae8614ff4550 100644 --- a/sdk/storage/storage-blob/samples/typescript/azureAdAuth.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/azureAdAuth.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* ONLY AVAILABLE IN NODE.JS RUNTIME @@ -18,10 +21,12 @@ - Make sure you have AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET as environment variables to successfully execute the sample(Can leverage process.env). */ -import { BlobServiceClient } from "../../src"; // Change to "@azure/storage-blob" in your package +import { BlobServiceClient } from "@azure/storage-blob"; import { DefaultAzureCredential } from "@azure/identity"; -async function main() { +import { runSample } from "./sampleHelpers"; + +export async function main() { // Enter your storage account name const account = process.env.ACCOUNT_NAME || ""; @@ -51,11 +56,6 @@ async function main() { console.log(`Created container ${containerName} successfully`, createContainerResponse.requestId); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed the sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-blob/samples/typescript/basic.ts b/sdk/storage/storage-blob/samples/typescript/src/basic.ts similarity index 90% rename from sdk/storage/storage-blob/samples/typescript/basic.ts rename to sdk/storage/storage-blob/samples/typescript/src/basic.ts index 6ef1c2e7d155..a5c76c7f8f74 100644 --- a/sdk/storage/storage-blob/samples/typescript/basic.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/basic.ts @@ -1,10 +1,19 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -import { BlobServiceClient, StorageSharedKeyCredential, BlobDownloadResponseModel } from "../../src"; // Change to "@azure/storage-blob" in your package +import { + BlobServiceClient, + StorageSharedKeyCredential, + BlobDownloadResponseModel +} from "@azure/storage-blob"; + +import { runSample } from "./sampleHelpers"; -async function main() { +export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; @@ -94,11 +103,6 @@ async function streamToString(readableStream: NodeJS.ReadableStream) { }); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-blob/samples/typescript/customPipeline.ts b/sdk/storage/storage-blob/samples/typescript/src/customPipeline.ts similarity index 83% rename from sdk/storage/storage-blob/samples/typescript/customPipeline.ts rename to sdk/storage/storage-blob/samples/typescript/src/customPipeline.ts index 024a03a641d9..5832ecbc9f51 100644 --- a/sdk/storage/storage-blob/samples/typescript/customPipeline.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/customPipeline.ts @@ -1,10 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -import { BlobServiceClient, StorageSharedKeyCredential, newPipeline } from "../../src"; // Change to "@azure/storage-blob" in your package +import { BlobServiceClient, StorageSharedKeyCredential, newPipeline } from "@azure/storage-blob"; + +import { runSample } from "./sampleHelpers"; -async function main() { +export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; @@ -44,11 +49,6 @@ async function main() { console.log("deleted container"); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-blob/samples/typescript/customizedClientHeaders.ts b/sdk/storage/storage-blob/samples/typescript/src/customizedClientHeaders.ts similarity index 86% rename from sdk/storage/storage-blob/samples/typescript/customizedClientHeaders.ts rename to sdk/storage/storage-blob/samples/typescript/src/customizedClientHeaders.ts index f8e9dc41daba..ec57fb0bcd83 100644 --- a/sdk/storage/storage-blob/samples/typescript/customizedClientHeaders.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/customizedClientHeaders.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* You can create your own policy and inject it into the default pipeline, or create your own Pipeline. A request policy is a filter triggered before and after a HTTP request. With a filter, we can tweak HTTP requests and responses. @@ -17,7 +20,9 @@ import { WebResource, RequestPolicy, RequestPolicyOptions -} from "../../src"; // Change to "@azure/storage-blob" in your package +} from "@azure/storage-blob"; + +import { runSample } from "./sampleHelpers"; // Create a policy factory with create() method provided class RequestIDPolicyFactory { @@ -60,7 +65,7 @@ class RequestIDPolicy extends BaseRequestPolicy { } // Main function -async function main() { +export async function main() { const account = process.env.ACCOUNT_NAME || ""; const accountSas = process.env.ACCOUNT_SAS || ""; @@ -74,17 +79,17 @@ async function main() { `https://${account}.blob.core.windows.net${accountSas}`, pipeline ); - const response = (await blobServiceClient - .listContainers() - .byPage() - .next()).value; + const response = ( + await blobServiceClient + .listContainers() + .byPage() + .next() + ).value; // Check customized client request ID console.log(response._response.request.headers.get("x-ms-client-request-id")); } -main() - .then(() => { - console.log("Successfully executed sample"); - }) - .catch(console.error); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-blob/samples/typescript/errorsAndResponses.ts b/sdk/storage/storage-blob/samples/typescript/src/errorsAndResponses.ts similarity index 94% rename from sdk/storage/storage-blob/samples/typescript/errorsAndResponses.ts rename to sdk/storage/storage-blob/samples/typescript/src/errorsAndResponses.ts index d83f8c80ad57..701459546b4b 100644 --- a/sdk/storage/storage-blob/samples/typescript/errorsAndResponses.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/errorsAndResponses.ts @@ -1,10 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter connection string of your storage account name in main() */ -import { BlobServiceClient } from "../../src"; // Change to "@azure/storage-blob" in your package +import { BlobServiceClient } from "@azure/storage-blob"; + +import { runSample } from "./sampleHelpers"; -async function main() { +export async function main() { // Create Blob Service Client from Account connection string or SAS connection string // Account connection string example - `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net` // SAS connection string example - `BlobEndpoint=https://myaccount.blob.core.windows.net/;QueueEndpoint=https://myaccount.queue.core.windows.net/;FileEndpoint=https://myaccount.file.core.windows.net/;TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sasString` @@ -145,11 +150,6 @@ async function streamToString(readableStream: NodeJS.ReadableStream) { }); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("\n\nSuccessfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-blob/samples/typescript/iterators-blobs-hierarchy.ts b/sdk/storage/storage-blob/samples/typescript/src/iterators-blobs-hierarchy.ts similarity index 92% rename from sdk/storage/storage-blob/samples/typescript/iterators-blobs-hierarchy.ts rename to sdk/storage/storage-blob/samples/typescript/src/iterators-blobs-hierarchy.ts index 7300db67379c..c082475fdeb8 100644 --- a/sdk/storage/storage-blob/samples/typescript/iterators-blobs-hierarchy.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/iterators-blobs-hierarchy.ts @@ -1,10 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -import { BlobServiceClient, StorageSharedKeyCredential } from "../../src"; // Change to "@azure/storage-blob" in your package +import { BlobServiceClient, StorageSharedKeyCredential } from "@azure/storage-blob"; + +import { runSample } from "./sampleHelpers"; -async function main() { +export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; @@ -131,11 +136,6 @@ async function main() { console.log("deleted container"); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed the sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-blob/samples/typescript/iterators-blobs.ts b/sdk/storage/storage-blob/samples/typescript/src/iterators-blobs.ts similarity index 91% rename from sdk/storage/storage-blob/samples/typescript/iterators-blobs.ts rename to sdk/storage/storage-blob/samples/typescript/src/iterators-blobs.ts index b443ae27020e..791fdd72f7f8 100644 --- a/sdk/storage/storage-blob/samples/typescript/iterators-blobs.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/iterators-blobs.ts @@ -1,10 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -import { BlobServiceClient, StorageSharedKeyCredential } from "../../src"; // Change to "@azure/storage-blob" in your package +import { BlobServiceClient, StorageSharedKeyCredential } from "@azure/storage-blob"; + +import { runSample } from "./sampleHelpers"; -async function main() { +export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; @@ -122,11 +127,6 @@ async function main() { console.log("deleted container"); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed the sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-blob/samples/typescript/iterators-containers.ts b/sdk/storage/storage-blob/samples/typescript/src/iterators-containers.ts similarity index 89% rename from sdk/storage/storage-blob/samples/typescript/iterators-containers.ts rename to sdk/storage/storage-blob/samples/typescript/src/iterators-containers.ts index 354feb380419..4bc8a18d53ec 100644 --- a/sdk/storage/storage-blob/samples/typescript/iterators-containers.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/iterators-containers.ts @@ -1,10 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -import { BlobServiceClient, StorageSharedKeyCredential } from "../../src"; // Change to "@azure/storage-blob" in your package +import { BlobServiceClient, StorageSharedKeyCredential } from "@azure/storage-blob"; + +import { runSample } from "./sampleHelpers"; -async function main() { +export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; @@ -103,11 +108,6 @@ async function main() { } } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed the sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-blob/samples/typescript/proxyAuth.ts b/sdk/storage/storage-blob/samples/typescript/src/proxyAuth.ts similarity index 77% rename from sdk/storage/storage-blob/samples/typescript/proxyAuth.ts rename to sdk/storage/storage-blob/samples/typescript/src/proxyAuth.ts index 43a3e29a4f25..f739306d8bed 100644 --- a/sdk/storage/storage-blob/samples/typescript/proxyAuth.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/proxyAuth.ts @@ -1,10 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -import { BlobServiceClient, StorageSharedKeyCredential } from "../../src"; // Change to "@azure/storage-blob" in your package +import { BlobServiceClient, StorageSharedKeyCredential } from "@azure/storage-blob"; + +import { runSample } from "./sampleHelpers"; -async function main() { +export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; @@ -38,11 +43,6 @@ async function main() { console.log(`Created container ${containerName} successfully`, createContainerResponse.requestId); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed the sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-blob/samples/typescript/readingSnapshot.ts b/sdk/storage/storage-blob/samples/typescript/src/readingSnapshot.ts similarity index 89% rename from sdk/storage/storage-blob/samples/typescript/readingSnapshot.ts rename to sdk/storage/storage-blob/samples/typescript/src/readingSnapshot.ts index 396d34b69597..7c2d7d5834a2 100644 --- a/sdk/storage/storage-blob/samples/typescript/readingSnapshot.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/readingSnapshot.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* If you use BlobClient.download() to download an append blob which is being actively appended, you may get a 412 HTTP error, just like this issue: https://github.com/Azure/azure-storage-js/issues/51 @@ -18,9 +21,11 @@ Setup: Enter your storage account name and shared key in main() */ -import { BlobServiceClient, StorageSharedKeyCredential } from "../../src"; // Change to "@azure/storage-blob" in your package +import { BlobServiceClient, StorageSharedKeyCredential } from "@azure/storage-blob"; + +import { runSample } from "./sampleHelpers"; -async function main() { +export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; @@ -82,11 +87,6 @@ async function streamToString(readableStream: NodeJS.ReadableStream) { }); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-blob/samples/typescript/src/run.ts b/sdk/storage/storage-blob/samples/typescript/src/run.ts new file mode 100644 index 000000000000..253d2bd3e862 --- /dev/null +++ b/sdk/storage/storage-blob/samples/typescript/src/run.ts @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { main as advancedMain } from "./advanced"; +import { main as anonymousCredMain } from "./anonymousCred"; +import { main as azureAdAuthMain } from "./azureAdAuth"; +import { main as basicMain } from "./basic"; +import { main as customizedClientHeadersMain } from "./customizedClientHeaders"; +import { main as customPipelineMain } from "./customPipeline"; +import { main as errorsAndResponsesMain } from "./errorsAndResponses"; +import { main as iteratorsBlobsHierarchyMain } from "./iterators-blobs-hierarchy"; +import { main as iteratorsBlobsMain } from "./iterators-blobs"; +import { main as iteratorsContainersMain } from "./iterators-containers"; +// import { main as proxyAuthMain } from "./proxyAuth"; +import { main as readingSnapshotMain } from "./readingSnapshot"; +import { main as sharedKeyCredMain } from "./sharedKeyCred"; +import { main as withConnStringMain } from "./withConnString"; + +import { config as dotenv } from "dotenv"; +dotenv(); + +const samples: Array<[string, () => Promise]> = [ + ["advanced", advancedMain], + ["anonymousCred", anonymousCredMain], + ["azureAdAuth", azureAdAuthMain], + ["basic", basicMain], + ["customizedClientHeaders", customizedClientHeadersMain], + ["customPipeline", customPipelineMain], + ["errorsAndResponses", errorsAndResponsesMain], + ["iterators-blobs-hierarchy", iteratorsBlobsHierarchyMain], + ["iterators-blobs", iteratorsBlobsMain], + ["iterators-containers", iteratorsContainersMain], + // ["proxyAuth", proxyAuthMain], // Requires a proxy + ["readingSnapshot", readingSnapshotMain], + ["sharedKeyCred", sharedKeyCredMain], + ["withConnString", withConnStringMain] +]; + +async function main() { + for (let [sampleName, sampleMain] of samples) { + console.log("[samples] Running sample", sampleName); + await sampleMain(); + } +} + +main().catch((error) => { + console.error("[samples] An error occurred:", error); + process.exit(1); +}); diff --git a/sdk/storage/storage-blob/samples/typescript/src/sampleHelpers.ts b/sdk/storage/storage-blob/samples/typescript/src/sampleHelpers.ts new file mode 100644 index 000000000000..841754c05a42 --- /dev/null +++ b/sdk/storage/storage-blob/samples/typescript/src/sampleHelpers.ts @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import * as dotenv from "dotenv"; +dotenv.config(); + +export function runSample(sampleMain: () => Promise): Promise { + if (!process.env["BATCH_RUN_SAMPLES"]) { + return sampleMain(); + } else { + return Promise.resolve(); + } +} diff --git a/sdk/storage/storage-blob/samples/typescript/sharedKeyCred.ts b/sdk/storage/storage-blob/samples/typescript/src/sharedKeyCred.ts similarity index 75% rename from sdk/storage/storage-blob/samples/typescript/sharedKeyCred.ts rename to sdk/storage/storage-blob/samples/typescript/src/sharedKeyCred.ts index 9de6e9bd9908..321e7be21ddf 100644 --- a/sdk/storage/storage-blob/samples/typescript/sharedKeyCred.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/sharedKeyCred.ts @@ -1,10 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -import { BlobServiceClient, StorageSharedKeyCredential } from "../../src"; // Change to "@azure/storage-blob" in your package +import { BlobServiceClient, StorageSharedKeyCredential } from "@azure/storage-blob"; + +import { runSample } from "./sampleHelpers"; -async function main() { +export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; @@ -37,11 +42,6 @@ async function main() { console.log("deleted container"); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-blob/samples/typescript/withConnString.ts b/sdk/storage/storage-blob/samples/typescript/src/withConnString.ts similarity index 79% rename from sdk/storage/storage-blob/samples/typescript/withConnString.ts rename to sdk/storage/storage-blob/samples/typescript/src/withConnString.ts index 72f49ce0175f..41fc1bb55859 100644 --- a/sdk/storage/storage-blob/samples/typescript/withConnString.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/withConnString.ts @@ -1,10 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -import { BlobServiceClient } from "../../src"; // Change to "@azure/storage-blob" in your package +import { BlobServiceClient } from "@azure/storage-blob"; + +import { runSample } from "./sampleHelpers"; -async function main() { +export async function main() { // Create Blob Service Client from Account connection string or SAS connection string // Account connection string example - `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net` // SAS connection string example - `BlobEndpoint=https://myaccount.blob.core.windows.net/;QueueEndpoint=https://myaccount.queue.core.windows.net/;FileEndpoint=https://myaccount.file.core.windows.net/;TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sasString` @@ -30,11 +35,6 @@ async function main() { console.log("deleted container"); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-blob/samples/typescript/tsconfig.json b/sdk/storage/storage-blob/samples/typescript/tsconfig.json new file mode 100644 index 000000000000..4332663bf7b7 --- /dev/null +++ b/sdk/storage/storage-blob/samples/typescript/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "module": "commonjs", + "moduleResolution": "node", + + "lib": ["dom", "dom.iterable", "esnext.asynciterable"], + + "allowSyntheticDefaultImports": true, + + "outDir": "dist", + "rootDir": "src" + }, + "include": ["src/**.ts"], + "exclude": ["node_modules"] +} From 6ac61c7a6599f2e7ce496e62561ec3640addea39 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Wed, 11 Dec 2019 13:51:18 -0800 Subject: [PATCH 14/39] [samples] Moved run-samples to common/scripts --- common/scripts/prep-samples.js | 5 +- common/scripts/run-samples.js | 102 ++++++++++++++++++ .../samples/javascript/run.js | 41 ------- .../samples/typescript/src/run.ts | 41 ------- 4 files changed, 104 insertions(+), 85 deletions(-) create mode 100644 common/scripts/run-samples.js delete mode 100644 sdk/storage/storage-file-share/samples/javascript/run.js delete mode 100644 sdk/storage/storage-file-share/samples/typescript/src/run.ts diff --git a/common/scripts/prep-samples.js b/common/scripts/prep-samples.js index 3db3d6921533..2727d50b2821 100644 --- a/common/scripts/prep-samples.js +++ b/common/scripts/prep-samples.js @@ -33,16 +33,15 @@ const fs = return { readdir: promisify(baseFS.readdir), readFile: promisify(baseFS.readFile), - stat: promisify(baseFS.stat), writeFile: promisify(baseFS.writeFile) }; })(); /** - * Breadth-first search for files ending in .ts, starting from `tsDir` + * Breadth-first search for files matching a given predicate * * @param {string} tsDir The root of the sample tree to search - * @param {(fs.Entry) => boolean} Predicate that decides whether or not a file entry is included + * @param {(fs.Entry) => boolean} matches Predicate that decides whether or not a file entry is included * @returns */ async function* findMatchingFiles(tsDir, matches) { diff --git a/common/scripts/run-samples.js b/common/scripts/run-samples.js new file mode 100644 index 000000000000..5481c26057be --- /dev/null +++ b/common/scripts/run-samples.js @@ -0,0 +1,102 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +/** + * run-samples.js + * + * Runs all JavaScript files in a directory, using the calling convention for + * our sample code. + */ + +const baseFS = require("fs"); +const path = require("path"); + +const IGNORE = ["node_modules", "sampleHelpers.js"]; + +// Node >= 10 provide fs.promises, but since we're still building Node 8 for now +// we need to use util.promisify if fs.promises doesn't exist +const fs = + baseFS.promises || + (() => { + const promisify = require("util").promisify; + return { + readdir: promisify(baseFS.readdir) + }; + })(); + +/** + * Breadth-first search for files matching a given predicate + * + * @param {string} tsDir The root of the sample tree to search + * @param {(fs.Entry) => boolean} matches Predicate that decides whether or not a file entry is included + * @returns + */ +async function* findMatchingFiles(tsDir, matches) { + const initialFiles = await fs.readdir(tsDir, { withFileTypes: true }); + + // BFS Queue and queue index + const q = initialFiles.map(f => [f, tsDir]); + + while (q.length) { + // [fs.Dirent, string] (file and dirName part of the full path) + const [entry, dirName] = q.shift(); + const fullPath = path.join(dirName, entry.name); + + if (IGNORE.includes(entry.name)) { + console.log("[run-samples] Ignoring", fullPath); + } + + if (entry.isDirectory()) { + // Enqueue children of this directory to the bfs + const children = await fs.readdir(fullPath, { withFileTypes: true }); + for (const child of children) { + q.push([child, fullPath]); + } + } else if (matches(entry)) { + yield fullPath; + } else { + console.log("[run-samples] Skipping", fullPath); + } + } + + // The full trace of files visited by the iterator is returned and can be accessed using `iter.value` + // once it is `done`, in case it is ever needed for debugging + return q; +} + +async function main() { + // Accept a base directory + const args = process.argv.slice(2); + + let sampleDir; + if (args.length) { + sampleDir = path.resolve(args[0]); + } else { + sampleDir = process.cwd(); + } + + // Patch the environment for the sample helper + process.env.BATCH_RUN_SAMPLES = "true"; + + console.log("[run-samples] Running all samples in:", baseDir); + + for await (const fileName of findMatchingFiles( + sampleDir, + entry => entry.isFile() && entry.name.endsWith(".js") + )) { + console.log("[run-samples] Running", fileName); + const { sampleMain } = require(fileName); + try { + await sampleMain(); + } catch (err) { + console.error("[run-samples] Error in", fileName); + console.error(err); + console.warn("[run-samples] Continuing ..."); + } + } +} + +main().catch(err => { + console.error("[prep-samples] Error:", err); + process.exit(1); +}); diff --git a/sdk/storage/storage-file-share/samples/javascript/run.js b/sdk/storage/storage-file-share/samples/javascript/run.js deleted file mode 100644 index fe3a2c361536..000000000000 --- a/sdk/storage/storage-file-share/samples/javascript/run.js +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -const { main: advancedMain } = require("./advanced"); -const { main: anonymousCredMain } = require("./anonymousCred"); -const { main: basicMain } = require("./basic"); -const { main: customPipelineMain } = require("./customPipeline"); -const { main: iteratorsFilesAndDirectoriesMain } = require("./iterators-files-and-directories"); -// const { main: iteratorsHandlesMain } = require("./iterators-handles"); -const { main: iteratorsSharesMain } = require("./iterators-shares"); -// const { main: proxyAuthMain } = require("./proxyAuth"); -const { main: sharedKeyCredMain } = require("./sharedKeyCred"); -const { main: withConnStringMain } = require("./withConnString"); - -const { config: dotenv } = require("dotenv"); -dotenv(); - -const samples = [ - ["advanced", advancedMain], - ["anonymousCred", anonymousCredMain], - ["basic", basicMain], - ["customPipeline", customPipelineMain], - ["iterators-files-and-directories", iteratorsFilesAndDirectoriesMain], - // ["iterators-handles", iteratorsHandlesMain], // Must be populated with a pre-existing share/directory name to run - ["iterators-shares", iteratorsSharesMain], - // ["proxyAuth", proxyAuthMain], // Requires a proxy - ["sharedKeyCred", sharedKeyCredMain], - ["withConnString", withConnStringMain] -]; - -async function main() { - for (let [sampleName, sampleMain] of samples) { - console.log("[samples] Running sample", sampleName); - await sampleMain(); - } -} - -main().catch((error) => { - console.error("[samples] An error occurred:", error); - process.exit(1); -}); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/run.ts b/sdk/storage/storage-file-share/samples/typescript/src/run.ts deleted file mode 100644 index 6ed649b99556..000000000000 --- a/sdk/storage/storage-file-share/samples/typescript/src/run.ts +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -import { main as advancedMain } from "./advanced"; -import { main as anonymousCredMain } from "./anonymousCred"; -import { main as basicMain } from "./basic"; -import { main as customPipelineMain } from "./customPipeline"; -import { main as iteratorsFilesAndDirectoriesMain } from "./iterators-files-and-directories"; -// import { main as iteratorsHandlesMain } from "./iterators-handles"; -import { main as iteratorsSharesMain } from "./iterators-shares"; -// import { main as proxyAuthMain } from "./proxyAuth"; -import { main as sharedKeyCredMain } from "./sharedKeyCred"; -import { main as withConnStringMain } from "./withConnString"; - -import { config as dotenv } from "dotenv"; -dotenv(); - -const samples: Array<[string, () => Promise]> = [ - ["advanced", advancedMain], - ["anonymousCred", anonymousCredMain], - ["basic", basicMain], - ["customPipeline", customPipelineMain], - ["iterators-files-and-directories", iteratorsFilesAndDirectoriesMain], - // ["iterators-handles", iteratorsHandlesMain], // Must be populated with a pre-existing share/directory name to run - ["iterators-shares", iteratorsSharesMain], - // ["proxyAuth", proxyAuthMain], // Requires a proxy - ["sharedKeyCred", sharedKeyCredMain], - ["withConnString", withConnStringMain] -]; - -async function main() { - for (let [sampleName, sampleMain] of samples) { - console.log("[samples] Running sample", sampleName); - await sampleMain(); - } -} - -main().catch((error) => { - console.error("[samples] An error occurred:", error); - process.exit(1); -}); From 12b3d0072a2d6cfffe4449acc14342b5feaace8c Mon Sep 17 00:00:00 2001 From: Will Temple Date: Wed, 11 Dec 2019 14:16:49 -0800 Subject: [PATCH 15/39] [storage-file-share] Changed proxyAuth samples to exit if proxy information is not provided. --- common/scripts/run-samples.js | 4 +-- sdk/storage/storage-file-share/package.json | 4 +-- .../samples/javascript/proxyAuth.js | 25 ++++++++++++------- .../samples/typescript/src/proxyAuth.ts | 25 ++++++++++++------- 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/common/scripts/run-samples.js b/common/scripts/run-samples.js index 5481c26057be..0c31f7d37f41 100644 --- a/common/scripts/run-samples.js +++ b/common/scripts/run-samples.js @@ -78,14 +78,14 @@ async function main() { // Patch the environment for the sample helper process.env.BATCH_RUN_SAMPLES = "true"; - console.log("[run-samples] Running all samples in:", baseDir); + console.log("[run-samples] Running all samples in:", sampleDir); for await (const fileName of findMatchingFiles( sampleDir, entry => entry.isFile() && entry.name.endsWith(".js") )) { console.log("[run-samples] Running", fileName); - const { sampleMain } = require(fileName); + const { main: sampleMain } = require(fileName); try { await sampleMain(); } catch (err) { diff --git a/sdk/storage/storage-file-share/package.json b/sdk/storage/storage-file-share/package.json index 4d64b462b2ee..02cdefcb9d66 100644 --- a/sdk/storage/storage-file-share/package.json +++ b/sdk/storage/storage-file-share/package.json @@ -31,8 +31,8 @@ "clean": "rimraf dist dist-esm dist-test typings temp browser/*.js* browser/*.zip statistics.html coverage coverage-browser .nyc_output *.tgz *.log test*.xml TEST*.xml", "clean:samples": "rimraf samples/javascript/node_modules samples/typescript/node_modules samples/typescript/dist samples/typescript/package-lock.json samples/javascript/package-lock.json", "extract-api": "tsc -p . && api-extractor run --local", - "execute:js-samples": "cross-env BATCH_RUN_SAMPLES=true node samples/javascript/run.js", - "execute:ts-samples": "cross-env BATCH_RUN_SAMPLES=true node samples/typescript/dist/samples/typescript/src/run.js", + "execute:js-samples": "node ../../../common/scripts/run-samples.js samples/javascript/", + "execute:ts-samples": "node ../../../common/scripts/run-samples.js samples/typescript/dist/samples/typescript/src/", "execute:samples": "npm run build:samples && npm run execute:js-samples && npm run execute:ts-samples", "format": "prettier --write --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", "integration-test:browser": "karma start --single-run", diff --git a/sdk/storage/storage-file-share/samples/javascript/proxyAuth.js b/sdk/storage/storage-file-share/samples/javascript/proxyAuth.js index d2ff7b39bad7..2714c1158f3e 100644 --- a/sdk/storage/storage-file-share/samples/javascript/proxyAuth.js +++ b/sdk/storage/storage-file-share/samples/javascript/proxyAuth.js @@ -18,20 +18,27 @@ async function main() { // StorageSharedKeyCredential is only avaiable in Node.js runtime, not in browsers const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey); + // Enter your proxy information + const proxyOptions = { + host: process.env.PROXY_HOST || "", + port: parseInt(process.env.PROXY_PORT || "3128"), + username: process.env.PROXY_USERNAME || "", + password: process.env.PROXY_PASSWORD || "" + }; + + if (proxyOptions.host === "") { + console.error( + "Error: Proxy information not provided, but it is required to run this sample. Exiting." + ); + process.exit(); + } + const serviceClient = new ShareServiceClient( `https://${account}.file.core.windows.net`, sharedKeyCredential, { - // proxy can either be a URL like "http://localhost:3128" - // or - // an option bag consisting {host, port, username, password } - proxyOptions: { - host: "http://localhost", - port: 3128, - username: "username", - password: "password" - } // if proxy is undefined, the library tries to load the proxy settings from the environment variables like HTTP_PROXY + proxyOptions } ); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts b/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts index 6a92e17e7b34..005632f9882a 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts @@ -14,6 +14,21 @@ export async function main() { const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; + // Enter your proxy information + const proxyOptions = { + host: process.env.PROXY_HOST || "", + port: parseInt(process.env.PROXY_PORT || "3128"), + username: process.env.PROXY_USERNAME || "", + password: process.env.PROXY_PASSWORD || "" + }; + + if (proxyOptions.host === "") { + console.error( + "Error: Proxy information not provided, but it is required to run this sample. Exiting." + ); + process.exit(); + } + // Use StorageSharedKeyCredential with storage account and account key // StorageSharedKeyCredential is only avaiable in Node.js runtime, not in browsers const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey); @@ -22,16 +37,8 @@ export async function main() { `https://${account}.file.core.windows.net`, sharedKeyCredential, { - // proxy can either be a URL like "http://localhost:3128" - // or - // an option bag consisting {host, port, username, password } - proxyOptions: { - host: "http://localhost", - port: 3128, - username: "username", - password: "password" - } // if proxy is undefined, the library tries to load the proxy settings from the environment variables like HTTP_PROXY + proxyOptions } ); From 5465f4cc62c56bc0e71bf1d39ae04708811f462f Mon Sep 17 00:00:00 2001 From: Will Temple Date: Wed, 11 Dec 2019 14:24:28 -0800 Subject: [PATCH 16/39] [storage-file-share] changed iterators-handles to exit if share/directory information is not provided with a nice error --- .../samples/javascript/iterators-handles.js | 10 ++++++++-- .../samples/typescript/src/iterators-handles.ts | 12 +++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/sdk/storage/storage-file-share/samples/javascript/iterators-handles.js b/sdk/storage/storage-file-share/samples/javascript/iterators-handles.js index c3a810a7e8b4..b45eb3ab7abc 100644 --- a/sdk/storage/storage-file-share/samples/javascript/iterators-handles.js +++ b/sdk/storage/storage-file-share/samples/javascript/iterators-handles.js @@ -17,8 +17,14 @@ async function main() { // https://docs.microsoft.com/en-us/azure/storage/files/storage-how-to-use-files-mac const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; - const shareName = ""; - const dirName = ""; + const shareName = process.env.SHARE_NAME || ""; + const dirName = process.env.DIR_NAME || ""; + + if (shareName === "" || dirName === "") { + throw new Error( + "Share/directory information not provided, but it is required to run this sample." + ); + } // Use StorageSharedKeyCredential with storage account and account key // StorageSharedKeyCredential is only avaiable in Node.js runtime, not in browsers diff --git a/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts b/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts index 951aa742d6cb..a6bd6f0779e9 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts @@ -5,7 +5,7 @@ Setup: Enter your storage account name and shared key in main() */ -import { ShareServiceClient, StorageSharedKeyCredential } from "@azure/storage-file-share"; +import { ShareServiceClient, StorageSharedKeyCredential } from "../../../src"; import { runSample } from "./sampleHelpers"; @@ -17,8 +17,14 @@ export async function main() { // https://docs.microsoft.com/en-us/azure/storage/files/storage-how-to-use-files-mac const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; - const shareName = ""; - const dirName = ""; + const shareName = process.env.SHARE_NAME || ""; + const dirName = process.env.DIR_NAME || ""; + + if (shareName === "" || dirName === "") { + throw new Error( + "Share/directory information not provided, but it is required to run this sample." + ); + } // Use StorageSharedKeyCredential with storage account and account key // StorageSharedKeyCredential is only avaiable in Node.js runtime, not in browsers From 8039b803cc61ef28339ec5461a1031489004bf49 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Wed, 11 Dec 2019 14:26:41 -0800 Subject: [PATCH 17/39] [run-samples] Error handling --- common/scripts/run-samples.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common/scripts/run-samples.js b/common/scripts/run-samples.js index 0c31f7d37f41..b6f4f1fce2c3 100644 --- a/common/scripts/run-samples.js +++ b/common/scripts/run-samples.js @@ -80,6 +80,8 @@ async function main() { console.log("[run-samples] Running all samples in:", sampleDir); + let didError = false; + for await (const fileName of findMatchingFiles( sampleDir, entry => entry.isFile() && entry.name.endsWith(".js") @@ -89,14 +91,19 @@ async function main() { try { await sampleMain(); } catch (err) { + didError = true; console.error("[run-samples] Error in", fileName); console.error(err); console.warn("[run-samples] Continuing ..."); } } + + if (didError) { + throw new Error("errors occurred during sample execution"); + } } main().catch(err => { - console.error("[prep-samples] Error:", err); + console.error("[run-samples] Error:", err); process.exit(1); }); From e5522113771e9b8e05fcd32b24a993568e8a650b Mon Sep 17 00:00:00 2001 From: Will Temple Date: Wed, 11 Dec 2019 14:31:24 -0800 Subject: [PATCH 18/39] [storage-file-share] Fixed sample errors due to prep-samples tree contamination --- .../samples/typescript/src/iterators-handles.ts | 2 +- .../storage-file-share/samples/typescript/src/proxyAuth.ts | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts b/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts index a6bd6f0779e9..ab008f242042 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts @@ -5,7 +5,7 @@ Setup: Enter your storage account name and shared key in main() */ -import { ShareServiceClient, StorageSharedKeyCredential } from "../../../src"; +import { ShareServiceClient, StorageSharedKeyCredential } from "@azure/storage-file-share"; import { runSample } from "./sampleHelpers"; diff --git a/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts b/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts index 005632f9882a..6f8f63e88c82 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts @@ -23,10 +23,7 @@ export async function main() { }; if (proxyOptions.host === "") { - console.error( - "Error: Proxy information not provided, but it is required to run this sample. Exiting." - ); - process.exit(); + throw new Error("Proxy information not provided, but it is required to run this sample."); } // Use StorageSharedKeyCredential with storage account and account key From b77c6b436f5176f01846aa815bb0d151763ea2d0 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Wed, 11 Dec 2019 14:35:25 -0800 Subject: [PATCH 19/39] [storage-file-share] Changed from exceptions to a simple return in cases that should not halt CI --- .../samples/javascript/iterators-handles.js | 5 +++-- .../storage-file-share/samples/javascript/proxyAuth.js | 6 ++---- .../samples/typescript/src/iterators-handles.ts | 5 +++-- .../storage-file-share/samples/typescript/src/proxyAuth.ts | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/sdk/storage/storage-file-share/samples/javascript/iterators-handles.js b/sdk/storage/storage-file-share/samples/javascript/iterators-handles.js index b45eb3ab7abc..d5701e2730df 100644 --- a/sdk/storage/storage-file-share/samples/javascript/iterators-handles.js +++ b/sdk/storage/storage-file-share/samples/javascript/iterators-handles.js @@ -21,9 +21,10 @@ async function main() { const dirName = process.env.DIR_NAME || ""; if (shareName === "" || dirName === "") { - throw new Error( - "Share/directory information not provided, but it is required to run this sample." + console.warn( + "Share/directory information not provided, but it is required to run this sample. Exiting." ); + return; } // Use StorageSharedKeyCredential with storage account and account key diff --git a/sdk/storage/storage-file-share/samples/javascript/proxyAuth.js b/sdk/storage/storage-file-share/samples/javascript/proxyAuth.js index 2714c1158f3e..fbc8f22f1f08 100644 --- a/sdk/storage/storage-file-share/samples/javascript/proxyAuth.js +++ b/sdk/storage/storage-file-share/samples/javascript/proxyAuth.js @@ -27,10 +27,8 @@ async function main() { }; if (proxyOptions.host === "") { - console.error( - "Error: Proxy information not provided, but it is required to run this sample. Exiting." - ); - process.exit(); + console.warn("Proxy information not provided, but it is required to run this sample. Exiting."); + return; } const serviceClient = new ShareServiceClient( diff --git a/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts b/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts index ab008f242042..acde9f1e045b 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts @@ -21,9 +21,10 @@ export async function main() { const dirName = process.env.DIR_NAME || ""; if (shareName === "" || dirName === "") { - throw new Error( - "Share/directory information not provided, but it is required to run this sample." + console.warn( + "Share/directory information not provided, but it is required to run this sample. Exiting." ); + return; } // Use StorageSharedKeyCredential with storage account and account key diff --git a/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts b/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts index 6f8f63e88c82..396a351e664a 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts @@ -23,7 +23,8 @@ export async function main() { }; if (proxyOptions.host === "") { - throw new Error("Proxy information not provided, but it is required to run this sample."); + console.warn("Proxy information not provided, but it is required to run this sample. Exiting."); + return; } // Use StorageSharedKeyCredential with storage account and account key From 14e6fbe1c028171e4ccf5425856453a313dc3bee Mon Sep 17 00:00:00 2001 From: Will Temple Date: Wed, 11 Dec 2019 14:40:08 -0800 Subject: [PATCH 20/39] [run-samples] Fixed an ignore bug --- common/scripts/run-samples.js | 1 + 1 file changed, 1 insertion(+) diff --git a/common/scripts/run-samples.js b/common/scripts/run-samples.js index b6f4f1fce2c3..47c8ae69b961 100644 --- a/common/scripts/run-samples.js +++ b/common/scripts/run-samples.js @@ -44,6 +44,7 @@ async function* findMatchingFiles(tsDir, matches) { if (IGNORE.includes(entry.name)) { console.log("[run-samples] Ignoring", fullPath); + continue; } if (entry.isDirectory()) { From d2e70cadaa3a34bed2f281bd2cd48648dafab1b2 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Wed, 11 Dec 2019 14:41:38 -0800 Subject: [PATCH 21/39] [storage-file-share] Removed scripts and references to execute:all --- sdk/storage/storage-file-share/samples/javascript/README.md | 6 ------ .../storage-file-share/samples/javascript/package.json | 3 --- sdk/storage/storage-file-share/samples/typescript/README.md | 6 ------ .../storage-file-share/samples/typescript/package.json | 3 +-- 4 files changed, 1 insertion(+), 17 deletions(-) diff --git a/sdk/storage/storage-file-share/samples/javascript/README.md b/sdk/storage/storage-file-share/samples/javascript/README.md index 3458a827f2a1..89a8b2a9c38d 100644 --- a/sdk/storage/storage-file-share/samples/javascript/README.md +++ b/sdk/storage/storage-file-share/samples/javascript/README.md @@ -57,12 +57,6 @@ Alternatively, run a single sample with the correct environment variables set (s npx cross-env ACCOUNT_NAME="" ACCOUNT_KEY="" node basic.js ``` -Or, to run all of the samples, use the following npm command: - -```bash -npm run execute:all -``` - ## Next Steps Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients. diff --git a/sdk/storage/storage-file-share/samples/javascript/package.json b/sdk/storage/storage-file-share/samples/javascript/package.json index 1f90cdb174a6..6e58f95bb61e 100644 --- a/sdk/storage/storage-file-share/samples/javascript/package.json +++ b/sdk/storage/storage-file-share/samples/javascript/package.json @@ -6,9 +6,6 @@ "engine": { "node": ">=8.0.0" }, - "scripts": { - "execute:all": "cross-env BATCH_RUN_SAMPLES=true node run.js" - }, "repository": { "type": "git", "url": "git+https://github.com/Azure/azure-sdk-for-js.git" diff --git a/sdk/storage/storage-file-share/samples/typescript/README.md b/sdk/storage/storage-file-share/samples/typescript/README.md index 6bb9aa52bf0f..8663bc9c120f 100644 --- a/sdk/storage/storage-file-share/samples/typescript/README.md +++ b/sdk/storage/storage-file-share/samples/typescript/README.md @@ -69,12 +69,6 @@ Alternatively, run a single sample with the correct environment variables set (s npx cross-env ACCOUNT_NAME="" ACCOUNT_KEY="" node dist/basic.js ``` -Or, to run all of the samples, use the following npm command: - -```bash -npm run execute:all -``` - ## Next Steps Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients. diff --git a/sdk/storage/storage-file-share/samples/typescript/package.json b/sdk/storage/storage-file-share/samples/typescript/package.json index e25c49ddeb86..19e69bd3b291 100644 --- a/sdk/storage/storage-file-share/samples/typescript/package.json +++ b/sdk/storage/storage-file-share/samples/typescript/package.json @@ -8,8 +8,7 @@ }, "scripts": { "build": "tsc", - "prebuild": "rimraf dist/", - "execute:all": "npm run build && cross-env BATCH_RUN_SAMPLES=true node dist/run.js" + "prebuild": "rimraf dist/" }, "repository": { "type": "git", From 1ab154b4c15db2b72aa4252d432e21479099fd2c Mon Sep 17 00:00:00 2001 From: Will Temple Date: Wed, 11 Dec 2019 14:55:27 -0800 Subject: [PATCH 22/39] [prep-samples] typo --- common/scripts/prep-samples.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/scripts/prep-samples.js b/common/scripts/prep-samples.js index 2727d50b2821..4e239537ca3c 100644 --- a/common/scripts/prep-samples.js +++ b/common/scripts/prep-samples.js @@ -83,7 +83,7 @@ async function* findMatchingFiles(tsDir, matches) { } /** - * Replaces package require/import statements with relative pathsfor CI + * Replaces package require/import statements with relative paths for CI * * @param {string} fileName the name of the file to open and process * @param {string} baseDir the base directory of the package From b27c65c0d86ecf7754bb7b61cb060409413c83f2 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Wed, 11 Dec 2019 15:02:49 -0800 Subject: [PATCH 23/39] [storage-file-share] Update sample.env --- .../storage-file-share/samples/javascript/sample.env | 11 +++++++++++ .../storage-file-share/samples/typescript/sample.env | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/sdk/storage/storage-file-share/samples/javascript/sample.env b/sdk/storage/storage-file-share/samples/javascript/sample.env index deb48f817cf6..3a0741abb9f0 100644 --- a/sdk/storage/storage-file-share/samples/javascript/sample.env +++ b/sdk/storage/storage-file-share/samples/javascript/sample.env @@ -7,3 +7,14 @@ STORAGE_CONNECTION_STRING= # Used for the advanced and anonymousCred tests. Create a SAS token for a storage account in the Azure Portal. ACCOUNT_SAS= + +# Used for iterators-handles, provide an existing share and directory name. +SHARE_NAME= +DIR_NAME= + +# To run the proxyAuth sample, set up an HTTP proxy and enter your information: +PROXY_HOST= +PROXY_PORT= +PROXY_USERNAME= +PROXY_PASSWORD= + diff --git a/sdk/storage/storage-file-share/samples/typescript/sample.env b/sdk/storage/storage-file-share/samples/typescript/sample.env index deb48f817cf6..3a0741abb9f0 100644 --- a/sdk/storage/storage-file-share/samples/typescript/sample.env +++ b/sdk/storage/storage-file-share/samples/typescript/sample.env @@ -7,3 +7,14 @@ STORAGE_CONNECTION_STRING= # Used for the advanced and anonymousCred tests. Create a SAS token for a storage account in the Azure Portal. ACCOUNT_SAS= + +# Used for iterators-handles, provide an existing share and directory name. +SHARE_NAME= +DIR_NAME= + +# To run the proxyAuth sample, set up an HTTP proxy and enter your information: +PROXY_HOST= +PROXY_PORT= +PROXY_USERNAME= +PROXY_PASSWORD= + From 0a1edcfb55d43a8b46d3cbf536d7f2ae6d86396f Mon Sep 17 00:00:00 2001 From: Will Temple Date: Wed, 11 Dec 2019 15:10:13 -0800 Subject: [PATCH 24/39] [storage-blob] Replicate updates for storage-blob --- sdk/storage/storage-blob/package.json | 5 +- .../storage-blob/samples/javascript/README.md | 6 --- .../samples/javascript/package.json | 3 -- .../samples/javascript/proxyAuth.js | 23 +++++---- .../storage-blob/samples/javascript/run.js | 49 ------------------- .../samples/javascript/sample.env | 11 ++++- .../storage-blob/samples/typescript/README.md | 6 --- .../samples/typescript/package.json | 3 +- .../samples/typescript/sample.env | 11 ++++- .../samples/typescript/src/proxyAuth.ts | 23 +++++---- .../samples/typescript/src/run.ts | 49 ------------------- 11 files changed, 52 insertions(+), 137 deletions(-) delete mode 100644 sdk/storage/storage-blob/samples/javascript/run.js delete mode 100644 sdk/storage/storage-blob/samples/typescript/src/run.ts diff --git a/sdk/storage/storage-blob/package.json b/sdk/storage/storage-blob/package.json index 9adc2c5016e3..4174f2143994 100644 --- a/sdk/storage/storage-blob/package.json +++ b/sdk/storage/storage-blob/package.json @@ -30,9 +30,10 @@ "build": "npm run build:es6 && npm run build:nodebrowser && api-extractor run --local", "check-format": "prettier --list-different --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", "clean": "rimraf dist dist-esm dist-test typings temp browser/*.js* browser/*.zip statistics.html coverage coverage-browser .nyc_output *.tgz *.log test*.xml TEST*.xml", + "clean:samples": "rimraf samples/javascript/node_modules samples/typescript/node_modules samples/typescript/dist samples/typescript/package-lock.json samples/javascript/package-lock.json", "extract-api": "tsc -p . && api-extractor run --local", - "execute:js-samples": "cross-env BATCH_RUN_SAMPLES=true node samples/javascript/run.js", - "execute:ts-samples": "cross-env BATCH_RUN_SAMPLES=true node samples/typescript/dist/samples/typescript/src/run.js", + "execute:js-samples": "node ../../../common/scripts/run-samples.js samples/javascript/", + "execute:ts-samples": "node ../../../common/scripts/run-samples.js samples/typescript/dist/samples/typescript/src/", "execute:samples": "npm run build:samples && npm run execute:js-samples && npm run execute:ts-samples", "format": "prettier --write --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", "integration-test:browser": "karma start --single-run", diff --git a/sdk/storage/storage-blob/samples/javascript/README.md b/sdk/storage/storage-blob/samples/javascript/README.md index 2885cdb5a22f..2a1e2c0c0705 100644 --- a/sdk/storage/storage-blob/samples/javascript/README.md +++ b/sdk/storage/storage-blob/samples/javascript/README.md @@ -61,12 +61,6 @@ Alternatively, run a single sample with the correct environment variables set (s npx cross-env ACCOUNT_NAME="" ACCOUNT_KEY="" node basic.js ``` -Or, to run all of the samples, use the following npm command: - -```bash -npm run execute:all -``` - ## Next Steps Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients. diff --git a/sdk/storage/storage-blob/samples/javascript/package.json b/sdk/storage/storage-blob/samples/javascript/package.json index b1576d7301ad..10e6d8f578da 100644 --- a/sdk/storage/storage-blob/samples/javascript/package.json +++ b/sdk/storage/storage-blob/samples/javascript/package.json @@ -6,9 +6,6 @@ "engine": { "node": ">=8.0.0" }, - "scripts": { - "execute:all": "cross-env BATCH_RUN_SAMPLES=true node run.js" - }, "repository": { "type": "git", "url": "git+https://github.com/Azure/azure-sdk-for-js.git" diff --git a/sdk/storage/storage-blob/samples/javascript/proxyAuth.js b/sdk/storage/storage-blob/samples/javascript/proxyAuth.js index 6d06e59c3518..86cd1e65118d 100644 --- a/sdk/storage/storage-blob/samples/javascript/proxyAuth.js +++ b/sdk/storage/storage-blob/samples/javascript/proxyAuth.js @@ -18,20 +18,25 @@ async function main() { // StorageSharedKeyCredential is only avaiable in Node.js runtime, not in browsers const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey); + // Enter your proxy information + const proxyOptions = { + host: process.env.PROXY_HOST || "", + port: parseInt(process.env.PROXY_PORT || "3128"), + username: process.env.PROXY_USERNAME || "", + password: process.env.PROXY_PASSWORD || "" + }; + + if (proxyOptions.host === "") { + console.warn("Proxy information not provided, but it is required to run this sample. Exiting."); + return; + } + const blobServiceClient = new BlobServiceClient( `https://${account}.blob.core.windows.net`, sharedKeyCredential, { - // proxy can either be a URL like "http://localhost:3128" - // or - // an option bag consisting {host, port, username, password } - proxyOptions: { - host: "http://localhost", - port: 3128, - username: "username", - password: "password" - } // if proxy is undefined, the library tries to load the proxy settings from the environment variables like HTTP_PROXY + proxyOptions } ); diff --git a/sdk/storage/storage-blob/samples/javascript/run.js b/sdk/storage/storage-blob/samples/javascript/run.js deleted file mode 100644 index 221c8d84f141..000000000000 --- a/sdk/storage/storage-blob/samples/javascript/run.js +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -const { main: advancedMain } = require("./advanced"); -const { main: anonymousCredMain } = require("./anonymousCred"); -const { main: azureAdAuthMain } = require("./azureAdAuth"); -const { main: basicMain } = require("./basic"); -const { main: customizedClientHeadersMain } = require("./customizedClientHeaders"); -const { main: customPipelineMain } = require("./customPipeline"); -const { main: errorsAndResponsesMain } = require("./errorsAndResponses"); -const { main: iteratorsBlobsHierarchyMain } = require("./iterators-blobs-hierarchy"); -const { main: iteratorsBlobsMain } = require("./iterators-blobs"); -const { main: iteratorsContainersMain } = require("./iterators-containers"); -// const { main: proxyAuthMain } = require("./proxyAuth"); -const { main: readingSnapshotMain } = require("./readingSnapshot"); -const { main: sharedKeyCredMain } = require("./sharedKeyCred"); -const { main: withConnStringMain } = require("./withConnString"); - -const { config: dotenv } = require("dotenv"); -dotenv(); - -const samples = [ - ["advanced", advancedMain], - ["anonymousCred", anonymousCredMain], - ["azureAdAuth", azureAdAuthMain], - ["basic", basicMain], - ["customizedClientHeaders", customizedClientHeadersMain], - ["customPipeline", customPipelineMain], - ["errorsAndResponses", errorsAndResponsesMain], - ["iterators-blobs-hierarchy", iteratorsBlobsHierarchyMain], - ["iterators-blobs", iteratorsBlobsMain], - ["iterators-containers", iteratorsContainersMain], - // ["proxyAuth", proxyAuthMain], // Requires a proxy - ["readingSnapshot", readingSnapshotMain], - ["sharedKeyCred", sharedKeyCredMain], - ["withConnString", withConnStringMain] -]; - -async function main() { - for (let [sampleName, sampleMain] of samples) { - console.log("[samples] Running sample", sampleName); - await sampleMain(); - } -} - -main().catch((error) => { - console.error("[samples] An error occurred:", error); - process.exit(1); -}); diff --git a/sdk/storage/storage-blob/samples/javascript/sample.env b/sdk/storage/storage-blob/samples/javascript/sample.env index 81e1cbbbd071..84d7ef49f88e 100644 --- a/sdk/storage/storage-blob/samples/javascript/sample.env +++ b/sdk/storage/storage-blob/samples/javascript/sample.env @@ -8,7 +8,16 @@ STORAGE_CONNECTION_STRING= # Used for the advanced and anonymousCred tests. Create a SAS token for a storage account in the Azure Portal. ACCOUNT_SAS= -# Used to authenticate using Azure AD +# Used to authenticate using Azure AD as a service principal for role-based authentication. +# +# See the documentation for `EnvironmentCredential` at the following link: +# https://docs.microsoft.com/javascript/api/@azure/identity/environmentcredential AZURE_TENANT_ID= AZURE_CLIENT_ID= AZURE_CLIENT_SECRET= + +# To run the proxyAuth sample, set up an HTTP proxy and enter your information: +PROXY_HOST= +PROXY_PORT= +PROXY_USERNAME= +PROXY_PASSWORD= diff --git a/sdk/storage/storage-blob/samples/typescript/README.md b/sdk/storage/storage-blob/samples/typescript/README.md index f4a5b816995f..7b22c4851422 100644 --- a/sdk/storage/storage-blob/samples/typescript/README.md +++ b/sdk/storage/storage-blob/samples/typescript/README.md @@ -73,12 +73,6 @@ Alternatively, run a single sample with the correct environment variables set (s npx cross-env ACCOUNT_NAME="" ACCOUNT_KEY="" node dist/basic.js ``` -Or, to run all of the samples, use the following npm command: - -```bash -npm run execute:all -``` - ## Next Steps Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients. diff --git a/sdk/storage/storage-blob/samples/typescript/package.json b/sdk/storage/storage-blob/samples/typescript/package.json index 3b947a61a8ed..11748303b62f 100644 --- a/sdk/storage/storage-blob/samples/typescript/package.json +++ b/sdk/storage/storage-blob/samples/typescript/package.json @@ -8,8 +8,7 @@ }, "scripts": { "build": "tsc", - "prebuild": "rimraf dist/", - "execute:all": "npm run build && cross-env BATCH_RUN_SAMPLES=true node dist/run.js" + "prebuild": "rimraf dist/" }, "repository": { "type": "git", diff --git a/sdk/storage/storage-blob/samples/typescript/sample.env b/sdk/storage/storage-blob/samples/typescript/sample.env index 81e1cbbbd071..84d7ef49f88e 100644 --- a/sdk/storage/storage-blob/samples/typescript/sample.env +++ b/sdk/storage/storage-blob/samples/typescript/sample.env @@ -8,7 +8,16 @@ STORAGE_CONNECTION_STRING= # Used for the advanced and anonymousCred tests. Create a SAS token for a storage account in the Azure Portal. ACCOUNT_SAS= -# Used to authenticate using Azure AD +# Used to authenticate using Azure AD as a service principal for role-based authentication. +# +# See the documentation for `EnvironmentCredential` at the following link: +# https://docs.microsoft.com/javascript/api/@azure/identity/environmentcredential AZURE_TENANT_ID= AZURE_CLIENT_ID= AZURE_CLIENT_SECRET= + +# To run the proxyAuth sample, set up an HTTP proxy and enter your information: +PROXY_HOST= +PROXY_PORT= +PROXY_USERNAME= +PROXY_PASSWORD= diff --git a/sdk/storage/storage-blob/samples/typescript/src/proxyAuth.ts b/sdk/storage/storage-blob/samples/typescript/src/proxyAuth.ts index f739306d8bed..71ac8dbedb25 100644 --- a/sdk/storage/storage-blob/samples/typescript/src/proxyAuth.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/proxyAuth.ts @@ -18,20 +18,25 @@ export async function main() { // StorageSharedKeyCredential is only avaiable in Node.js runtime, not in browsers const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey); + // Enter your proxy information + const proxyOptions = { + host: process.env.PROXY_HOST || "", + port: parseInt(process.env.PROXY_PORT || "3128"), + username: process.env.PROXY_USERNAME || "", + password: process.env.PROXY_PASSWORD || "" + }; + + if (proxyOptions.host === "") { + console.warn("Proxy information not provided, but it is required to run this sample. Exiting."); + return; + } + const blobServiceClient = new BlobServiceClient( `https://${account}.blob.core.windows.net`, sharedKeyCredential, { - // proxy can either be a URL like "http://localhost:3128" - // or - // an option bag consisting {host, port, username, password } - proxyOptions: { - host: "http://localhost", - port: 3128, - username: "username", - password: "password" - } // if proxy is undefined, the library tries to load the proxy settings from the environment variables like HTTP_PROXY + proxyOptions } ); diff --git a/sdk/storage/storage-blob/samples/typescript/src/run.ts b/sdk/storage/storage-blob/samples/typescript/src/run.ts deleted file mode 100644 index 253d2bd3e862..000000000000 --- a/sdk/storage/storage-blob/samples/typescript/src/run.ts +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -import { main as advancedMain } from "./advanced"; -import { main as anonymousCredMain } from "./anonymousCred"; -import { main as azureAdAuthMain } from "./azureAdAuth"; -import { main as basicMain } from "./basic"; -import { main as customizedClientHeadersMain } from "./customizedClientHeaders"; -import { main as customPipelineMain } from "./customPipeline"; -import { main as errorsAndResponsesMain } from "./errorsAndResponses"; -import { main as iteratorsBlobsHierarchyMain } from "./iterators-blobs-hierarchy"; -import { main as iteratorsBlobsMain } from "./iterators-blobs"; -import { main as iteratorsContainersMain } from "./iterators-containers"; -// import { main as proxyAuthMain } from "./proxyAuth"; -import { main as readingSnapshotMain } from "./readingSnapshot"; -import { main as sharedKeyCredMain } from "./sharedKeyCred"; -import { main as withConnStringMain } from "./withConnString"; - -import { config as dotenv } from "dotenv"; -dotenv(); - -const samples: Array<[string, () => Promise]> = [ - ["advanced", advancedMain], - ["anonymousCred", anonymousCredMain], - ["azureAdAuth", azureAdAuthMain], - ["basic", basicMain], - ["customizedClientHeaders", customizedClientHeadersMain], - ["customPipeline", customPipelineMain], - ["errorsAndResponses", errorsAndResponsesMain], - ["iterators-blobs-hierarchy", iteratorsBlobsHierarchyMain], - ["iterators-blobs", iteratorsBlobsMain], - ["iterators-containers", iteratorsContainersMain], - // ["proxyAuth", proxyAuthMain], // Requires a proxy - ["readingSnapshot", readingSnapshotMain], - ["sharedKeyCred", sharedKeyCredMain], - ["withConnString", withConnStringMain] -]; - -async function main() { - for (let [sampleName, sampleMain] of samples) { - console.log("[samples] Running sample", sampleName); - await sampleMain(); - } -} - -main().catch((error) => { - console.error("[samples] An error occurred:", error); - process.exit(1); -}); From 8f8b6e2afceaaf15a415458ab450b7413a7c98ce Mon Sep 17 00:00:00 2001 From: Will Temple Date: Wed, 11 Dec 2019 15:19:52 -0800 Subject: [PATCH 25/39] [storage-blob] remove execute-samples.js --- sdk/storage/storage-blob/execute-samples.js | 80 --------------------- 1 file changed, 80 deletions(-) delete mode 100644 sdk/storage/storage-blob/execute-samples.js diff --git a/sdk/storage/storage-blob/execute-samples.js b/sdk/storage/storage-blob/execute-samples.js deleted file mode 100644 index aa77c71f12be..000000000000 --- a/sdk/storage/storage-blob/execute-samples.js +++ /dev/null @@ -1,80 +0,0 @@ -const execa = require("execa"); -const fs = require("fs"); -require("dotenv").config({ path: "../.env" }); - -// Samples can be skipped by mentioning them in the skipSamples Array. -// Suppose skipSamples = ["some-entry", "sample-2"], -// some-entry.ts, sample-2.ts, some-entry.js and sample-2.js will be skipped. -const skipSamples = ["proxyAuth"]; - -const bDel = `!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`; -const del = `${bDel}------------------------------${bDel}`; - -// Colours - green, yellow, red and blue - for console logs. -const { g, y, r, b } = [["r", 1], ["g", 2], ["b", 4], ["y", 3]].reduce( - (cols, col) => ({ - ...cols, - [col[0]]: (f) => `\x1b[3${col[1]}m${f}\x1b[0m` - }), - {} -); - -// Executes `cmd` in `cwd`(directory). -async function exec(cmd, cwd) { - let command = execa(cmd, { - cwd, - shell: true - }); - command.stderr.pipe(process.stderr); - command.stdout.pipe(process.stdout); - return command; -} - -async function runSamples(language) { - let cmd; - // Tries to execute all the samples in the `directory`. - const directory = `./samples/${language}`; - - if (language === "typescript") { - cmd = "ts-node"; - } else { - cmd = "node"; - await exec(`npm run build:js-samples`, directory); - } - - console.log(`Running ${language} samples...`); - - const files = fs.readdirSync(directory); - - for (var i = 0; i < files.length; i++) { - if (!skipSamples.includes(files[i].split(".")[0])) { - try { - console.log(`\n\n${b(del)}\n${del}`); - console.log(`${bDel}\t${files[i]} \t `); - console.log(`${del}\n${b(del)} \n`); - - console.log(`${g("Running")} ${y(files[i])} ${g("...")}`); - // Executing a sample - Example: (`ts-node samplefilename.ts`, `./samples/typescript`). - await exec(`${cmd} ${files[i]}`, directory); - console.log(`${g(files[i] + " is done..!")}`); - } catch (error) { - console.log(error.message); - console.log(`${r(del)}\n${del}`); - console.log(`${bDel}\t${files[i]} Sample - FAILED\t `); - console.log(`${del}\n${r(del)}`); - } - } - } -} - -(async () => { - try { - await runSamples("typescript"); - await runSamples("javascript"); - process.exit(0); - } catch (error) { - console.log("Samples failed!"); - console.log(error); - process.exit(1); - } -})(); From 2de60763012ae62f9a2ec2271e753709b70a4f9e Mon Sep 17 00:00:00 2001 From: Will Temple Date: Wed, 11 Dec 2019 16:16:03 -0800 Subject: [PATCH 26/39] [storage-blob] Fixed a bug in blob samples ts readme --- sdk/storage/storage-blob/samples/typescript/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/storage/storage-blob/samples/typescript/README.md b/sdk/storage/storage-blob/samples/typescript/README.md index 7b22c4851422..d5856db9b7cb 100644 --- a/sdk/storage/storage-blob/samples/typescript/README.md +++ b/sdk/storage/storage-blob/samples/typescript/README.md @@ -91,8 +91,8 @@ Take a look at our [API Documentation][apiref] for more information about the AP [readingsnapshot]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/typescript/src/readingSnapshot.ts [sharedkeycred]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/typescript/src/sharedKeyCred.ts [withconnstring]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/typescript/src/withConnString.ts -[apiref]: https://docs.microsoft.com/javascript/api/@azure/storage-file-share +[apiref]: https://docs.microsoft.com/javascript/api/@azure/storage-blob [azstorage]: https://docs.microsoft.com/azure/storage/common/storage-account-overview [freesub]: https://azure.microsoft.com/free/ -[package]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-file-share/README.md +[package]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/README.md [typescript]: https://www.typescriptlang.org/docs/home.html From 5de83487bae2259e8a1cf41c629e2d6ffd908446 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Wed, 11 Dec 2019 16:16:44 -0800 Subject: [PATCH 27/39] [storage-queue] Replicate updates to samples on storage-queue --- sdk/storage/storage-queue/execute-samples.js | 80 ----------------- sdk/storage/storage-queue/package.json | 9 +- .../samples/javascript/README.md | 73 ++++++++++++++++ .../samples/javascript/anonymousCred.js | 20 +++-- .../samples/javascript/azureAdAuth.js | 20 +++-- .../storage-queue/samples/javascript/basic.js | 20 +++-- .../samples/javascript/customPipeline.js | 20 +++-- .../samples/javascript/iterators.js | 20 +++-- .../samples/javascript/package.json | 36 ++++++++ .../samples/javascript/proxyAuth.js | 43 ++++++---- .../samples/javascript/sample.env | 23 +++++ .../samples/javascript/sampleHelpers.js | 15 ++++ .../samples/javascript/sharedKeyCred.js | 20 +++-- .../samples/javascript/withConnString.js | 20 +++-- .../storage-queue/samples/tsconfig.json | 20 ++--- .../samples/typescript/README.md | 86 +++++++++++++++++++ .../samples/typescript/package.json | 43 ++++++++++ .../samples/typescript/sample.env | 23 +++++ .../typescript/{ => src}/anonymousCred.ts | 20 ++--- .../typescript/{ => src}/azureAdAuth.ts | 20 ++--- .../samples/typescript/{ => src}/basic.ts | 20 ++--- .../typescript/{ => src}/customPipeline.ts | 20 ++--- .../samples/typescript/{ => src}/iterators.ts | 20 ++--- .../samples/typescript/{ => src}/proxyAuth.ts | 43 ++++++---- .../samples/typescript/src/sampleHelpers.ts | 13 +++ .../typescript/{ => src}/sharedKeyCred.ts | 20 ++--- .../typescript/{ => src}/withConnString.ts | 20 ++--- .../samples/typescript/tsconfig.json | 15 ++++ 28 files changed, 537 insertions(+), 265 deletions(-) delete mode 100644 sdk/storage/storage-queue/execute-samples.js create mode 100644 sdk/storage/storage-queue/samples/javascript/README.md create mode 100644 sdk/storage/storage-queue/samples/javascript/package.json create mode 100644 sdk/storage/storage-queue/samples/javascript/sample.env create mode 100644 sdk/storage/storage-queue/samples/javascript/sampleHelpers.js create mode 100644 sdk/storage/storage-queue/samples/typescript/README.md create mode 100644 sdk/storage/storage-queue/samples/typescript/package.json create mode 100644 sdk/storage/storage-queue/samples/typescript/sample.env rename sdk/storage/storage-queue/samples/typescript/{ => src}/anonymousCred.ts (74%) rename sdk/storage/storage-queue/samples/typescript/{ => src}/azureAdAuth.ts (88%) rename sdk/storage/storage-queue/samples/typescript/{ => src}/basic.ts (92%) rename sdk/storage/storage-queue/samples/typescript/{ => src}/customPipeline.ts (84%) rename sdk/storage/storage-queue/samples/typescript/{ => src}/iterators.ts (91%) rename sdk/storage/storage-queue/samples/typescript/{ => src}/proxyAuth.ts (65%) create mode 100644 sdk/storage/storage-queue/samples/typescript/src/sampleHelpers.ts rename sdk/storage/storage-queue/samples/typescript/{ => src}/sharedKeyCred.ts (78%) rename sdk/storage/storage-queue/samples/typescript/{ => src}/withConnString.ts (79%) create mode 100644 sdk/storage/storage-queue/samples/typescript/tsconfig.json diff --git a/sdk/storage/storage-queue/execute-samples.js b/sdk/storage/storage-queue/execute-samples.js deleted file mode 100644 index aa77c71f12be..000000000000 --- a/sdk/storage/storage-queue/execute-samples.js +++ /dev/null @@ -1,80 +0,0 @@ -const execa = require("execa"); -const fs = require("fs"); -require("dotenv").config({ path: "../.env" }); - -// Samples can be skipped by mentioning them in the skipSamples Array. -// Suppose skipSamples = ["some-entry", "sample-2"], -// some-entry.ts, sample-2.ts, some-entry.js and sample-2.js will be skipped. -const skipSamples = ["proxyAuth"]; - -const bDel = `!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`; -const del = `${bDel}------------------------------${bDel}`; - -// Colours - green, yellow, red and blue - for console logs. -const { g, y, r, b } = [["r", 1], ["g", 2], ["b", 4], ["y", 3]].reduce( - (cols, col) => ({ - ...cols, - [col[0]]: (f) => `\x1b[3${col[1]}m${f}\x1b[0m` - }), - {} -); - -// Executes `cmd` in `cwd`(directory). -async function exec(cmd, cwd) { - let command = execa(cmd, { - cwd, - shell: true - }); - command.stderr.pipe(process.stderr); - command.stdout.pipe(process.stdout); - return command; -} - -async function runSamples(language) { - let cmd; - // Tries to execute all the samples in the `directory`. - const directory = `./samples/${language}`; - - if (language === "typescript") { - cmd = "ts-node"; - } else { - cmd = "node"; - await exec(`npm run build:js-samples`, directory); - } - - console.log(`Running ${language} samples...`); - - const files = fs.readdirSync(directory); - - for (var i = 0; i < files.length; i++) { - if (!skipSamples.includes(files[i].split(".")[0])) { - try { - console.log(`\n\n${b(del)}\n${del}`); - console.log(`${bDel}\t${files[i]} \t `); - console.log(`${del}\n${b(del)} \n`); - - console.log(`${g("Running")} ${y(files[i])} ${g("...")}`); - // Executing a sample - Example: (`ts-node samplefilename.ts`, `./samples/typescript`). - await exec(`${cmd} ${files[i]}`, directory); - console.log(`${g(files[i] + " is done..!")}`); - } catch (error) { - console.log(error.message); - console.log(`${r(del)}\n${del}`); - console.log(`${bDel}\t${files[i]} Sample - FAILED\t `); - console.log(`${del}\n${r(del)}`); - } - } - } -} - -(async () => { - try { - await runSamples("typescript"); - await runSamples("javascript"); - process.exit(0); - } catch (error) { - console.log("Samples failed!"); - console.log(error); - process.exit(1); - } -})(); diff --git a/sdk/storage/storage-queue/package.json b/sdk/storage/storage-queue/package.json index 9eb0cd963227..7653e6ea7006 100644 --- a/sdk/storage/storage-queue/package.json +++ b/sdk/storage/storage-queue/package.json @@ -21,14 +21,17 @@ "build:autorest": "autorest ./swagger/README.md --typescript --package-version=12.0.1 --use=@microsoft.azure/autorest.typescript@5.0.1", "build:es6": "tsc -p tsconfig.json", "build:nodebrowser": "rollup -c 2>&1", - "build:js-samples": "npm run clean && npm run build:es6 && cross-env ONLY_NODE=true rollup -c 2>&1", - "build:ts-samples": "npm run clean && cd samples && tsc -p . ", + "build:samples": "npm run clean && npm run build:es6 && cross-env ONLY_NODE=true rollup -c 2>&1 && npm run build:prep-samples", + "build:prep-samples": "node ../../../common/scripts/prep-samples.js && cd samples && tsc", "build:test": "npm run build:es6 && rollup -c rollup.test.config.js 2>&1", "build": "npm run build:es6 && npm run build:nodebrowser && api-extractor run --local", "check-format": "prettier --list-different --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", "clean": "rimraf dist dist-esm dist-test typings temp browser/*.js* browser/*.zip statistics.html coverage coverage-browser .nyc_output *.tgz *.log test*.xml TEST*.xml", + "clean:samples": "rimraf samples/javascript/node_modules samples/typescript/node_modules samples/typescript/dist samples/typescript/package-lock.json samples/javascript/package-lock.json", "extract-api": "tsc -p . && api-extractor run --local", - "execute:samples": "node execute-samples.js", + "execute:js-samples": "node ../../../common/scripts/run-samples.js samples/javascript/", + "execute:ts-samples": "node ../../../common/scripts/run-samples.js samples/typescript/dist/samples/typescript/src/", + "execute:samples": "npm run build:samples && npm run execute:js-samples && npm run execute:ts-samples", "format": "prettier --write --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", "integration-test:browser": "karma start --single-run", "integration-test:node": "nyc mocha --require source-map-support/register --reporter mocha-multi --reporter-options spec=-,mocha-junit-reporter=- --full-trace -t 120000 --retries 2 dist-test/index.node.js", diff --git a/sdk/storage/storage-queue/samples/javascript/README.md b/sdk/storage/storage-queue/samples/javascript/README.md new file mode 100644 index 000000000000..39307f32733c --- /dev/null +++ b/sdk/storage/storage-queue/samples/javascript/README.md @@ -0,0 +1,73 @@ +--- +page_type: sample +languages: + - javascript +products: + - azure + - azure-storage +urlFragment: storage-queue-javascript +--- + +# Azure Storage Queue client library samples for JavaScript + +These sample programs show how to use the JavaScript client libraries for Azure Storage Queues in some common scenarios. + +| **File Name** | **Description** | +| ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | +| [basic.js][basic] | authenticate with the service using an account name & key (or anonymously with a SAS URL); send, peek, and dequeue messages | +| [withConnString.js][withconnstring] | connect to and authenticate with the service using a connection string | +| [sharedKeyCred.js][sharedkeycred] | authenticate with the service using an account name and a shared key | +| [anonymousCred.js][anonymouscred] | authenticate with the service anonymously using a SAS URL | +| [azureAdAuth.js][azureadauth] | authenticate with the service using Azure Active Directory | +| [proxyAuth.js][proxyauth] | connect to the service using a proxy and authenticate with an account name & key | +| [iterators.js][iterators] | different options for iterating over messages, showing options for paging, resuming paging etc. | +| [customPipeline.js][custompipeline] | use custom HTTP pipeline options when connecting to the service | + +## Prerequisites + +The sample are compatible with Node.js >= 8.0.0, except for the samples that use the async `for await` syntax, which require Node.js >= 10.0.0. + +You need [an Azure subscription][freesub] and [an Azure Storage account][azstorage] to run these sample programs. Samples retrieve credentials to access the storage account from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function. + +Adapting the samples to run in the browser requires some additional consideration. For details, please see the [package README][package]. + +## Setup + +To run the samples using the published version of the package: + +1. Install the dependencies using `npm`: + +```bash +npm install +``` + +2. Edit the file `sample.env`, adding the correct credentials to access the Azure service and run the samples. Then rename the file from `sample.env` to just `.env`. The sample programs will read this file automatically. + +3. Run whichever samples you like (note that some samples may require additional setup, see the table above): + +```bash +node basic.js +``` + +Alternatively, run a single sample with the correct environment variables set (step 3 is not required if you do this), for example (cross-platform): + +```bash +npx cross-env ACCOUNT_NAME="" ACCOUNT_KEY="" node basic.js +``` + +## Next Steps + +Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients. + +[anonymouscred]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-queue/samples/javascript/anonymousCred.js +[azureadauth]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-queue/samples/javascript/azureAdAuth.js +[basic]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-queue/samples/javascript/basic.js +[custompipeline]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-queue/samples/javascript/customPipeline.js +[iterators]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-queue/samples/javascript/iterators.js +[proxyauth]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-queue/samples/javascript/proxyAuth.js +[sharedkeycred]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-queue/samples/javascript/sharedKeyCred.js +[withconnstring]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-queue/samples/javascript/withConnString.js +[apiref]: https://docs.microsoft.com/javascript/api/@azure/storage-queue +[azstorage]: https://docs.microsoft.com/azure/storage/common/storage-account-overview +[freesub]: https://azure.microsoft.com/free/ +[package]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-queue/README.md diff --git a/sdk/storage/storage-queue/samples/javascript/anonymousCred.js b/sdk/storage/storage-queue/samples/javascript/anonymousCred.js index f6e17a48c6bf..48bbf304df39 100644 --- a/sdk/storage/storage-queue/samples/javascript/anonymousCred.js +++ b/sdk/storage/storage-queue/samples/javascript/anonymousCred.js @@ -1,8 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and SAS in main() */ -const { QueueServiceClient, AnonymousCredential } = require("../.."); // Change to "@azure/storage-queue" in your package +const { QueueServiceClient, AnonymousCredential } = require("@azure/storage-queue"); + +const { runSample } = require("./sampleHelpers"); async function main() { // Enter your storage account name and SAS @@ -33,11 +38,8 @@ async function main() { ); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-queue/samples/javascript/azureAdAuth.js b/sdk/storage/storage-queue/samples/javascript/azureAdAuth.js index 05979df93de3..be44e4615651 100644 --- a/sdk/storage/storage-queue/samples/javascript/azureAdAuth.js +++ b/sdk/storage/storage-queue/samples/javascript/azureAdAuth.js @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* ONLY AVAILABLE IN NODE.JS RUNTIME @@ -18,10 +21,12 @@ - Make sure you have AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET as environment variables to successfully execute the sample(Can leverage process.env). */ -const { QueueServiceClient } = require("../.."); // Change to "@azure/storage-queue" in your package +const { QueueServiceClient } = require("@azure/storage-queue"); const { DefaultAzureCredential } = require("@azure/identity"); +const { runSample } = require("./sampleHelpers"); + async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -51,11 +56,8 @@ async function main() { } } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-queue/samples/javascript/basic.js b/sdk/storage/storage-queue/samples/javascript/basic.js index b1ec573a5677..15eee55b482a 100644 --- a/sdk/storage/storage-queue/samples/javascript/basic.js +++ b/sdk/storage/storage-queue/samples/javascript/basic.js @@ -1,8 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -const { QueueServiceClient, StorageSharedKeyCredential } = require("../.."); // Change to "@azure/storage-queue" in your package +const { QueueServiceClient, StorageSharedKeyCredential } = require("@azure/storage-queue"); + +const { runSample } = require("./sampleHelpers"); async function main() { // Enter your storage account name and shared key @@ -87,11 +92,8 @@ async function main() { ); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-queue/samples/javascript/customPipeline.js b/sdk/storage/storage-queue/samples/javascript/customPipeline.js index 04a6cbd3af05..9405c5e9bf58 100644 --- a/sdk/storage/storage-queue/samples/javascript/customPipeline.js +++ b/sdk/storage/storage-queue/samples/javascript/customPipeline.js @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ @@ -6,7 +9,9 @@ const { QueueServiceClient, newPipeline, StorageSharedKeyCredential -} = require("../.."); // Change to "@azure/storage-queue" in your package +} = require("@azure/storage-queue"); + +const { runSample } = require("./sampleHelpers"); async function main() { // Enter your storage account name and shared key @@ -53,11 +58,8 @@ async function main() { ); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-queue/samples/javascript/iterators.js b/sdk/storage/storage-queue/samples/javascript/iterators.js index 3a7847c9b471..4fcb906e9438 100644 --- a/sdk/storage/storage-queue/samples/javascript/iterators.js +++ b/sdk/storage/storage-queue/samples/javascript/iterators.js @@ -1,8 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -const { QueueServiceClient, StorageSharedKeyCredential } = require("../.."); // Change to "@azure/storage-queue" in your package +const { QueueServiceClient, StorageSharedKeyCredential } = require("@azure/storage-queue"); + +const { runSample } = require("./sampleHelpers"); async function main() { // Enter your storage account name and shared key @@ -102,11 +107,8 @@ async function main() { } } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-queue/samples/javascript/package.json b/sdk/storage/storage-queue/samples/javascript/package.json new file mode 100644 index 000000000000..f851c75f6e96 --- /dev/null +++ b/sdk/storage/storage-queue/samples/javascript/package.json @@ -0,0 +1,36 @@ +{ + "name": "azure-storage-queue-samples-js", + "private": true, + "version": "0.1.0", + "description": "Azure Storage Queue client library samples for TypeScript", + "engine": { + "node": ">=8.0.0" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Azure/azure-sdk-for-js.git" + }, + "keywords": [ + "Azure", + "Storage", + "File", + "Node.js", + "JavaScript" + ], + "author": "Microsoft Corporation", + "license": "MIT", + "bugs": { + "url": "https://github.com/Azure/azure-sdk-for-js/issues" + }, + "homepage": "https://github.com/Azure/azure-sdk-for-js#readme", + "sideEffects": false, + "dependencies": { + "@azure/identity": "latest", + "@azure/storage-queue": "latest", + "dotenv": "^8.2.0" + }, + "devDependencies": { + "cross-env": "^6.0.3", + "rimraf": "^3.0.0" + } +} diff --git a/sdk/storage/storage-queue/samples/javascript/proxyAuth.js b/sdk/storage/storage-queue/samples/javascript/proxyAuth.js index c7b9a160bad4..6abf6978e8c1 100644 --- a/sdk/storage/storage-queue/samples/javascript/proxyAuth.js +++ b/sdk/storage/storage-queue/samples/javascript/proxyAuth.js @@ -1,8 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -const { QueueServiceClient, StorageSharedKeyCredential } = require("../.."); // Change to "@azure/storage-queue" in your package +const { QueueServiceClient, StorageSharedKeyCredential } = require("@azure/storage-queue"); + +const { runSample } = require("./sampleHelpers"); async function main() { // Enter your storage account name and shared key @@ -13,20 +18,25 @@ async function main() { // StorageSharedKeyCredential is only avaiable in Node.js runtime, not in browsers const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey); + // Enter your proxy information + const proxyOptions = { + host: process.env.PROXY_HOST || "", + port: parseInt(process.env.PROXY_PORT || "3128"), + username: process.env.PROXY_USERNAME || "", + password: process.env.PROXY_PASSWORD || "" + }; + + if (proxyOptions.host === "") { + console.warn("Proxy information not provided, but it is required to run this sample. Exiting."); + return; + } + const queueServiceClient = new QueueServiceClient( `https://${account}.queue.core.windows.net`, sharedKeyCredential, { - // proxy can either be a URL like "http://localhost:3128" - // or - // an option bag consisting {host, port, username, password } - proxyOptions: { - host: "http://localhost", - port: 3128, - username: "username", - password: "password" - } // if proxy is undefined, the library tries to load the proxy settings from the environment variables like HTTP_PROXY + proxyOptions } ); @@ -45,11 +55,8 @@ async function main() { ); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed the sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-queue/samples/javascript/sample.env b/sdk/storage/storage-queue/samples/javascript/sample.env new file mode 100644 index 000000000000..84d7ef49f88e --- /dev/null +++ b/sdk/storage/storage-queue/samples/javascript/sample.env @@ -0,0 +1,23 @@ +# Used in most samples. Retrieve these values from a storage account in the Azure Portal. +ACCOUNT_NAME= +ACCOUNT_KEY= + +# Used for withConnString +STORAGE_CONNECTION_STRING= + +# Used for the advanced and anonymousCred tests. Create a SAS token for a storage account in the Azure Portal. +ACCOUNT_SAS= + +# Used to authenticate using Azure AD as a service principal for role-based authentication. +# +# See the documentation for `EnvironmentCredential` at the following link: +# https://docs.microsoft.com/javascript/api/@azure/identity/environmentcredential +AZURE_TENANT_ID= +AZURE_CLIENT_ID= +AZURE_CLIENT_SECRET= + +# To run the proxyAuth sample, set up an HTTP proxy and enter your information: +PROXY_HOST= +PROXY_PORT= +PROXY_USERNAME= +PROXY_PASSWORD= diff --git a/sdk/storage/storage-queue/samples/javascript/sampleHelpers.js b/sdk/storage/storage-queue/samples/javascript/sampleHelpers.js new file mode 100644 index 000000000000..4b68987083ea --- /dev/null +++ b/sdk/storage/storage-queue/samples/javascript/sampleHelpers.js @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +const dotenv = require("dotenv"); +dotenv.config(); + +module.exports = { + runSample(sampleMain) { + if (!process.env["BATCH_RUN_SAMPLES"]) { + return sampleMain(); + } else { + return Promise.resolve(); + } + } +}; diff --git a/sdk/storage/storage-queue/samples/javascript/sharedKeyCred.js b/sdk/storage/storage-queue/samples/javascript/sharedKeyCred.js index 60a31c934449..3df4d0e18e8f 100644 --- a/sdk/storage/storage-queue/samples/javascript/sharedKeyCred.js +++ b/sdk/storage/storage-queue/samples/javascript/sharedKeyCred.js @@ -1,8 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -const { QueueServiceClient, StorageSharedKeyCredential } = require("../.."); // Change to "@azure/storage-queue" in your package +const { QueueServiceClient, StorageSharedKeyCredential } = require("@azure/storage-queue"); + +const { runSample } = require("./sampleHelpers"); async function main() { // Enter your storage account name and shared key @@ -33,11 +38,8 @@ async function main() { ); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-queue/samples/javascript/withConnString.js b/sdk/storage/storage-queue/samples/javascript/withConnString.js index 55d138da18ab..8881905e9370 100644 --- a/sdk/storage/storage-queue/samples/javascript/withConnString.js +++ b/sdk/storage/storage-queue/samples/javascript/withConnString.js @@ -1,8 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -const { QueueServiceClient } = require("../.."); // Change to "@azure/storage-queue" in your package +const { QueueServiceClient } = require("@azure/storage-queue"); + +const { runSample } = require("./sampleHelpers"); async function main() { // Create Queue Service Client from Account connection string or SAS connection string @@ -27,11 +32,8 @@ async function main() { ); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); + +module.exports = { main }; diff --git a/sdk/storage/storage-queue/samples/tsconfig.json b/sdk/storage/storage-queue/samples/tsconfig.json index c01d1f002034..3a37abdb0902 100644 --- a/sdk/storage/storage-queue/samples/tsconfig.json +++ b/sdk/storage/storage-queue/samples/tsconfig.json @@ -1,13 +1,9 @@ { - "extends": "../tsconfig.json", - "compilerOptions": { - "module": "commonjs" - }, - "include": [ - "**/*.ts" - ], - "exclude": [ - "../node_modules", - "../typings/**", - ] -} \ No newline at end of file + "extends": "../tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "typescript/dist" + }, + "include": ["typescript/src/**.ts"], + "exclude": ["typescript/*.json", "**/node_modules/", "../node_modules", "../typings"] +} diff --git a/sdk/storage/storage-queue/samples/typescript/README.md b/sdk/storage/storage-queue/samples/typescript/README.md new file mode 100644 index 000000000000..cf2ef94493af --- /dev/null +++ b/sdk/storage/storage-queue/samples/typescript/README.md @@ -0,0 +1,86 @@ +--- +page_type: sample +languages: + - typescript +products: + - azure + - azure-storage +urlFragment: storage-queue-typescript +--- + +# Azure Storage Queue client library samples for TypeScript + +These sample programs show how to use the TypeScript client libraries for Azure Storage Queues in some common scenarios. + +| **File Name** | **Description** | +| ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | +| [basic.ts][basic] | authenticate with the service using an account name & key (or anonymously with a SAS URL); send, peek, and dequeue messages | +| [withConnString.ts][withconnstring] | connect to and authenticate with the service using a connection string | +| [sharedKeyCred.ts][sharedkeycred] | authenticate with the service using an account name and a shared key | +| [anonymousCred.ts][anonymouscred] | authenticate with the service anonymously using a SAS URL | +| [azureAdAuth.ts][azureadauth] | authenticate with the service using Azure Active Directory | +| [proxyAuth.ts][proxyauth] | connect to the service using a proxy and authenticate with an account name & key | +| [iterators.ts][iterators] | different options for iterating over messages, showing options for paging, resuming paging etc. | +| [customPipeline.ts][custompipeline] | use custom HTTP pipeline options when connecting to the service | + +## Prerequisites + +The samples are compatible with Node.js >= 8.0.0, except for the samples that use the async `for await` syntax, which require a Node.js >= 10.0.0. + +Before running the samples in Node, they must be compiled to JavaScript using the TypeScript compiler. For more information on TypeScript, see the [TypeScript documentation][typescript]. Install the TypeScript compiler using + +```bash +npm install -g typescript +``` + +You need [an Azure subscription][freesub] and [an Azure Storage account][azstorage] to run these sample programs. Samples retrieve credentials to access the storage account from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function. + +Adapting the samples to run in the browser requires some additional consideration. For details, please see the [package README][package]. + +## Setup + +To run the samples using the published version of the package: + +1. Install the dependencies using `npm`: + +```bash +npm install +``` + +2. Compile the samples + +```bash +npm run build +``` + +3. Edit the file `sample.env`, adding the correct credentials to access the Azure service and run the samples. Then rename the file from `sample.env` to just `.env`. The sample programs will read this file automatically. + +4. Run whichever samples you like (note that some samples may require additional setup, see the table above): + +```bash +node dist/basic.js +``` + +Alternatively, run a single sample with the correct environment variables set (step 3 is not required if you do this), for example (cross-platform): + +```bash +npx cross-env ACCOUNT_NAME="" ACCOUNT_KEY="" node dist/basic.js +``` + +## Next Steps + +Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients. + +[anonymouscred]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-queue/samples/typescript/src/anonymousCred.ts +[azureadauth]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-queue/samples/typescript/src/azureAdAuth.ts +[basic]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-queue/samples/typescript/src/basic.ts +[custompipeline]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-queue/samples/typescript/src/customPipeline.ts +[iterators]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-queue/samples/typescript/src/iterators.ts +[proxyauth]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-queue/samples/typescript/src/proxyAuth.ts +[sharedkeycred]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-queue/samples/typescript/src/sharedKeyCred.ts +[withconnstring]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-queue/samples/typescript/src/withConnString.ts +[apiref]: https://docs.microsoft.com/javascript/api/@azure/storage-queue +[azstorage]: https://docs.microsoft.com/azure/storage/common/storage-account-overview +[freesub]: https://azure.microsoft.com/free/ +[package]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-queue/README.md +[typescript]: https://www.typescriptlang.org/docs/home.html diff --git a/sdk/storage/storage-queue/samples/typescript/package.json b/sdk/storage/storage-queue/samples/typescript/package.json new file mode 100644 index 000000000000..ad73a043af73 --- /dev/null +++ b/sdk/storage/storage-queue/samples/typescript/package.json @@ -0,0 +1,43 @@ +{ + "name": "azure-storage-queue-samples-ts", + "private": true, + "version": "0.1.0", + "description": "Azure Storage Queue client library samples for TypeScript", + "engine": { + "node": ">=8.0.0" + }, + "scripts": { + "build": "tsc", + "prebuild": "rimraf dist/" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Azure/azure-sdk-for-js.git" + }, + "keywords": [ + "Azure", + "Storage", + "File", + "Node.js", + "TypeScript" + ], + "author": "Microsoft Corporation", + "license": "MIT", + "bugs": { + "url": "https://github.com/Azure/azure-sdk-for-js/issues" + }, + "homepage": "https://github.com/Azure/azure-sdk-for-js#readme", + "sideEffects": false, + "dependencies": { + "@azure/identity": "latest", + "@azure/storage-queue": "latest", + "dotenv": "^8.2.0" + }, + "devDependencies": { + "@types/node": "^8.0.0", + "cross-env": "^6.0.3", + "rimraf": "^3.0.0", + "ts-node": "^8.3.0", + "typescript": "~3.6.4" + } +} diff --git a/sdk/storage/storage-queue/samples/typescript/sample.env b/sdk/storage/storage-queue/samples/typescript/sample.env new file mode 100644 index 000000000000..84d7ef49f88e --- /dev/null +++ b/sdk/storage/storage-queue/samples/typescript/sample.env @@ -0,0 +1,23 @@ +# Used in most samples. Retrieve these values from a storage account in the Azure Portal. +ACCOUNT_NAME= +ACCOUNT_KEY= + +# Used for withConnString +STORAGE_CONNECTION_STRING= + +# Used for the advanced and anonymousCred tests. Create a SAS token for a storage account in the Azure Portal. +ACCOUNT_SAS= + +# Used to authenticate using Azure AD as a service principal for role-based authentication. +# +# See the documentation for `EnvironmentCredential` at the following link: +# https://docs.microsoft.com/javascript/api/@azure/identity/environmentcredential +AZURE_TENANT_ID= +AZURE_CLIENT_ID= +AZURE_CLIENT_SECRET= + +# To run the proxyAuth sample, set up an HTTP proxy and enter your information: +PROXY_HOST= +PROXY_PORT= +PROXY_USERNAME= +PROXY_PASSWORD= diff --git a/sdk/storage/storage-queue/samples/typescript/anonymousCred.ts b/sdk/storage/storage-queue/samples/typescript/src/anonymousCred.ts similarity index 74% rename from sdk/storage/storage-queue/samples/typescript/anonymousCred.ts rename to sdk/storage/storage-queue/samples/typescript/src/anonymousCred.ts index b73850dfda6c..7a8b92eeb32a 100644 --- a/sdk/storage/storage-queue/samples/typescript/anonymousCred.ts +++ b/sdk/storage/storage-queue/samples/typescript/src/anonymousCred.ts @@ -1,10 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and SAS in main() */ -import { QueueServiceClient, AnonymousCredential } from "../../src"; // Change to "@azure/storage-queue" in your package +import { QueueServiceClient, AnonymousCredential } from "@azure/storage-queue"; + +import { runSample } from "./sampleHelpers"; -async function main() { +export async function main() { // Enter your storage account name and SAS const account = process.env.ACCOUNT_NAME || ""; const accountSas = process.env.ACCOUNT_SAS || ""; @@ -33,11 +38,6 @@ async function main() { ); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-queue/samples/typescript/azureAdAuth.ts b/sdk/storage/storage-queue/samples/typescript/src/azureAdAuth.ts similarity index 88% rename from sdk/storage/storage-queue/samples/typescript/azureAdAuth.ts rename to sdk/storage/storage-queue/samples/typescript/src/azureAdAuth.ts index fdebc142fd2d..9b5eb4332b12 100644 --- a/sdk/storage/storage-queue/samples/typescript/azureAdAuth.ts +++ b/sdk/storage/storage-queue/samples/typescript/src/azureAdAuth.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* ONLY AVAILABLE IN NODE.JS RUNTIME @@ -18,11 +21,13 @@ - Make sure you have AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET as environment variables to successfully execute the sample(Can leverage process.env). */ -import { QueueServiceClient } from "../../src"; // Change to "@azure/storage-queue" in your package +import { QueueServiceClient } from "@azure/storage-queue"; import { DefaultAzureCredential } from "@azure/identity"; -async function main() { +import { runSample } from "./sampleHelpers"; + +export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -51,11 +56,6 @@ async function main() { } } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-queue/samples/typescript/basic.ts b/sdk/storage/storage-queue/samples/typescript/src/basic.ts similarity index 92% rename from sdk/storage/storage-queue/samples/typescript/basic.ts rename to sdk/storage/storage-queue/samples/typescript/src/basic.ts index 5596cd8d0618..7736499d80fd 100644 --- a/sdk/storage/storage-queue/samples/typescript/basic.ts +++ b/sdk/storage/storage-queue/samples/typescript/src/basic.ts @@ -1,10 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -import { QueueServiceClient, StorageSharedKeyCredential } from "../../src"; // Change to "@azure/storage-queue" in your package +import { QueueServiceClient, StorageSharedKeyCredential } from "@azure/storage-queue"; + +import { runSample } from "./sampleHelpers"; -async function main() { +export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; @@ -88,11 +93,6 @@ async function main() { ); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-queue/samples/typescript/customPipeline.ts b/sdk/storage/storage-queue/samples/typescript/src/customPipeline.ts similarity index 84% rename from sdk/storage/storage-queue/samples/typescript/customPipeline.ts rename to sdk/storage/storage-queue/samples/typescript/src/customPipeline.ts index ac988cd05f87..ca1458aced07 100644 --- a/sdk/storage/storage-queue/samples/typescript/customPipeline.ts +++ b/sdk/storage/storage-queue/samples/typescript/src/customPipeline.ts @@ -1,10 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -import { QueueServiceClient, newPipeline, StorageSharedKeyCredential } from "../../src"; // Change to "@azure/storage-queue" in your package +import { QueueServiceClient, newPipeline, StorageSharedKeyCredential } from "@azure/storage-queue"; + +import { runSample } from "./sampleHelpers"; -async function main() { +export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; @@ -49,11 +54,6 @@ async function main() { ); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-queue/samples/typescript/iterators.ts b/sdk/storage/storage-queue/samples/typescript/src/iterators.ts similarity index 91% rename from sdk/storage/storage-queue/samples/typescript/iterators.ts rename to sdk/storage/storage-queue/samples/typescript/src/iterators.ts index e06bbc00cbb7..f7d4c5eae82a 100644 --- a/sdk/storage/storage-queue/samples/typescript/iterators.ts +++ b/sdk/storage/storage-queue/samples/typescript/src/iterators.ts @@ -1,10 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -import { QueueServiceClient, StorageSharedKeyCredential } from "../../src"; // Change to "@azure/storage-queue" in your package +import { QueueServiceClient, StorageSharedKeyCredential } from "@azure/storage-queue"; + +import { runSample } from "./sampleHelpers"; -async function main() { +export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; @@ -102,11 +107,6 @@ async function main() { } } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-queue/samples/typescript/proxyAuth.ts b/sdk/storage/storage-queue/samples/typescript/src/proxyAuth.ts similarity index 65% rename from sdk/storage/storage-queue/samples/typescript/proxyAuth.ts rename to sdk/storage/storage-queue/samples/typescript/src/proxyAuth.ts index 1b52e7b07084..46c6256dbf91 100644 --- a/sdk/storage/storage-queue/samples/typescript/proxyAuth.ts +++ b/sdk/storage/storage-queue/samples/typescript/src/proxyAuth.ts @@ -1,10 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -import { StorageSharedKeyCredential, QueueServiceClient } from "../../src"; // Change to "@azure/storage-queue" in your package +import { StorageSharedKeyCredential, QueueServiceClient } from "@azure/storage-queue"; + +import { runSample } from "./sampleHelpers"; -async function main() { +export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; @@ -13,20 +18,25 @@ async function main() { // StorageSharedKeyCredential is only avaiable in Node.js runtime, not in browsers const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey); + // Enter your proxy information + const proxyOptions = { + host: process.env.PROXY_HOST || "", + port: parseInt(process.env.PROXY_PORT || "3128"), + username: process.env.PROXY_USERNAME || "", + password: process.env.PROXY_PASSWORD || "" + }; + + if (proxyOptions.host === "") { + console.warn("Proxy information not provided, but it is required to run this sample. Exiting."); + return; + } + const queueServiceClient = new QueueServiceClient( `https://${account}.queue.core.windows.net`, sharedKeyCredential, { - // proxy can either be a URL like "http://localhost:3128" - // or - // an option bag consisting {host, port, username, password } - proxyOptions: { - host: "http://localhost", - port: 3128, - username: "username", - password: "password" - } // if proxy is undefined, the library tries to load the proxy settings from the environment variables like HTTP_PROXY + proxyOptions } ); @@ -45,11 +55,6 @@ async function main() { ); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed the sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-queue/samples/typescript/src/sampleHelpers.ts b/sdk/storage/storage-queue/samples/typescript/src/sampleHelpers.ts new file mode 100644 index 000000000000..841754c05a42 --- /dev/null +++ b/sdk/storage/storage-queue/samples/typescript/src/sampleHelpers.ts @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import * as dotenv from "dotenv"; +dotenv.config(); + +export function runSample(sampleMain: () => Promise): Promise { + if (!process.env["BATCH_RUN_SAMPLES"]) { + return sampleMain(); + } else { + return Promise.resolve(); + } +} diff --git a/sdk/storage/storage-queue/samples/typescript/sharedKeyCred.ts b/sdk/storage/storage-queue/samples/typescript/src/sharedKeyCred.ts similarity index 78% rename from sdk/storage/storage-queue/samples/typescript/sharedKeyCred.ts rename to sdk/storage/storage-queue/samples/typescript/src/sharedKeyCred.ts index 114c9371b500..8d636158e980 100644 --- a/sdk/storage/storage-queue/samples/typescript/sharedKeyCred.ts +++ b/sdk/storage/storage-queue/samples/typescript/src/sharedKeyCred.ts @@ -1,10 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -import { QueueServiceClient, StorageSharedKeyCredential } from "../../src"; // Change to "@azure/storage-queue" in your package +import { QueueServiceClient, StorageSharedKeyCredential } from "@azure/storage-queue"; + +import { runSample } from "./sampleHelpers"; -async function main() { +export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; @@ -33,11 +38,6 @@ async function main() { ); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-queue/samples/typescript/withConnString.ts b/sdk/storage/storage-queue/samples/typescript/src/withConnString.ts similarity index 79% rename from sdk/storage/storage-queue/samples/typescript/withConnString.ts rename to sdk/storage/storage-queue/samples/typescript/src/withConnString.ts index 329acd5c00f4..a323fba4e84a 100644 --- a/sdk/storage/storage-queue/samples/typescript/withConnString.ts +++ b/sdk/storage/storage-queue/samples/typescript/src/withConnString.ts @@ -1,10 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /* Setup: Enter your storage account name and shared key in main() */ -import { QueueServiceClient } from "../../src"; // Change to "@azure/storage-queue" in your package +import { QueueServiceClient } from "@azure/storage-queue"; + +import { runSample } from "./sampleHelpers"; -async function main() { +export async function main() { // Create Queue Service Client from Account connection string or SAS connection string // Account connection string example - `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net` // SAS connection string example - `BlobEndpoint=https://myaccount.blob.core.windows.net/;QueueEndpoint=https://myaccount.queue.core.windows.net/;FileEndpoint=https://myaccount.file.core.windows.net/;TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sasString` @@ -27,11 +32,6 @@ async function main() { ); } -// An async method returns a Promise object, which is compatible with then().catch() coding style. -main() - .then(() => { - console.log("Successfully executed sample."); - }) - .catch((err) => { - console.log(err.message); - }); +runSample(main).catch((err) => { + console.error("Error running sample:", err.message); +}); diff --git a/sdk/storage/storage-queue/samples/typescript/tsconfig.json b/sdk/storage/storage-queue/samples/typescript/tsconfig.json new file mode 100644 index 000000000000..4332663bf7b7 --- /dev/null +++ b/sdk/storage/storage-queue/samples/typescript/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "module": "commonjs", + "moduleResolution": "node", + + "lib": ["dom", "dom.iterable", "esnext.asynciterable"], + + "allowSyntheticDefaultImports": true, + + "outDir": "dist", + "rootDir": "src" + }, + "include": ["src/**.ts"], + "exclude": ["node_modules"] +} From 30b38b4ed89a8bd2948b25f9a5ecf1724f170ea9 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Thu, 12 Dec 2019 11:48:57 -0800 Subject: [PATCH 28/39] [run-samples] made the runner give a brief digest of errors --- common/scripts/run-samples.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/common/scripts/run-samples.js b/common/scripts/run-samples.js index 47c8ae69b961..13143eb7b7cb 100644 --- a/common/scripts/run-samples.js +++ b/common/scripts/run-samples.js @@ -81,7 +81,7 @@ async function main() { console.log("[run-samples] Running all samples in:", sampleDir); - let didError = false; + let errors = []; for await (const fileName of findMatchingFiles( sampleDir, @@ -92,15 +92,22 @@ async function main() { try { await sampleMain(); } catch (err) { - didError = true; - console.error("[run-samples] Error in", fileName); - console.error(err); + const truncatedError = err + .toString() + .split("\n")[0] + .slice(0, 100); + errors.push([path.basename(fileName), truncatedError]); + console.warn("[run-samples] Error in", fileName, ":", err); console.warn("[run-samples] Continuing ..."); } } - if (didError) { - throw new Error("errors occurred during sample execution"); + if (errors !== []) { + console.error("[run-samples] Errors occurred in the following files:"); + for (const [fileName, error] of errors) { + console.error(" -", fileName, "(", error, ")"); + } + process.exit(1); } } From 46ac9849e114904e17d724132fa12bcd780980d7 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Thu, 12 Dec 2019 12:16:22 -0800 Subject: [PATCH 29/39] [storage] Made aad auth samples skippable when AAD information is not available. --- .../storage-blob/samples/javascript/azureAdAuth.js | 12 ++++++++++++ .../samples/typescript/src/azureAdAuth.ts | 12 ++++++++++++ .../storage-queue/samples/javascript/azureAdAuth.js | 12 ++++++++++++ .../samples/typescript/src/azureAdAuth.ts | 12 ++++++++++++ 4 files changed, 48 insertions(+) diff --git a/sdk/storage/storage-blob/samples/javascript/azureAdAuth.js b/sdk/storage/storage-blob/samples/javascript/azureAdAuth.js index 6e6d2d457d3c..09c6e5398b5e 100644 --- a/sdk/storage/storage-blob/samples/javascript/azureAdAuth.js +++ b/sdk/storage/storage-blob/samples/javascript/azureAdAuth.js @@ -30,6 +30,18 @@ async function main() { // Enter your storage account name const account = process.env.ACCOUNT_NAME || ""; + // Azure AD Credential information is required to run this sample: + if ( + !process.env.AZURE_TENANT_ID || + !process.env.AZURE_CLIENT_ID || + !process.env.AZURE_CLIENT_SECRET + ) { + console.warn( + "Azure AD authentication information not provided, but it is required to run this sample. Exiting." + ); + return; + } + // ONLY AVAILABLE IN NODE.JS RUNTIME // DefaultAzureCredential will first look for Azure Active Directory (AAD) // client secret credentials in the following environment variables: diff --git a/sdk/storage/storage-blob/samples/typescript/src/azureAdAuth.ts b/sdk/storage/storage-blob/samples/typescript/src/azureAdAuth.ts index ae8614ff4550..1ec892d861ea 100644 --- a/sdk/storage/storage-blob/samples/typescript/src/azureAdAuth.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/azureAdAuth.ts @@ -30,6 +30,18 @@ export async function main() { // Enter your storage account name const account = process.env.ACCOUNT_NAME || ""; + // Azure AD Credential information is required to run this sample: + if ( + !process.env.AZURE_TENANT_ID || + !process.env.AZURE_CLIENT_ID || + !process.env.AZURE_CLIENT_SECRET + ) { + console.warn( + "Azure AD authentication information not provided, but it is required to run this sample. Exiting." + ); + return; + } + // ONLY AVAILABLE IN NODE.JS RUNTIME // DefaultAzureCredential will first look for Azure Active Directory (AAD) // client secret credentials in the following environment variables: diff --git a/sdk/storage/storage-queue/samples/javascript/azureAdAuth.js b/sdk/storage/storage-queue/samples/javascript/azureAdAuth.js index be44e4615651..a098e5604fb0 100644 --- a/sdk/storage/storage-queue/samples/javascript/azureAdAuth.js +++ b/sdk/storage/storage-queue/samples/javascript/azureAdAuth.js @@ -31,6 +31,18 @@ async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; + // Azure AD Credential information is required to run this sample: + if ( + !process.env.AZURE_TENANT_ID || + !process.env.AZURE_CLIENT_ID || + !process.env.AZURE_CLIENT_SECRET + ) { + console.warn( + "Azure AD authentication information not provided, but it is required to run this sample. Exiting." + ); + return; + } + // ONLY AVAILABLE IN NODE.JS RUNTIME // DefaultAzureCredential will first look for Azure Active Directory (AAD) // client secret credentials in the following environment variables: diff --git a/sdk/storage/storage-queue/samples/typescript/src/azureAdAuth.ts b/sdk/storage/storage-queue/samples/typescript/src/azureAdAuth.ts index 9b5eb4332b12..efdd3074ed74 100644 --- a/sdk/storage/storage-queue/samples/typescript/src/azureAdAuth.ts +++ b/sdk/storage/storage-queue/samples/typescript/src/azureAdAuth.ts @@ -31,6 +31,18 @@ export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; + // Azure AD Credential information is required to run this sample: + if ( + !process.env.AZURE_TENANT_ID || + !process.env.AZURE_CLIENT_ID || + !process.env.AZURE_CLIENT_SECRET + ) { + console.warn( + "Azure AD authentication information not provided, but it is required to run this sample. Exiting." + ); + return; + } + // ONLY AVAILABLE IN NODE.JS RUNTIME // DefaultAzureCredential will first look for Azure Active Directory (AAD) // client secret credentials in the following environment variables: From 77c602d2463a279c803a6a18c7492bdc70f8e235 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Thu, 12 Dec 2019 12:19:12 -0800 Subject: [PATCH 30/39] [storage] changed proxyAuth samples to use HTTP[s]_PROXY vars --- .../samples/javascript/proxyAuth.js | 24 +++++++------- .../samples/typescript/src/proxyAuth.ts | 24 +++++++------- .../samples/javascript/proxyAuth.js | 24 +++++++------- .../samples/typescript/src/proxyAuth.ts | 32 ++++++++++--------- .../samples/javascript/proxyAuth.js | 24 +++++++------- .../samples/typescript/src/proxyAuth.ts | 24 +++++++------- 6 files changed, 82 insertions(+), 70 deletions(-) diff --git a/sdk/storage/storage-blob/samples/javascript/proxyAuth.js b/sdk/storage/storage-blob/samples/javascript/proxyAuth.js index 86cd1e65118d..82701a54ee8e 100644 --- a/sdk/storage/storage-blob/samples/javascript/proxyAuth.js +++ b/sdk/storage/storage-blob/samples/javascript/proxyAuth.js @@ -18,15 +18,8 @@ async function main() { // StorageSharedKeyCredential is only avaiable in Node.js runtime, not in browsers const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey); - // Enter your proxy information - const proxyOptions = { - host: process.env.PROXY_HOST || "", - port: parseInt(process.env.PROXY_PORT || "3128"), - username: process.env.PROXY_USERNAME || "", - password: process.env.PROXY_PASSWORD || "" - }; - - if (proxyOptions.host === "") { + // To use the manual proxyOptions below, remove this block + if (!process.env.HTTP_PROXY || !process.env.HTTPS_PROXY) { console.warn("Proxy information not provided, but it is required to run this sample. Exiting."); return; } @@ -34,9 +27,18 @@ async function main() { const blobServiceClient = new BlobServiceClient( `https://${account}.blob.core.windows.net`, sharedKeyCredential, + // The library tries to load the proxy settings from the environment variables like HTTP_PROXY + // Alternatively, the service client accepts the following `proxyOptions` as part of its options: { - // if proxy is undefined, the library tries to load the proxy settings from the environment variables like HTTP_PROXY - proxyOptions + /* + proxyOptions : { + // To use these options, remove the section above that checks for HTTP_PROXY or HTTPS_PROXY + host: "http://localhost", + port: 3128, + username: "", + password: "" + } + */ } ); diff --git a/sdk/storage/storage-blob/samples/typescript/src/proxyAuth.ts b/sdk/storage/storage-blob/samples/typescript/src/proxyAuth.ts index 71ac8dbedb25..14f91802b9dc 100644 --- a/sdk/storage/storage-blob/samples/typescript/src/proxyAuth.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/proxyAuth.ts @@ -18,15 +18,8 @@ export async function main() { // StorageSharedKeyCredential is only avaiable in Node.js runtime, not in browsers const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey); - // Enter your proxy information - const proxyOptions = { - host: process.env.PROXY_HOST || "", - port: parseInt(process.env.PROXY_PORT || "3128"), - username: process.env.PROXY_USERNAME || "", - password: process.env.PROXY_PASSWORD || "" - }; - - if (proxyOptions.host === "") { + // To use the manual proxyOptions below, remove this block + if (!process.env.HTTP_PROXY || !process.env.HTTPS_PROXY) { console.warn("Proxy information not provided, but it is required to run this sample. Exiting."); return; } @@ -34,9 +27,18 @@ export async function main() { const blobServiceClient = new BlobServiceClient( `https://${account}.blob.core.windows.net`, sharedKeyCredential, + // The library tries to load the proxy settings from the environment variables like HTTP_PROXY + // Alternatively, the service client accepts the following `proxyOptions` as part of its options: { - // if proxy is undefined, the library tries to load the proxy settings from the environment variables like HTTP_PROXY - proxyOptions + /* + proxyOptions : { + // To use these options, remove the section above that checks for HTTP_PROXY or HTTPS_PROXY + host: "http://localhost", + port: 3128, + username: "", + password: "" + } + */ } ); diff --git a/sdk/storage/storage-file-share/samples/javascript/proxyAuth.js b/sdk/storage/storage-file-share/samples/javascript/proxyAuth.js index fbc8f22f1f08..9892074c05cc 100644 --- a/sdk/storage/storage-file-share/samples/javascript/proxyAuth.js +++ b/sdk/storage/storage-file-share/samples/javascript/proxyAuth.js @@ -18,15 +18,8 @@ async function main() { // StorageSharedKeyCredential is only avaiable in Node.js runtime, not in browsers const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey); - // Enter your proxy information - const proxyOptions = { - host: process.env.PROXY_HOST || "", - port: parseInt(process.env.PROXY_PORT || "3128"), - username: process.env.PROXY_USERNAME || "", - password: process.env.PROXY_PASSWORD || "" - }; - - if (proxyOptions.host === "") { + // To use the manual proxyOptions below, remove this block + if (!process.env.HTTP_PROXY || !process.env.HTTPS_PROXY) { console.warn("Proxy information not provided, but it is required to run this sample. Exiting."); return; } @@ -34,9 +27,18 @@ async function main() { const serviceClient = new ShareServiceClient( `https://${account}.file.core.windows.net`, sharedKeyCredential, + // The library tries to load the proxy settings from the environment variables like HTTP_PROXY + // Alternatively, the service client accepts the following `proxyOptions` as part of its options: { - // if proxy is undefined, the library tries to load the proxy settings from the environment variables like HTTP_PROXY - proxyOptions + /* + proxyOptions : { + // To use these options, remove the section above that checks for HTTP_PROXY or HTTPS_PROXY + host: "http://localhost", + port: 3128, + username: "", + password: "" + } + */ } ); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts b/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts index 396a351e664a..9019964d8a31 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts @@ -14,29 +14,31 @@ export async function main() { const account = process.env.ACCOUNT_NAME || ""; const accountKey = process.env.ACCOUNT_KEY || ""; - // Enter your proxy information - const proxyOptions = { - host: process.env.PROXY_HOST || "", - port: parseInt(process.env.PROXY_PORT || "3128"), - username: process.env.PROXY_USERNAME || "", - password: process.env.PROXY_PASSWORD || "" - }; - - if (proxyOptions.host === "") { - console.warn("Proxy information not provided, but it is required to run this sample. Exiting."); - return; - } - // Use StorageSharedKeyCredential with storage account and account key // StorageSharedKeyCredential is only avaiable in Node.js runtime, not in browsers const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey); + // To use the manual proxyOptions below, remove this block + if (!process.env.HTTP_PROXY || !process.env.HTTPS_PROXY) { + console.warn("Proxy information not provided, but it is required to run this sample. Exiting."); + return; + } + const serviceClient = new ShareServiceClient( `https://${account}.file.core.windows.net`, sharedKeyCredential, + // The library tries to load the proxy settings from the environment variables like HTTP_PROXY + // Alternatively, the service client accepts the following `proxyOptions` as part of its options: { - // if proxy is undefined, the library tries to load the proxy settings from the environment variables like HTTP_PROXY - proxyOptions + /* + proxyOptions : { + // To use these options, remove the section above that checks for HTTP_PROXY or HTTPS_PROXY + host: "http://localhost", + port: 3128, + username: "", + password: "" + } + */ } ); diff --git a/sdk/storage/storage-queue/samples/javascript/proxyAuth.js b/sdk/storage/storage-queue/samples/javascript/proxyAuth.js index 6abf6978e8c1..4f5967951f0b 100644 --- a/sdk/storage/storage-queue/samples/javascript/proxyAuth.js +++ b/sdk/storage/storage-queue/samples/javascript/proxyAuth.js @@ -18,15 +18,8 @@ async function main() { // StorageSharedKeyCredential is only avaiable in Node.js runtime, not in browsers const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey); - // Enter your proxy information - const proxyOptions = { - host: process.env.PROXY_HOST || "", - port: parseInt(process.env.PROXY_PORT || "3128"), - username: process.env.PROXY_USERNAME || "", - password: process.env.PROXY_PASSWORD || "" - }; - - if (proxyOptions.host === "") { + // To use the manual proxyOptions below, remove this block + if (!process.env.HTTP_PROXY || !process.env.HTTPS_PROXY) { console.warn("Proxy information not provided, but it is required to run this sample. Exiting."); return; } @@ -34,9 +27,18 @@ async function main() { const queueServiceClient = new QueueServiceClient( `https://${account}.queue.core.windows.net`, sharedKeyCredential, + // The library tries to load the proxy settings from the environment variables like HTTP_PROXY + // Alternatively, the service client accepts the following `proxyOptions` as part of its options: { - // if proxy is undefined, the library tries to load the proxy settings from the environment variables like HTTP_PROXY - proxyOptions + /* + proxyOptions : { + // To use these options, remove the section above that checks for HTTP_PROXY or HTTPS_PROXY + host: "http://localhost", + port: 3128, + username: "", + password: "" + } + */ } ); diff --git a/sdk/storage/storage-queue/samples/typescript/src/proxyAuth.ts b/sdk/storage/storage-queue/samples/typescript/src/proxyAuth.ts index 46c6256dbf91..6e1f58139b43 100644 --- a/sdk/storage/storage-queue/samples/typescript/src/proxyAuth.ts +++ b/sdk/storage/storage-queue/samples/typescript/src/proxyAuth.ts @@ -18,15 +18,8 @@ export async function main() { // StorageSharedKeyCredential is only avaiable in Node.js runtime, not in browsers const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey); - // Enter your proxy information - const proxyOptions = { - host: process.env.PROXY_HOST || "", - port: parseInt(process.env.PROXY_PORT || "3128"), - username: process.env.PROXY_USERNAME || "", - password: process.env.PROXY_PASSWORD || "" - }; - - if (proxyOptions.host === "") { + // To use the manual proxyOptions below, remove this block + if (!process.env.HTTP_PROXY || !process.env.HTTPS_PROXY) { console.warn("Proxy information not provided, but it is required to run this sample. Exiting."); return; } @@ -34,9 +27,18 @@ export async function main() { const queueServiceClient = new QueueServiceClient( `https://${account}.queue.core.windows.net`, sharedKeyCredential, + // The library tries to load the proxy settings from the environment variables like HTTP_PROXY + // Alternatively, the service client accepts the following `proxyOptions` as part of its options: { - // if proxy is undefined, the library tries to load the proxy settings from the environment variables like HTTP_PROXY - proxyOptions + /* + proxyOptions : { + // To use these options, remove the section above that checks for HTTP_PROXY or HTTPS_PROXY + host: "http://localhost", + port: 3128, + username: "", + password: "" + } + */ } ); From c1fd600497de5626c78c88fb3549b1c41f944b45 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Thu, 12 Dec 2019 12:58:12 -0800 Subject: [PATCH 31/39] [storage-file-share] Fixed a bug in iterators sample when no queues exist, updated readmes --- .../samples/javascript/README.md | 20 +++++++++---------- .../samples/javascript/iterators.js | 18 ++++++++++------- .../samples/typescript/README.md | 20 +++++++++---------- .../samples/typescript/src/iterators.ts | 18 ++++++++++------- 4 files changed, 42 insertions(+), 34 deletions(-) diff --git a/sdk/storage/storage-queue/samples/javascript/README.md b/sdk/storage/storage-queue/samples/javascript/README.md index 39307f32733c..57046bc373b8 100644 --- a/sdk/storage/storage-queue/samples/javascript/README.md +++ b/sdk/storage/storage-queue/samples/javascript/README.md @@ -12,16 +12,16 @@ urlFragment: storage-queue-javascript These sample programs show how to use the JavaScript client libraries for Azure Storage Queues in some common scenarios. -| **File Name** | **Description** | -| ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | -| [basic.js][basic] | authenticate with the service using an account name & key (or anonymously with a SAS URL); send, peek, and dequeue messages | -| [withConnString.js][withconnstring] | connect to and authenticate with the service using a connection string | -| [sharedKeyCred.js][sharedkeycred] | authenticate with the service using an account name and a shared key | -| [anonymousCred.js][anonymouscred] | authenticate with the service anonymously using a SAS URL | -| [azureAdAuth.js][azureadauth] | authenticate with the service using Azure Active Directory | -| [proxyAuth.js][proxyauth] | connect to the service using a proxy and authenticate with an account name & key | -| [iterators.js][iterators] | different options for iterating over messages, showing options for paging, resuming paging etc. | -| [customPipeline.js][custompipeline] | use custom HTTP pipeline options when connecting to the service | +| **File Name** | **Description** | +| ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [basic.js][basic] | authenticate with the service using an account name & key (or anonymously with a SAS URL); send, peek, and dequeue messages | +| [withConnString.js][withconnstring] | connect to and authenticate with the service using a connection string | +| [sharedKeyCred.js][sharedkeycred] | authenticate with the service using an account name and a shared key | +| [anonymousCred.js][anonymouscred] | authenticate with the service anonymously using a SAS URL | +| [azureAdAuth.js][azureadauth] | authenticate with the service using Azure Active Directory | +| [proxyAuth.js][proxyauth] | connect to the service using a proxy and authenticate with an account name & key | +| [iterators.js][iterators] | different options for iterating over messages, showing options for paging, resuming paging etc. (requires several queues to already exist in order to see output) | +| [customPipeline.js][custompipeline] | use custom HTTP pipeline options when connecting to the service | ## Prerequisites diff --git a/sdk/storage/storage-queue/samples/javascript/iterators.js b/sdk/storage/storage-queue/samples/javascript/iterators.js index 4fcb906e9438..77d00063e3fc 100644 --- a/sdk/storage/storage-queue/samples/javascript/iterators.js +++ b/sdk/storage/storage-queue/samples/javascript/iterators.js @@ -96,13 +96,17 @@ async function main() { } // Gets next marker let marker = response.value.continuationToken; - // Passing next marker as continuationToken - iterator = queueServiceClient.listQueues().byPage({ continuationToken: marker, maxPageSize: 10 }); - response = await iterator.next(); - // Prints 10 queue names - if (response.value.queueItems) { - for (const queueItem of response.value.queueItems) { - console.log(`Queue ${i++}: ${queueItem.name}`); + if (marker) { + // Passing next marker as continuationToken + iterator = queueServiceClient + .listQueues() + .byPage({ continuationToken: marker, maxPageSize: 10 }); + response = await iterator.next(); + // Prints 10 queue names + if (response.value.queueItems) { + for (const queueItem of response.value.queueItems) { + console.log(`Queue ${i++}: ${queueItem.name}`); + } } } } diff --git a/sdk/storage/storage-queue/samples/typescript/README.md b/sdk/storage/storage-queue/samples/typescript/README.md index cf2ef94493af..9107a5c4b234 100644 --- a/sdk/storage/storage-queue/samples/typescript/README.md +++ b/sdk/storage/storage-queue/samples/typescript/README.md @@ -12,16 +12,16 @@ urlFragment: storage-queue-typescript These sample programs show how to use the TypeScript client libraries for Azure Storage Queues in some common scenarios. -| **File Name** | **Description** | -| ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | -| [basic.ts][basic] | authenticate with the service using an account name & key (or anonymously with a SAS URL); send, peek, and dequeue messages | -| [withConnString.ts][withconnstring] | connect to and authenticate with the service using a connection string | -| [sharedKeyCred.ts][sharedkeycred] | authenticate with the service using an account name and a shared key | -| [anonymousCred.ts][anonymouscred] | authenticate with the service anonymously using a SAS URL | -| [azureAdAuth.ts][azureadauth] | authenticate with the service using Azure Active Directory | -| [proxyAuth.ts][proxyauth] | connect to the service using a proxy and authenticate with an account name & key | -| [iterators.ts][iterators] | different options for iterating over messages, showing options for paging, resuming paging etc. | -| [customPipeline.ts][custompipeline] | use custom HTTP pipeline options when connecting to the service | +| **File Name** | **Description** | +| ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [basic.ts][basic] | authenticate with the service using an account name & key (or anonymously with a SAS URL); send, peek, and dequeue messages | +| [withConnString.ts][withconnstring] | connect to and authenticate with the service using a connection string | +| [sharedKeyCred.ts][sharedkeycred] | authenticate with the service using an account name and a shared key | +| [anonymousCred.ts][anonymouscred] | authenticate with the service anonymously using a SAS URL | +| [azureAdAuth.ts][azureadauth] | authenticate with the service using Azure Active Directory | +| [proxyAuth.ts][proxyauth] | connect to the service using a proxy and authenticate with an account name & key | +| [iterators.ts][iterators] | different options for iterating over messages, showing options for paging, resuming paging etc. (requires several queues to already exist in order to see output) | +| [customPipeline.ts][custompipeline] | use custom HTTP pipeline options when connecting to the service | ## Prerequisites diff --git a/sdk/storage/storage-queue/samples/typescript/src/iterators.ts b/sdk/storage/storage-queue/samples/typescript/src/iterators.ts index f7d4c5eae82a..f298cf86cdfb 100644 --- a/sdk/storage/storage-queue/samples/typescript/src/iterators.ts +++ b/sdk/storage/storage-queue/samples/typescript/src/iterators.ts @@ -96,13 +96,17 @@ export async function main() { } // Gets next marker let marker = response.value.continuationToken; - // Passing next marker as continuationToken - iterator = queueServiceClient.listQueues().byPage({ continuationToken: marker, maxPageSize: 10 }); - response = await iterator.next(); - // Prints 10 queue names - if (response.value.queueItems) { - for (const queueItem of response.value.queueItems) { - console.log(`Queue ${i++}: ${queueItem.name}`); + if (marker) { + // Passing next marker as continuationToken + iterator = queueServiceClient + .listQueues() + .byPage({ continuationToken: marker, maxPageSize: 10 }); + response = await iterator.next(); + // Prints 10 queue names + if (response.value.queueItems) { + for (const queueItem of response.value.queueItems) { + console.log(`Queue ${i++}: ${queueItem.name}`); + } } } } From 6f97268e8707aec403a0bcdbc233b5082a1b874e Mon Sep 17 00:00:00 2001 From: Will Temple Date: Thu, 12 Dec 2019 13:18:19 -0800 Subject: [PATCH 32/39] [scripts] Make the scripts less wordy and fixed a bug in run-samples --- common/scripts/prep-samples.js | 3 +-- common/scripts/run-samples.js | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/common/scripts/prep-samples.js b/common/scripts/prep-samples.js index 4e239537ca3c..1f486ae04c4b 100644 --- a/common/scripts/prep-samples.js +++ b/common/scripts/prep-samples.js @@ -127,6 +127,7 @@ async function enableLocalRun(fileName, baseDir, pkgName) { : `const $1 = require("${relativePath}");` ); + console.log("[prep-samples] Updating imports in", fileName); return fs.writeFile(fileName, updatedContents, { encoding: "utf-8" }); } @@ -155,7 +156,6 @@ async function main() { entry.name.endsWith(".ts") && !entry.name.endsWith(".d.ts") )) { - console.log("[prep-samples] Updating imports in", fileName); await enableLocalRun(fileName, baseDir, package.name); } @@ -164,7 +164,6 @@ async function main() { jsDir, entry => entry.isFile() && entry.name.endsWith(".js") )) { - console.log("[prep-samples] Updating imports in", fileName); await enableLocalRun(fileName, baseDir, package.name); } } diff --git a/common/scripts/run-samples.js b/common/scripts/run-samples.js index 13143eb7b7cb..1c0705e45970 100644 --- a/common/scripts/run-samples.js +++ b/common/scripts/run-samples.js @@ -55,8 +55,6 @@ async function* findMatchingFiles(tsDir, matches) { } } else if (matches(entry)) { yield fullPath; - } else { - console.log("[run-samples] Skipping", fullPath); } } @@ -102,7 +100,7 @@ async function main() { } } - if (errors !== []) { + if (errors.length > 0) { console.error("[run-samples] Errors occurred in the following files:"); for (const [fileName, error] of errors) { console.error(" -", fileName, "(", error, ")"); From 98fa55c184714440db0a83ffbf602a30565a02f6 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Thu, 12 Dec 2019 13:29:15 -0800 Subject: [PATCH 33/39] [storage] Updated sample.env files to use HTTP_PROXY --- sdk/storage/storage-blob/samples/javascript/sample.env | 5 +---- sdk/storage/storage-blob/samples/typescript/sample.env | 5 +---- .../storage-file-share/samples/javascript/sample.env | 6 +----- .../storage-file-share/samples/typescript/sample.env | 6 +----- sdk/storage/storage-queue/samples/javascript/sample.env | 5 +---- sdk/storage/storage-queue/samples/typescript/sample.env | 5 +---- 6 files changed, 6 insertions(+), 26 deletions(-) diff --git a/sdk/storage/storage-blob/samples/javascript/sample.env b/sdk/storage/storage-blob/samples/javascript/sample.env index 84d7ef49f88e..92a81cac6547 100644 --- a/sdk/storage/storage-blob/samples/javascript/sample.env +++ b/sdk/storage/storage-blob/samples/javascript/sample.env @@ -17,7 +17,4 @@ AZURE_CLIENT_ID= AZURE_CLIENT_SECRET= # To run the proxyAuth sample, set up an HTTP proxy and enter your information: -PROXY_HOST= -PROXY_PORT= -PROXY_USERNAME= -PROXY_PASSWORD= +# HTTP_PROXY=http://localhost:3128 diff --git a/sdk/storage/storage-blob/samples/typescript/sample.env b/sdk/storage/storage-blob/samples/typescript/sample.env index 84d7ef49f88e..92a81cac6547 100644 --- a/sdk/storage/storage-blob/samples/typescript/sample.env +++ b/sdk/storage/storage-blob/samples/typescript/sample.env @@ -17,7 +17,4 @@ AZURE_CLIENT_ID= AZURE_CLIENT_SECRET= # To run the proxyAuth sample, set up an HTTP proxy and enter your information: -PROXY_HOST= -PROXY_PORT= -PROXY_USERNAME= -PROXY_PASSWORD= +# HTTP_PROXY=http://localhost:3128 diff --git a/sdk/storage/storage-file-share/samples/javascript/sample.env b/sdk/storage/storage-file-share/samples/javascript/sample.env index 3a0741abb9f0..020e02500273 100644 --- a/sdk/storage/storage-file-share/samples/javascript/sample.env +++ b/sdk/storage/storage-file-share/samples/javascript/sample.env @@ -13,8 +13,4 @@ SHARE_NAME= DIR_NAME= # To run the proxyAuth sample, set up an HTTP proxy and enter your information: -PROXY_HOST= -PROXY_PORT= -PROXY_USERNAME= -PROXY_PASSWORD= - +# HTTP_PROXY=http://localhost:3128 diff --git a/sdk/storage/storage-file-share/samples/typescript/sample.env b/sdk/storage/storage-file-share/samples/typescript/sample.env index 3a0741abb9f0..020e02500273 100644 --- a/sdk/storage/storage-file-share/samples/typescript/sample.env +++ b/sdk/storage/storage-file-share/samples/typescript/sample.env @@ -13,8 +13,4 @@ SHARE_NAME= DIR_NAME= # To run the proxyAuth sample, set up an HTTP proxy and enter your information: -PROXY_HOST= -PROXY_PORT= -PROXY_USERNAME= -PROXY_PASSWORD= - +# HTTP_PROXY=http://localhost:3128 diff --git a/sdk/storage/storage-queue/samples/javascript/sample.env b/sdk/storage/storage-queue/samples/javascript/sample.env index 84d7ef49f88e..92a81cac6547 100644 --- a/sdk/storage/storage-queue/samples/javascript/sample.env +++ b/sdk/storage/storage-queue/samples/javascript/sample.env @@ -17,7 +17,4 @@ AZURE_CLIENT_ID= AZURE_CLIENT_SECRET= # To run the proxyAuth sample, set up an HTTP proxy and enter your information: -PROXY_HOST= -PROXY_PORT= -PROXY_USERNAME= -PROXY_PASSWORD= +# HTTP_PROXY=http://localhost:3128 diff --git a/sdk/storage/storage-queue/samples/typescript/sample.env b/sdk/storage/storage-queue/samples/typescript/sample.env index 84d7ef49f88e..92a81cac6547 100644 --- a/sdk/storage/storage-queue/samples/typescript/sample.env +++ b/sdk/storage/storage-queue/samples/typescript/sample.env @@ -17,7 +17,4 @@ AZURE_CLIENT_ID= AZURE_CLIENT_SECRET= # To run the proxyAuth sample, set up an HTTP proxy and enter your information: -PROXY_HOST= -PROXY_PORT= -PROXY_USERNAME= -PROXY_PASSWORD= +# HTTP_PROXY=http://localhost:3128 From 787e631b6e2ece07c246737aca7e5aa121dd084c Mon Sep 17 00:00:00 2001 From: Will Temple Date: Mon, 16 Dec 2019 10:20:07 -0800 Subject: [PATCH 34/39] [storage] Fixed wrong keywords in three sample packages. --- sdk/storage/storage-blob/samples/javascript/package.json | 2 +- sdk/storage/storage-queue/samples/javascript/package.json | 2 +- sdk/storage/storage-queue/samples/typescript/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/storage/storage-blob/samples/javascript/package.json b/sdk/storage/storage-blob/samples/javascript/package.json index 10e6d8f578da..556fbb345f1b 100644 --- a/sdk/storage/storage-blob/samples/javascript/package.json +++ b/sdk/storage/storage-blob/samples/javascript/package.json @@ -13,7 +13,7 @@ "keywords": [ "Azure", "Storage", - "File", + "Blob", "Node.js", "JavaScript" ], diff --git a/sdk/storage/storage-queue/samples/javascript/package.json b/sdk/storage/storage-queue/samples/javascript/package.json index f851c75f6e96..808753da1928 100644 --- a/sdk/storage/storage-queue/samples/javascript/package.json +++ b/sdk/storage/storage-queue/samples/javascript/package.json @@ -13,7 +13,7 @@ "keywords": [ "Azure", "Storage", - "File", + "Queue", "Node.js", "JavaScript" ], diff --git a/sdk/storage/storage-queue/samples/typescript/package.json b/sdk/storage/storage-queue/samples/typescript/package.json index ad73a043af73..f3bc35e4e910 100644 --- a/sdk/storage/storage-queue/samples/typescript/package.json +++ b/sdk/storage/storage-queue/samples/typescript/package.json @@ -17,7 +17,7 @@ "keywords": [ "Azure", "Storage", - "File", + "Queue", "Node.js", "TypeScript" ], From 1e25ecedc7080216aead4ab4957a44c8c6220e36 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Mon, 16 Dec 2019 10:30:56 -0800 Subject: [PATCH 35/39] [prep-samples] tsDir -> dir --- common/scripts/prep-samples.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/scripts/prep-samples.js b/common/scripts/prep-samples.js index 1f486ae04c4b..4f4a7a063c10 100644 --- a/common/scripts/prep-samples.js +++ b/common/scripts/prep-samples.js @@ -40,15 +40,15 @@ const fs = /** * Breadth-first search for files matching a given predicate * - * @param {string} tsDir The root of the sample tree to search + * @param {string} dir The root of the sample tree to search * @param {(fs.Entry) => boolean} matches Predicate that decides whether or not a file entry is included * @returns */ -async function* findMatchingFiles(tsDir, matches) { - const initialFiles = await fs.readdir(tsDir, { withFileTypes: true }); +async function* findMatchingFiles(dir, matches) { + const initialFiles = await fs.readdir(dir, { withFileTypes: true }); // BFS Queue and queue index - const q = initialFiles.map(f => [f, tsDir]); + const q = initialFiles.map(f => [f, dir]); while (q.length) { // [fs.Dirent, string] (file and dirName part of the full path) From d6653e5dc643bf0168d79c2d147feee56e21803d Mon Sep 17 00:00:00 2001 From: Will Temple Date: Mon, 16 Dec 2019 12:04:16 -0800 Subject: [PATCH 36/39] [storage-queue] Removed need for sampleHelpers --- common/scripts/prep-samples.js | 8 +++++++- .../samples/javascript/anonymousCred.js | 8 +++----- .../samples/javascript/azureAdAuth.js | 8 +++----- .../storage-queue/samples/javascript/basic.js | 8 +++----- .../samples/javascript/customPipeline.js | 8 +++----- .../storage-queue/samples/javascript/iterators.js | 8 +++----- .../storage-queue/samples/javascript/proxyAuth.js | 8 +++----- .../samples/javascript/sampleHelpers.js | 15 --------------- .../samples/javascript/sharedKeyCred.js | 8 +++----- .../samples/javascript/withConnString.js | 8 +++----- .../samples/typescript/src/anonymousCred.ts | 4 +--- .../samples/typescript/src/azureAdAuth.ts | 4 +--- .../storage-queue/samples/typescript/src/basic.ts | 4 +--- .../samples/typescript/src/customPipeline.ts | 4 +--- .../samples/typescript/src/iterators.ts | 4 ++-- .../samples/typescript/src/proxyAuth.ts | 4 +--- .../samples/typescript/src/sampleHelpers.ts | 13 ------------- .../samples/typescript/src/sharedKeyCred.ts | 4 +--- .../samples/typescript/src/withConnString.ts | 4 +--- 19 files changed, 40 insertions(+), 92 deletions(-) delete mode 100644 sdk/storage/storage-queue/samples/javascript/sampleHelpers.js delete mode 100644 sdk/storage/storage-queue/samples/typescript/src/sampleHelpers.ts diff --git a/common/scripts/prep-samples.js b/common/scripts/prep-samples.js index 4f4a7a063c10..2390a9457dc4 100644 --- a/common/scripts/prep-samples.js +++ b/common/scripts/prep-samples.js @@ -120,13 +120,19 @@ async function enableLocalRun(fileName, baseDir, pkgName) { relativePath += "/src"; } - const updatedContents = fileContents.replace( + const importRenamedContents = fileContents.replace( importRegex, isTs ? `import $1 from "${relativePath}";` : `const $1 = require("${relativePath}");` ); + // Remove trailing call to main() + const updatedContents = importRenamedContents.replace( + /^main\(\)\.catch.*/s, + "\n" + ); + console.log("[prep-samples] Updating imports in", fileName); return fs.writeFile(fileName, updatedContents, { encoding: "utf-8" }); } diff --git a/sdk/storage/storage-queue/samples/javascript/anonymousCred.js b/sdk/storage/storage-queue/samples/javascript/anonymousCred.js index 48bbf304df39..5b803b60a265 100644 --- a/sdk/storage/storage-queue/samples/javascript/anonymousCred.js +++ b/sdk/storage/storage-queue/samples/javascript/anonymousCred.js @@ -7,8 +7,6 @@ const { QueueServiceClient, AnonymousCredential } = require("@azure/storage-queue"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and SAS const account = process.env.ACCOUNT_NAME || ""; @@ -38,8 +36,8 @@ async function main() { ); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-queue/samples/javascript/azureAdAuth.js b/sdk/storage/storage-queue/samples/javascript/azureAdAuth.js index a098e5604fb0..3e4eef84b735 100644 --- a/sdk/storage/storage-queue/samples/javascript/azureAdAuth.js +++ b/sdk/storage/storage-queue/samples/javascript/azureAdAuth.js @@ -25,8 +25,6 @@ const { QueueServiceClient } = require("@azure/storage-queue"); const { DefaultAzureCredential } = require("@azure/identity"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -68,8 +66,8 @@ async function main() { } } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-queue/samples/javascript/basic.js b/sdk/storage/storage-queue/samples/javascript/basic.js index 15eee55b482a..f8649d6ba214 100644 --- a/sdk/storage/storage-queue/samples/javascript/basic.js +++ b/sdk/storage/storage-queue/samples/javascript/basic.js @@ -7,8 +7,6 @@ const { QueueServiceClient, StorageSharedKeyCredential } = require("@azure/storage-queue"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -92,8 +90,8 @@ async function main() { ); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-queue/samples/javascript/customPipeline.js b/sdk/storage/storage-queue/samples/javascript/customPipeline.js index 9405c5e9bf58..f8941f941433 100644 --- a/sdk/storage/storage-queue/samples/javascript/customPipeline.js +++ b/sdk/storage/storage-queue/samples/javascript/customPipeline.js @@ -11,8 +11,6 @@ const { StorageSharedKeyCredential } = require("@azure/storage-queue"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -58,8 +56,8 @@ async function main() { ); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-queue/samples/javascript/iterators.js b/sdk/storage/storage-queue/samples/javascript/iterators.js index 77d00063e3fc..c05f0182a1e5 100644 --- a/sdk/storage/storage-queue/samples/javascript/iterators.js +++ b/sdk/storage/storage-queue/samples/javascript/iterators.js @@ -7,8 +7,6 @@ const { QueueServiceClient, StorageSharedKeyCredential } = require("@azure/storage-queue"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -111,8 +109,8 @@ async function main() { } } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-queue/samples/javascript/proxyAuth.js b/sdk/storage/storage-queue/samples/javascript/proxyAuth.js index 4f5967951f0b..e492602cae25 100644 --- a/sdk/storage/storage-queue/samples/javascript/proxyAuth.js +++ b/sdk/storage/storage-queue/samples/javascript/proxyAuth.js @@ -7,8 +7,6 @@ const { QueueServiceClient, StorageSharedKeyCredential } = require("@azure/storage-queue"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -57,8 +55,8 @@ async function main() { ); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-queue/samples/javascript/sampleHelpers.js b/sdk/storage/storage-queue/samples/javascript/sampleHelpers.js deleted file mode 100644 index 4b68987083ea..000000000000 --- a/sdk/storage/storage-queue/samples/javascript/sampleHelpers.js +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -const dotenv = require("dotenv"); -dotenv.config(); - -module.exports = { - runSample(sampleMain) { - if (!process.env["BATCH_RUN_SAMPLES"]) { - return sampleMain(); - } else { - return Promise.resolve(); - } - } -}; diff --git a/sdk/storage/storage-queue/samples/javascript/sharedKeyCred.js b/sdk/storage/storage-queue/samples/javascript/sharedKeyCred.js index 3df4d0e18e8f..60468c60c03b 100644 --- a/sdk/storage/storage-queue/samples/javascript/sharedKeyCred.js +++ b/sdk/storage/storage-queue/samples/javascript/sharedKeyCred.js @@ -7,8 +7,6 @@ const { QueueServiceClient, StorageSharedKeyCredential } = require("@azure/storage-queue"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -38,8 +36,8 @@ async function main() { ); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-queue/samples/javascript/withConnString.js b/sdk/storage/storage-queue/samples/javascript/withConnString.js index 8881905e9370..9bb10bc6195d 100644 --- a/sdk/storage/storage-queue/samples/javascript/withConnString.js +++ b/sdk/storage/storage-queue/samples/javascript/withConnString.js @@ -7,8 +7,6 @@ const { QueueServiceClient } = require("@azure/storage-queue"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Create Queue Service Client from Account connection string or SAS connection string // Account connection string example - `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net` @@ -32,8 +30,8 @@ async function main() { ); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-queue/samples/typescript/src/anonymousCred.ts b/sdk/storage/storage-queue/samples/typescript/src/anonymousCred.ts index 7a8b92eeb32a..7b0dd1d52885 100644 --- a/sdk/storage/storage-queue/samples/typescript/src/anonymousCred.ts +++ b/sdk/storage/storage-queue/samples/typescript/src/anonymousCred.ts @@ -7,8 +7,6 @@ import { QueueServiceClient, AnonymousCredential } from "@azure/storage-queue"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name and SAS const account = process.env.ACCOUNT_NAME || ""; @@ -38,6 +36,6 @@ export async function main() { ); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-queue/samples/typescript/src/azureAdAuth.ts b/sdk/storage/storage-queue/samples/typescript/src/azureAdAuth.ts index efdd3074ed74..7c0fbab464d7 100644 --- a/sdk/storage/storage-queue/samples/typescript/src/azureAdAuth.ts +++ b/sdk/storage/storage-queue/samples/typescript/src/azureAdAuth.ts @@ -25,8 +25,6 @@ import { QueueServiceClient } from "@azure/storage-queue"; import { DefaultAzureCredential } from "@azure/identity"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -68,6 +66,6 @@ export async function main() { } } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-queue/samples/typescript/src/basic.ts b/sdk/storage/storage-queue/samples/typescript/src/basic.ts index 7736499d80fd..86f4ad8fa5d9 100644 --- a/sdk/storage/storage-queue/samples/typescript/src/basic.ts +++ b/sdk/storage/storage-queue/samples/typescript/src/basic.ts @@ -7,8 +7,6 @@ import { QueueServiceClient, StorageSharedKeyCredential } from "@azure/storage-queue"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -93,6 +91,6 @@ export async function main() { ); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-queue/samples/typescript/src/customPipeline.ts b/sdk/storage/storage-queue/samples/typescript/src/customPipeline.ts index ca1458aced07..245626532895 100644 --- a/sdk/storage/storage-queue/samples/typescript/src/customPipeline.ts +++ b/sdk/storage/storage-queue/samples/typescript/src/customPipeline.ts @@ -7,8 +7,6 @@ import { QueueServiceClient, newPipeline, StorageSharedKeyCredential } from "@azure/storage-queue"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -54,6 +52,6 @@ export async function main() { ); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-queue/samples/typescript/src/iterators.ts b/sdk/storage/storage-queue/samples/typescript/src/iterators.ts index f298cf86cdfb..12570674f969 100644 --- a/sdk/storage/storage-queue/samples/typescript/src/iterators.ts +++ b/sdk/storage/storage-queue/samples/typescript/src/iterators.ts @@ -7,7 +7,7 @@ import { QueueServiceClient, StorageSharedKeyCredential } from "@azure/storage-queue"; -import { runSample } from "./sampleHelpers"; + export async function main() { // Enter your storage account name and shared key @@ -111,6 +111,6 @@ export async function main() { } } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-queue/samples/typescript/src/proxyAuth.ts b/sdk/storage/storage-queue/samples/typescript/src/proxyAuth.ts index 6e1f58139b43..4616ed1ec649 100644 --- a/sdk/storage/storage-queue/samples/typescript/src/proxyAuth.ts +++ b/sdk/storage/storage-queue/samples/typescript/src/proxyAuth.ts @@ -7,8 +7,6 @@ import { StorageSharedKeyCredential, QueueServiceClient } from "@azure/storage-queue"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -57,6 +55,6 @@ export async function main() { ); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-queue/samples/typescript/src/sampleHelpers.ts b/sdk/storage/storage-queue/samples/typescript/src/sampleHelpers.ts deleted file mode 100644 index 841754c05a42..000000000000 --- a/sdk/storage/storage-queue/samples/typescript/src/sampleHelpers.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -import * as dotenv from "dotenv"; -dotenv.config(); - -export function runSample(sampleMain: () => Promise): Promise { - if (!process.env["BATCH_RUN_SAMPLES"]) { - return sampleMain(); - } else { - return Promise.resolve(); - } -} diff --git a/sdk/storage/storage-queue/samples/typescript/src/sharedKeyCred.ts b/sdk/storage/storage-queue/samples/typescript/src/sharedKeyCred.ts index 8d636158e980..fbc13a880353 100644 --- a/sdk/storage/storage-queue/samples/typescript/src/sharedKeyCred.ts +++ b/sdk/storage/storage-queue/samples/typescript/src/sharedKeyCred.ts @@ -7,8 +7,6 @@ import { QueueServiceClient, StorageSharedKeyCredential } from "@azure/storage-queue"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -38,6 +36,6 @@ export async function main() { ); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-queue/samples/typescript/src/withConnString.ts b/sdk/storage/storage-queue/samples/typescript/src/withConnString.ts index a323fba4e84a..949f8a63a2bd 100644 --- a/sdk/storage/storage-queue/samples/typescript/src/withConnString.ts +++ b/sdk/storage/storage-queue/samples/typescript/src/withConnString.ts @@ -7,8 +7,6 @@ import { QueueServiceClient } from "@azure/storage-queue"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Create Queue Service Client from Account connection string or SAS connection string // Account connection string example - `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net` @@ -32,6 +30,6 @@ export async function main() { ); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); From e10e99b30d9fa2ca9fd5f95631276fa59bf5fd44 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Mon, 16 Dec 2019 12:16:59 -0800 Subject: [PATCH 37/39] [storage-file-share] Remove sampleHelpers --- common/scripts/prep-samples.js | 4 ++-- .../samples/javascript/advanced.js | 8 +++----- .../samples/javascript/anonymousCred.js | 8 +++----- .../samples/javascript/basic.js | 8 +++----- .../samples/javascript/customPipeline.js | 8 +++----- .../javascript/iterators-files-and-directories.js | 8 +++----- .../samples/javascript/iterators-handles.js | 8 +++----- .../samples/javascript/iterators-shares.js | 8 +++----- .../samples/javascript/proxyAuth.js | 8 +++----- .../samples/javascript/sampleHelpers.js | 15 --------------- .../samples/javascript/sharedKeyCred.js | 8 +++----- .../samples/javascript/withConnString.js | 8 +++----- .../samples/typescript/src/advanced.ts | 4 +--- .../samples/typescript/src/anonymousCred.ts | 4 +--- .../samples/typescript/src/basic.ts | 4 +--- .../samples/typescript/src/customPipeline.ts | 4 +--- .../src/iterators-files-and-directories.ts | 4 +--- .../samples/typescript/src/iterators-handles.ts | 4 +--- .../samples/typescript/src/iterators-shares.ts | 4 +--- .../samples/typescript/src/proxyAuth.ts | 4 +--- .../samples/typescript/src/sampleHelpers.ts | 13 ------------- .../samples/typescript/src/sharedKeyCred.ts | 4 +--- .../samples/typescript/src/withConnString.ts | 4 +--- 23 files changed, 42 insertions(+), 110 deletions(-) delete mode 100644 sdk/storage/storage-file-share/samples/javascript/sampleHelpers.js delete mode 100644 sdk/storage/storage-file-share/samples/typescript/src/sampleHelpers.ts diff --git a/common/scripts/prep-samples.js b/common/scripts/prep-samples.js index 2390a9457dc4..6598ef84a5b5 100644 --- a/common/scripts/prep-samples.js +++ b/common/scripts/prep-samples.js @@ -129,8 +129,8 @@ async function enableLocalRun(fileName, baseDir, pkgName) { // Remove trailing call to main() const updatedContents = importRenamedContents.replace( - /^main\(\)\.catch.*/s, - "\n" + new RegExp("main\\(\\)\\.catch.*", "s"), + "" ); console.log("[prep-samples] Updating imports in", fileName); diff --git a/sdk/storage/storage-file-share/samples/javascript/advanced.js b/sdk/storage/storage-file-share/samples/javascript/advanced.js index cd8a82a8b431..c209f0271064 100644 --- a/sdk/storage/storage-file-share/samples/javascript/advanced.js +++ b/sdk/storage/storage-file-share/samples/javascript/advanced.js @@ -13,8 +13,6 @@ const { newPipeline } = require("@azure/storage-file-share"); -const { runSample } = require("./sampleHelpers"); - // Enabling logging may help uncover useful information about failures. // In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. // Alternatively, logging can be enabled at runtime by calling `setLogLevel("info");` @@ -104,8 +102,8 @@ async function main() { console.log("deleted share"); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-file-share/samples/javascript/anonymousCred.js b/sdk/storage/storage-file-share/samples/javascript/anonymousCred.js index bd43b34e5ede..5f1d04dd36ef 100644 --- a/sdk/storage/storage-file-share/samples/javascript/anonymousCred.js +++ b/sdk/storage/storage-file-share/samples/javascript/anonymousCred.js @@ -7,8 +7,6 @@ const { ShareServiceClient, AnonymousCredential } = require("@azure/storage-file-share"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and SAS const account = process.env.ACCOUNT_NAME || ""; @@ -41,8 +39,8 @@ async function main() { console.log(`deleted share ${shareName}`); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-file-share/samples/javascript/basic.js b/sdk/storage/storage-file-share/samples/javascript/basic.js index b6724e17ef0b..ee24fdf092dd 100644 --- a/sdk/storage/storage-file-share/samples/javascript/basic.js +++ b/sdk/storage/storage-file-share/samples/javascript/basic.js @@ -7,8 +7,6 @@ const { ShareServiceClient, StorageSharedKeyCredential } = require("@azure/storage-file-share"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -95,8 +93,8 @@ async function streamToString(readableStream) { }); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-file-share/samples/javascript/customPipeline.js b/sdk/storage/storage-file-share/samples/javascript/customPipeline.js index 9f95ede4ed78..26dce67e53a6 100644 --- a/sdk/storage/storage-file-share/samples/javascript/customPipeline.js +++ b/sdk/storage/storage-file-share/samples/javascript/customPipeline.js @@ -11,8 +11,6 @@ const { newPipeline } = require("@azure/storage-file-share"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -52,8 +50,8 @@ async function main() { console.log(`deleted share ${shareName}`); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-file-share/samples/javascript/iterators-files-and-directories.js b/sdk/storage/storage-file-share/samples/javascript/iterators-files-and-directories.js index e1dea5d48545..e5eb7c0496b7 100644 --- a/sdk/storage/storage-file-share/samples/javascript/iterators-files-and-directories.js +++ b/sdk/storage/storage-file-share/samples/javascript/iterators-files-and-directories.js @@ -7,8 +7,6 @@ const { ShareServiceClient, StorageSharedKeyCredential } = require("@azure/storage-file-share"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -162,8 +160,8 @@ async function main() { console.log(`deleted share ${shareName}`); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-file-share/samples/javascript/iterators-handles.js b/sdk/storage/storage-file-share/samples/javascript/iterators-handles.js index d5701e2730df..963611f1fc6b 100644 --- a/sdk/storage/storage-file-share/samples/javascript/iterators-handles.js +++ b/sdk/storage/storage-file-share/samples/javascript/iterators-handles.js @@ -7,8 +7,6 @@ const { ShareServiceClient, StorageSharedKeyCredential } = require("@azure/storage-file-share"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name, shared key, share name, and directory name. // Please ensure your directory is mounted @@ -162,8 +160,8 @@ async function main() { } } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-file-share/samples/javascript/iterators-shares.js b/sdk/storage/storage-file-share/samples/javascript/iterators-shares.js index f01b1fcadbd4..77821b82a0ac 100644 --- a/sdk/storage/storage-file-share/samples/javascript/iterators-shares.js +++ b/sdk/storage/storage-file-share/samples/javascript/iterators-shares.js @@ -7,8 +7,6 @@ const { ShareServiceClient, StorageSharedKeyCredential } = require("@azure/storage-file-share"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -107,8 +105,8 @@ async function main() { } } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-file-share/samples/javascript/proxyAuth.js b/sdk/storage/storage-file-share/samples/javascript/proxyAuth.js index 9892074c05cc..e13be1d424df 100644 --- a/sdk/storage/storage-file-share/samples/javascript/proxyAuth.js +++ b/sdk/storage/storage-file-share/samples/javascript/proxyAuth.js @@ -7,8 +7,6 @@ const { ShareServiceClient, StorageSharedKeyCredential } = require("@azure/storage-file-share"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -53,8 +51,8 @@ async function main() { console.log(`deleted share ${shareName}`); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-file-share/samples/javascript/sampleHelpers.js b/sdk/storage/storage-file-share/samples/javascript/sampleHelpers.js deleted file mode 100644 index 4b68987083ea..000000000000 --- a/sdk/storage/storage-file-share/samples/javascript/sampleHelpers.js +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -const dotenv = require("dotenv"); -dotenv.config(); - -module.exports = { - runSample(sampleMain) { - if (!process.env["BATCH_RUN_SAMPLES"]) { - return sampleMain(); - } else { - return Promise.resolve(); - } - } -}; diff --git a/sdk/storage/storage-file-share/samples/javascript/sharedKeyCred.js b/sdk/storage/storage-file-share/samples/javascript/sharedKeyCred.js index 0f00205d57c9..e0a9ac7bc19d 100644 --- a/sdk/storage/storage-file-share/samples/javascript/sharedKeyCred.js +++ b/sdk/storage/storage-file-share/samples/javascript/sharedKeyCred.js @@ -7,8 +7,6 @@ const { ShareServiceClient, StorageSharedKeyCredential } = require("@azure/storage-file-share"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -41,8 +39,8 @@ async function main() { console.log(`deleted share ${shareName}`); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-file-share/samples/javascript/withConnString.js b/sdk/storage/storage-file-share/samples/javascript/withConnString.js index 0f4d31cead14..8646d1214e59 100644 --- a/sdk/storage/storage-file-share/samples/javascript/withConnString.js +++ b/sdk/storage/storage-file-share/samples/javascript/withConnString.js @@ -7,8 +7,6 @@ const { ShareServiceClient } = require("@azure/storage-file-share"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Create File Service Client from Account connection string or SAS connection string // Account connection string example - `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net` @@ -34,8 +32,8 @@ async function main() { console.log(`deleted share ${shareName}`); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-file-share/samples/typescript/src/advanced.ts b/sdk/storage/storage-file-share/samples/typescript/src/advanced.ts index 23cb97ba6925..e6bd3bfcf77f 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/advanced.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/advanced.ts @@ -9,8 +9,6 @@ import * as fs from "fs"; import { AbortController } from "@azure/abort-controller"; import { AnonymousCredential, ShareServiceClient, newPipeline } from "@azure/storage-file-share"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Fill in following settings before running this sample const account = process.env.ACCOUNT_NAME || ""; @@ -93,6 +91,6 @@ export async function main() { console.log("deleted share"); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/anonymousCred.ts b/sdk/storage/storage-file-share/samples/typescript/src/anonymousCred.ts index 641d127b8fa2..182001a40db7 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/anonymousCred.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/anonymousCred.ts @@ -7,8 +7,6 @@ import { ShareServiceClient, AnonymousCredential } from "@azure/storage-file-share"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name and SAS const account = process.env.ACCOUNT_NAME || ""; @@ -41,6 +39,6 @@ export async function main() { console.log(`deleted share ${shareName}`); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/basic.ts b/sdk/storage/storage-file-share/samples/typescript/src/basic.ts index c3bc8173f8ee..a5efc001b618 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/basic.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/basic.ts @@ -7,8 +7,6 @@ import { ShareServiceClient, StorageSharedKeyCredential } from "@azure/storage-file-share"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -95,6 +93,6 @@ async function streamToString(readableStream: NodeJS.ReadableStream) { }); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/customPipeline.ts b/sdk/storage/storage-file-share/samples/typescript/src/customPipeline.ts index 8aac3de2c2c9..192505a67334 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/customPipeline.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/customPipeline.ts @@ -11,8 +11,6 @@ import { StorageSharedKeyCredential } from "@azure/storage-file-share"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -52,6 +50,6 @@ export async function main() { console.log(`deleted share ${shareName}`); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/iterators-files-and-directories.ts b/sdk/storage/storage-file-share/samples/typescript/src/iterators-files-and-directories.ts index df8d78e7859e..87b42dbd471a 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/iterators-files-and-directories.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/iterators-files-and-directories.ts @@ -7,8 +7,6 @@ import { ShareServiceClient, StorageSharedKeyCredential } from "@azure/storage-file-share"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -162,6 +160,6 @@ export async function main() { console.log(`deleted share ${shareName}`); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts b/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts index acde9f1e045b..ba20b26d1bff 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/iterators-handles.ts @@ -7,8 +7,6 @@ import { ShareServiceClient, StorageSharedKeyCredential } from "@azure/storage-file-share"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name, shared key, share name, and directory name. // Please ensure your directory is mounted @@ -162,6 +160,6 @@ export async function main() { } } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/iterators-shares.ts b/sdk/storage/storage-file-share/samples/typescript/src/iterators-shares.ts index 3e914b568843..55af7a37c8c6 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/iterators-shares.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/iterators-shares.ts @@ -7,8 +7,6 @@ import { ShareServiceClient, StorageSharedKeyCredential } from "@azure/storage-file-share"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -107,6 +105,6 @@ export async function main() { } } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts b/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts index 9019964d8a31..d48e31440900 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/proxyAuth.ts @@ -7,8 +7,6 @@ import { StorageSharedKeyCredential, ShareServiceClient } from "@azure/storage-file-share"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -53,6 +51,6 @@ export async function main() { console.log(`deleted share ${shareName}`); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/sampleHelpers.ts b/sdk/storage/storage-file-share/samples/typescript/src/sampleHelpers.ts deleted file mode 100644 index 841754c05a42..000000000000 --- a/sdk/storage/storage-file-share/samples/typescript/src/sampleHelpers.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -import * as dotenv from "dotenv"; -dotenv.config(); - -export function runSample(sampleMain: () => Promise): Promise { - if (!process.env["BATCH_RUN_SAMPLES"]) { - return sampleMain(); - } else { - return Promise.resolve(); - } -} diff --git a/sdk/storage/storage-file-share/samples/typescript/src/sharedKeyCred.ts b/sdk/storage/storage-file-share/samples/typescript/src/sharedKeyCred.ts index 7ca67399531e..e92bbf370864 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/sharedKeyCred.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/sharedKeyCred.ts @@ -7,8 +7,6 @@ import { ShareServiceClient, StorageSharedKeyCredential } from "@azure/storage-file-share"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -41,6 +39,6 @@ export async function main() { console.log(`deleted share ${shareName}`); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-file-share/samples/typescript/src/withConnString.ts b/sdk/storage/storage-file-share/samples/typescript/src/withConnString.ts index dba1bee16952..9c05d32e9ef8 100644 --- a/sdk/storage/storage-file-share/samples/typescript/src/withConnString.ts +++ b/sdk/storage/storage-file-share/samples/typescript/src/withConnString.ts @@ -7,8 +7,6 @@ import { ShareServiceClient } from "@azure/storage-file-share"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Create File Service Client from Account connection string or SAS connection string // Account connection string example - `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net` @@ -34,6 +32,6 @@ export async function main() { console.log(`deleted share ${shareName}`); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); From 3145d3ca9fbd3838820bb82eaacc19601206b269 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Mon, 16 Dec 2019 12:31:28 -0800 Subject: [PATCH 38/39] [storage-blob] removed sampleHelpers --- .../storage-blob/samples/javascript/advanced.js | 8 +++----- .../samples/javascript/anonymousCred.js | 8 +++----- .../samples/javascript/azureAdAuth.js | 8 +++----- .../storage-blob/samples/javascript/basic.js | 8 +++----- .../samples/javascript/customPipeline.js | 8 +++----- .../samples/javascript/customizedClientHeaders.js | 8 +++----- .../samples/javascript/errorsAndResponses.js | 8 +++----- .../javascript/iterators-blobs-hierarchy.js | 8 +++----- .../samples/javascript/iterators-blobs.js | 8 +++----- .../samples/javascript/iterators-containers.js | 8 +++----- .../storage-blob/samples/javascript/proxyAuth.js | 8 +++----- .../samples/javascript/readingSnapshot.js | 8 +++----- .../samples/javascript/sampleHelpers.js | 15 --------------- .../samples/javascript/sharedKeyCred.js | 8 +++----- .../samples/javascript/withConnString.js | 8 +++----- .../samples/typescript/src/advanced.ts | 4 +--- .../samples/typescript/src/anonymousCred.ts | 4 +--- .../samples/typescript/src/azureAdAuth.ts | 4 +--- .../storage-blob/samples/typescript/src/basic.ts | 4 +--- .../samples/typescript/src/customPipeline.ts | 4 +--- .../typescript/src/customizedClientHeaders.ts | 4 +--- .../samples/typescript/src/errorsAndResponses.ts | 4 +--- .../typescript/src/iterators-blobs-hierarchy.ts | 4 +--- .../samples/typescript/src/iterators-blobs.ts | 4 +--- .../typescript/src/iterators-containers.ts | 4 +--- .../samples/typescript/src/proxyAuth.ts | 4 +--- .../samples/typescript/src/readingSnapshot.ts | 4 +--- .../samples/typescript/src/sampleHelpers.ts | 13 ------------- .../samples/typescript/src/sharedKeyCred.ts | 4 +--- .../samples/typescript/src/withConnString.ts | 4 +--- 30 files changed, 56 insertions(+), 140 deletions(-) delete mode 100644 sdk/storage/storage-blob/samples/javascript/sampleHelpers.js delete mode 100644 sdk/storage/storage-blob/samples/typescript/src/sampleHelpers.ts diff --git a/sdk/storage/storage-blob/samples/javascript/advanced.js b/sdk/storage/storage-blob/samples/javascript/advanced.js index 614cd816134d..8c17271098ee 100644 --- a/sdk/storage/storage-blob/samples/javascript/advanced.js +++ b/sdk/storage/storage-blob/samples/javascript/advanced.js @@ -9,8 +9,6 @@ const fs = require("fs"); const { AbortController } = require("@azure/abort-controller"); const { AnonymousCredential, BlobServiceClient, newPipeline } = require("@azure/storage-blob"); -const { runSample } = require("./sampleHelpers"); - // Enabling logging may help uncover useful information about failures. // In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. // Alternatively, logging can be enabled at runtime by calling `setLogLevel("info");` @@ -132,8 +130,8 @@ async function main() { console.log("deleted container"); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/anonymousCred.js b/sdk/storage/storage-blob/samples/javascript/anonymousCred.js index 428afc880e06..8b5f1657fe82 100644 --- a/sdk/storage/storage-blob/samples/javascript/anonymousCred.js +++ b/sdk/storage/storage-blob/samples/javascript/anonymousCred.js @@ -7,8 +7,6 @@ const { BlobServiceClient, AnonymousCredential } = require("@azure/storage-blob"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and SAS const account = process.env.ACCOUNT_NAME || ""; @@ -42,8 +40,8 @@ async function main() { console.log("deleted container"); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/azureAdAuth.js b/sdk/storage/storage-blob/samples/javascript/azureAdAuth.js index 09c6e5398b5e..fb43688cabe2 100644 --- a/sdk/storage/storage-blob/samples/javascript/azureAdAuth.js +++ b/sdk/storage/storage-blob/samples/javascript/azureAdAuth.js @@ -24,8 +24,6 @@ const { BlobServiceClient } = require("@azure/storage-blob"); const { DefaultAzureCredential } = require("@azure/identity"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name const account = process.env.ACCOUNT_NAME || ""; @@ -68,8 +66,8 @@ async function main() { console.log(`Created container ${containerName} successfully`, createContainerResponse.requestId); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/basic.js b/sdk/storage/storage-blob/samples/javascript/basic.js index 51cde552ddb4..b48c474bb516 100644 --- a/sdk/storage/storage-blob/samples/javascript/basic.js +++ b/sdk/storage/storage-blob/samples/javascript/basic.js @@ -7,8 +7,6 @@ const { BlobServiceClient, StorageSharedKeyCredential } = require("@azure/storage-blob"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -99,8 +97,8 @@ async function streamToString(readableStream) { }); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/customPipeline.js b/sdk/storage/storage-blob/samples/javascript/customPipeline.js index be7944457a74..4823d0ae2046 100644 --- a/sdk/storage/storage-blob/samples/javascript/customPipeline.js +++ b/sdk/storage/storage-blob/samples/javascript/customPipeline.js @@ -11,8 +11,6 @@ const { newPipeline } = require("@azure/storage-blob"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -53,8 +51,8 @@ async function main() { console.log("deleted container"); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/customizedClientHeaders.js b/sdk/storage/storage-blob/samples/javascript/customizedClientHeaders.js index 00a4efba5f1f..a05233749bcd 100644 --- a/sdk/storage/storage-blob/samples/javascript/customizedClientHeaders.js +++ b/sdk/storage/storage-blob/samples/javascript/customizedClientHeaders.js @@ -19,8 +19,6 @@ const { BaseRequestPolicy } = require("@azure/storage-blob"); -const { runSample } = require("./sampleHelpers"); - // Create a policy factory with create() method provided class RequestIDPolicyFactory { // Constructor to accept parameters @@ -85,8 +83,8 @@ async function main() { console.log(response._response.request.headers.get("x-ms-client-request-id")); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/errorsAndResponses.js b/sdk/storage/storage-blob/samples/javascript/errorsAndResponses.js index 024b6e0c9ec3..b40e9b2495f9 100644 --- a/sdk/storage/storage-blob/samples/javascript/errorsAndResponses.js +++ b/sdk/storage/storage-blob/samples/javascript/errorsAndResponses.js @@ -7,8 +7,6 @@ const { BlobServiceClient } = require("@azure/storage-blob"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Create Blob Service Client from Account connection string or SAS connection string // Account connection string example - `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net` @@ -150,8 +148,8 @@ async function streamToString(readableStream) { }); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/iterators-blobs-hierarchy.js b/sdk/storage/storage-blob/samples/javascript/iterators-blobs-hierarchy.js index cdc5c21da6c5..414c5137bea8 100644 --- a/sdk/storage/storage-blob/samples/javascript/iterators-blobs-hierarchy.js +++ b/sdk/storage/storage-blob/samples/javascript/iterators-blobs-hierarchy.js @@ -7,8 +7,6 @@ const { BlobServiceClient, StorageSharedKeyCredential } = require("@azure/storage-blob"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -136,8 +134,8 @@ async function main() { console.log("deleted container"); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/iterators-blobs.js b/sdk/storage/storage-blob/samples/javascript/iterators-blobs.js index fee6c48847f1..a942de620acf 100644 --- a/sdk/storage/storage-blob/samples/javascript/iterators-blobs.js +++ b/sdk/storage/storage-blob/samples/javascript/iterators-blobs.js @@ -7,8 +7,6 @@ const { BlobServiceClient, StorageSharedKeyCredential } = require("@azure/storage-blob"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -127,8 +125,8 @@ async function main() { console.log("deleted container"); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/iterators-containers.js b/sdk/storage/storage-blob/samples/javascript/iterators-containers.js index 12ff311f3894..d2a207407c1d 100644 --- a/sdk/storage/storage-blob/samples/javascript/iterators-containers.js +++ b/sdk/storage/storage-blob/samples/javascript/iterators-containers.js @@ -7,8 +7,6 @@ const { BlobServiceClient, StorageSharedKeyCredential } = require("@azure/storage-blob"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -116,8 +114,8 @@ async function main() { } } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/proxyAuth.js b/sdk/storage/storage-blob/samples/javascript/proxyAuth.js index 82701a54ee8e..c20efe0ae404 100644 --- a/sdk/storage/storage-blob/samples/javascript/proxyAuth.js +++ b/sdk/storage/storage-blob/samples/javascript/proxyAuth.js @@ -7,8 +7,6 @@ const { BlobServiceClient, StorageSharedKeyCredential } = require("@azure/storage-blob"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -50,8 +48,8 @@ async function main() { console.log(`Created container ${containerName} successfully`, createContainerResponse.requestId); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/readingSnapshot.js b/sdk/storage/storage-blob/samples/javascript/readingSnapshot.js index c34483abd9f7..22126e7a40f8 100644 --- a/sdk/storage/storage-blob/samples/javascript/readingSnapshot.js +++ b/sdk/storage/storage-blob/samples/javascript/readingSnapshot.js @@ -23,8 +23,6 @@ const { BlobServiceClient, StorageSharedKeyCredential } = require("@azure/storage-blob"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -87,8 +85,8 @@ async function streamToString(readableStream) { }); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/sampleHelpers.js b/sdk/storage/storage-blob/samples/javascript/sampleHelpers.js deleted file mode 100644 index 4b68987083ea..000000000000 --- a/sdk/storage/storage-blob/samples/javascript/sampleHelpers.js +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -const dotenv = require("dotenv"); -dotenv.config(); - -module.exports = { - runSample(sampleMain) { - if (!process.env["BATCH_RUN_SAMPLES"]) { - return sampleMain(); - } else { - return Promise.resolve(); - } - } -}; diff --git a/sdk/storage/storage-blob/samples/javascript/sharedKeyCred.js b/sdk/storage/storage-blob/samples/javascript/sharedKeyCred.js index f0a9b2dc1e23..a9085cceb204 100644 --- a/sdk/storage/storage-blob/samples/javascript/sharedKeyCred.js +++ b/sdk/storage/storage-blob/samples/javascript/sharedKeyCred.js @@ -7,8 +7,6 @@ const { BlobServiceClient, StorageSharedKeyCredential } = require("@azure/storage-blob"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -42,8 +40,8 @@ async function main() { console.log("deleted container"); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/javascript/withConnString.js b/sdk/storage/storage-blob/samples/javascript/withConnString.js index 6244d986b614..5dc16dddd7be 100644 --- a/sdk/storage/storage-blob/samples/javascript/withConnString.js +++ b/sdk/storage/storage-blob/samples/javascript/withConnString.js @@ -7,8 +7,6 @@ const { BlobServiceClient } = require("@azure/storage-blob"); -const { runSample } = require("./sampleHelpers"); - async function main() { // Create Blob Service Client from Account connection string or SAS connection string // Account connection string example - `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net` @@ -35,8 +33,8 @@ async function main() { console.log("deleted container"); } -runSample(main).catch((err) => { +module.exports = { main }; + +main().catch((err) => { console.error("Error running sample:", err.message); }); - -module.exports = { main }; diff --git a/sdk/storage/storage-blob/samples/typescript/src/advanced.ts b/sdk/storage/storage-blob/samples/typescript/src/advanced.ts index a5b17b39d924..45749d72b489 100644 --- a/sdk/storage/storage-blob/samples/typescript/src/advanced.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/advanced.ts @@ -16,8 +16,6 @@ import { AnonymousCredential, BlobServiceClient, newPipeline } from "@azure/stor import { setLogLevel } from "@azure/logger"; setLogLevel("info"); -import { runSample } from "./sampleHelpers"; - export async function main() { // Fill in following settings before running this sample const account = process.env.ACCOUNT_NAME || ""; @@ -132,6 +130,6 @@ export async function main() { console.log("deleted container"); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-blob/samples/typescript/src/anonymousCred.ts b/sdk/storage/storage-blob/samples/typescript/src/anonymousCred.ts index 22873ba7b1ff..d743ed1ecc9b 100644 --- a/sdk/storage/storage-blob/samples/typescript/src/anonymousCred.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/anonymousCred.ts @@ -7,8 +7,6 @@ import { BlobServiceClient, AnonymousCredential } from "@azure/storage-blob"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name and SAS const account = process.env.ACCOUNT_NAME || ""; @@ -42,6 +40,6 @@ export async function main() { console.log("deleted container"); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-blob/samples/typescript/src/azureAdAuth.ts b/sdk/storage/storage-blob/samples/typescript/src/azureAdAuth.ts index 1ec892d861ea..ae8cd0e9ae13 100644 --- a/sdk/storage/storage-blob/samples/typescript/src/azureAdAuth.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/azureAdAuth.ts @@ -24,8 +24,6 @@ import { BlobServiceClient } from "@azure/storage-blob"; import { DefaultAzureCredential } from "@azure/identity"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name const account = process.env.ACCOUNT_NAME || ""; @@ -68,6 +66,6 @@ export async function main() { console.log(`Created container ${containerName} successfully`, createContainerResponse.requestId); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-blob/samples/typescript/src/basic.ts b/sdk/storage/storage-blob/samples/typescript/src/basic.ts index a5c76c7f8f74..f13e5e8789cb 100644 --- a/sdk/storage/storage-blob/samples/typescript/src/basic.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/basic.ts @@ -11,8 +11,6 @@ import { BlobDownloadResponseModel } from "@azure/storage-blob"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -103,6 +101,6 @@ async function streamToString(readableStream: NodeJS.ReadableStream) { }); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-blob/samples/typescript/src/customPipeline.ts b/sdk/storage/storage-blob/samples/typescript/src/customPipeline.ts index 5832ecbc9f51..d1123d40911d 100644 --- a/sdk/storage/storage-blob/samples/typescript/src/customPipeline.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/customPipeline.ts @@ -7,8 +7,6 @@ import { BlobServiceClient, StorageSharedKeyCredential, newPipeline } from "@azure/storage-blob"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -49,6 +47,6 @@ export async function main() { console.log("deleted container"); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-blob/samples/typescript/src/customizedClientHeaders.ts b/sdk/storage/storage-blob/samples/typescript/src/customizedClientHeaders.ts index ec57fb0bcd83..eaef5ec8bd8e 100644 --- a/sdk/storage/storage-blob/samples/typescript/src/customizedClientHeaders.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/customizedClientHeaders.ts @@ -22,8 +22,6 @@ import { RequestPolicyOptions } from "@azure/storage-blob"; -import { runSample } from "./sampleHelpers"; - // Create a policy factory with create() method provided class RequestIDPolicyFactory { prefix: string; @@ -90,6 +88,6 @@ export async function main() { console.log(response._response.request.headers.get("x-ms-client-request-id")); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-blob/samples/typescript/src/errorsAndResponses.ts b/sdk/storage/storage-blob/samples/typescript/src/errorsAndResponses.ts index 701459546b4b..ff53ca26233c 100644 --- a/sdk/storage/storage-blob/samples/typescript/src/errorsAndResponses.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/errorsAndResponses.ts @@ -7,8 +7,6 @@ import { BlobServiceClient } from "@azure/storage-blob"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Create Blob Service Client from Account connection string or SAS connection string // Account connection string example - `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net` @@ -150,6 +148,6 @@ async function streamToString(readableStream: NodeJS.ReadableStream) { }); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-blob/samples/typescript/src/iterators-blobs-hierarchy.ts b/sdk/storage/storage-blob/samples/typescript/src/iterators-blobs-hierarchy.ts index c082475fdeb8..2cda531e30b2 100644 --- a/sdk/storage/storage-blob/samples/typescript/src/iterators-blobs-hierarchy.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/iterators-blobs-hierarchy.ts @@ -7,8 +7,6 @@ import { BlobServiceClient, StorageSharedKeyCredential } from "@azure/storage-blob"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -136,6 +134,6 @@ export async function main() { console.log("deleted container"); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-blob/samples/typescript/src/iterators-blobs.ts b/sdk/storage/storage-blob/samples/typescript/src/iterators-blobs.ts index 791fdd72f7f8..383b3dd7775a 100644 --- a/sdk/storage/storage-blob/samples/typescript/src/iterators-blobs.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/iterators-blobs.ts @@ -7,8 +7,6 @@ import { BlobServiceClient, StorageSharedKeyCredential } from "@azure/storage-blob"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -127,6 +125,6 @@ export async function main() { console.log("deleted container"); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-blob/samples/typescript/src/iterators-containers.ts b/sdk/storage/storage-blob/samples/typescript/src/iterators-containers.ts index 4bc8a18d53ec..faf8e05eb705 100644 --- a/sdk/storage/storage-blob/samples/typescript/src/iterators-containers.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/iterators-containers.ts @@ -7,8 +7,6 @@ import { BlobServiceClient, StorageSharedKeyCredential } from "@azure/storage-blob"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -108,6 +106,6 @@ export async function main() { } } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-blob/samples/typescript/src/proxyAuth.ts b/sdk/storage/storage-blob/samples/typescript/src/proxyAuth.ts index 14f91802b9dc..59082a866743 100644 --- a/sdk/storage/storage-blob/samples/typescript/src/proxyAuth.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/proxyAuth.ts @@ -7,8 +7,6 @@ import { BlobServiceClient, StorageSharedKeyCredential } from "@azure/storage-blob"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -50,6 +48,6 @@ export async function main() { console.log(`Created container ${containerName} successfully`, createContainerResponse.requestId); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-blob/samples/typescript/src/readingSnapshot.ts b/sdk/storage/storage-blob/samples/typescript/src/readingSnapshot.ts index 7c2d7d5834a2..4d212eaecd20 100644 --- a/sdk/storage/storage-blob/samples/typescript/src/readingSnapshot.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/readingSnapshot.ts @@ -23,8 +23,6 @@ import { BlobServiceClient, StorageSharedKeyCredential } from "@azure/storage-blob"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -87,6 +85,6 @@ async function streamToString(readableStream: NodeJS.ReadableStream) { }); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-blob/samples/typescript/src/sampleHelpers.ts b/sdk/storage/storage-blob/samples/typescript/src/sampleHelpers.ts deleted file mode 100644 index 841754c05a42..000000000000 --- a/sdk/storage/storage-blob/samples/typescript/src/sampleHelpers.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -import * as dotenv from "dotenv"; -dotenv.config(); - -export function runSample(sampleMain: () => Promise): Promise { - if (!process.env["BATCH_RUN_SAMPLES"]) { - return sampleMain(); - } else { - return Promise.resolve(); - } -} diff --git a/sdk/storage/storage-blob/samples/typescript/src/sharedKeyCred.ts b/sdk/storage/storage-blob/samples/typescript/src/sharedKeyCred.ts index 321e7be21ddf..7680c443b72a 100644 --- a/sdk/storage/storage-blob/samples/typescript/src/sharedKeyCred.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/sharedKeyCred.ts @@ -7,8 +7,6 @@ import { BlobServiceClient, StorageSharedKeyCredential } from "@azure/storage-blob"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Enter your storage account name and shared key const account = process.env.ACCOUNT_NAME || ""; @@ -42,6 +40,6 @@ export async function main() { console.log("deleted container"); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); diff --git a/sdk/storage/storage-blob/samples/typescript/src/withConnString.ts b/sdk/storage/storage-blob/samples/typescript/src/withConnString.ts index 41fc1bb55859..594c5dcb4d78 100644 --- a/sdk/storage/storage-blob/samples/typescript/src/withConnString.ts +++ b/sdk/storage/storage-blob/samples/typescript/src/withConnString.ts @@ -7,8 +7,6 @@ import { BlobServiceClient } from "@azure/storage-blob"; -import { runSample } from "./sampleHelpers"; - export async function main() { // Create Blob Service Client from Account connection string or SAS connection string // Account connection string example - `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net` @@ -35,6 +33,6 @@ export async function main() { console.log("deleted container"); } -runSample(main).catch((err) => { +main().catch((err) => { console.error("Error running sample:", err.message); }); From 3be448343eb4930f073bfd729ba25ffe5f07c890 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Mon, 16 Dec 2019 12:46:16 -0800 Subject: [PATCH 39/39] [run-samples] Removed outdated sampleHelpers.js from ignore list --- common/scripts/run-samples.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/scripts/run-samples.js b/common/scripts/run-samples.js index 1c0705e45970..aeabbbc7b552 100644 --- a/common/scripts/run-samples.js +++ b/common/scripts/run-samples.js @@ -11,7 +11,7 @@ const baseFS = require("fs"); const path = require("path"); -const IGNORE = ["node_modules", "sampleHelpers.js"]; +const IGNORE = ["node_modules"]; // Node >= 10 provide fs.promises, but since we're still building Node 8 for now // we need to use util.promisify if fs.promises doesn't exist