-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
customPipeline.ts
60 lines (49 loc) · 1.82 KB
/
customPipeline.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
* @summary use custom HTTP pipeline options when connecting to the service
*/
import {
newPipeline,
ShareServiceClient,
StorageSharedKeyCredential
} from "@azure/storage-file-share";
// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();
export async function main() {
// Enter your storage account name and shared key
const account = process.env.ACCOUNT_NAME || "";
const accountKey = process.env.ACCOUNT_KEY || "";
// Use StorageSharedKeyCredential with storage account and account key
// StorageSharedKeyCredential is only available in Node.js runtime, not in browsers
const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);
// Use sharedKeyCredential or anonymousCredential to create a pipeline
const pipeline = newPipeline(sharedKeyCredential, {
// httpClient: MyHTTPClient, // A customized HTTP client implementing IHttpClient interface
retryOptions: { maxTries: 4 }, // Retry options
userAgentOptions: { userAgentPrefix: "AdvancedSample V1.0.0" } // Customized telemetry string
});
// List shares
const serviceClient = new ShareServiceClient(
`https://${account}.file.core.windows.net`,
pipeline
);
console.log("Shares:");
let i = 1;
for await (const share of serviceClient.listShares()) {
console.log(`Share ${i++}: ${share.name}`);
}
// Create a share
const shareName = `newshare${new Date().getTime()}`;
const shareClient = serviceClient.getShareClient(shareName);
await shareClient.create();
console.log(`Created share ${shareClient.name} successfully.`);
// Delete share
await shareClient.delete();
console.log(`Deleted share ${shareClient.name}.`);
}
main().catch((error) => {
console.error(error);
process.exit(1);
});