-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
proxyAuth.ts
61 lines (51 loc) · 1.98 KB
/
proxyAuth.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
61
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
* @summary configure proxy settings when connecting to the storage service
*/
import { StorageSharedKeyCredential, ShareServiceClient } 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);
// 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:
{
/*
proxyOptions : {
// To use these options, remove the section above that checks for HTTP_PROXY or HTTPS_PROXY
host: "http://localhost",
port: 3128,
username: "<username>",
password: "<password>"
}
*/
}
);
// 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);
});