UNPKG

2.04 kBJavaScriptView Raw
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT license.
3import { StorageClientContext } from "./generated/src/storageClientContext";
4import { escapeURLPath, getURLScheme, iEqual, getAccountNameFromUrl } from "./utils/utils.common";
5import { AnonymousCredential } from "./credentials/AnonymousCredential";
6import { StorageSharedKeyCredential } from "./credentials/StorageSharedKeyCredential";
7import { isTokenCredential, isNode } from "@azure/core-http";
8/**
9 * A StorageClient represents a based URL class for {@link BlobServiceClient}, {@link ContainerClient}
10 * and etc.
11 */
12export class StorageClient {
13 /**
14 * Creates an instance of StorageClient.
15 * @param url - url to resource
16 * @param pipeline - request policy pipeline.
17 */
18 constructor(url, pipeline) {
19 // URL should be encoded and only once, protocol layer shouldn't encode URL again
20 this.url = escapeURLPath(url);
21 this.accountName = getAccountNameFromUrl(url);
22 this.pipeline = pipeline;
23 this.storageClientContext = new StorageClientContext(this.url, pipeline.toServiceClientOptions());
24 this.isHttps = iEqual(getURLScheme(this.url) || "", "https");
25 this.credential = new AnonymousCredential();
26 for (const factory of this.pipeline.factories) {
27 if ((isNode && factory instanceof StorageSharedKeyCredential) ||
28 factory instanceof AnonymousCredential) {
29 this.credential = factory;
30 }
31 else if (isTokenCredential(factory.credential)) {
32 // Only works if the factory has been attached a "credential" property.
33 // We do that in newPipeline() when using TokenCredential.
34 this.credential = factory.credential;
35 }
36 }
37 // Override protocol layer's default content-type
38 const storageClientContext = this.storageClientContext;
39 storageClientContext.requestContentType = undefined;
40 }
41}
42//# sourceMappingURL=StorageClient.js.map
\No newline at end of file