-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
StorageClient.ts
103 lines (96 loc) · 3.34 KB
/
StorageClient.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { StorageClientContext } from "./generated/src/storageClientContext";
import { Pipeline } from "./Pipeline";
import { escapeURLPath, getURLScheme, iEqual, getAccountNameFromUrl } from "./utils/utils.common";
import { AnonymousCredential } from "./credentials/AnonymousCredential";
import { StorageSharedKeyCredential } from "./credentials/StorageSharedKeyCredential";
import { TokenCredential, isTokenCredential, isNode } from "@azure/core-http";
import { OperationTracingOptions } from "@azure/core-tracing";
/**
* An interface for options common to every remote operation.
*/
export interface CommonOptions {
/**
* Options to configure spans created when tracing is enabled.
*/
tracingOptions?: OperationTracingOptions;
}
/**
* A StorageClient represents a based URL class for {@link BlobServiceClient}, {@link ContainerClient}
* and etc.
*
* @export
* @class StorageClient
*/
export abstract class StorageClient {
/**
* Encoded URL string value.
*
* @type {string}
* @memberof StorageClient
*/
public readonly url: string;
public readonly accountName: string;
/**
* Request policy pipeline.
*
* @internal
* @ignore
* @type {Pipeline}
* @memberof StorageClient
*/
protected readonly pipeline: Pipeline;
/**
* Such as AnonymousCredential, StorageSharedKeyCredential or any credential from the @azure/identity package to authenticate requests to the service. You can also provide an object that implements the TokenCredential interface. If not specified, AnonymousCredential is used.
*
* @type {StorageSharedKeyCredential | AnonymousCredential | TokenCredential}
* @memberof StorageClient
*/
public readonly credential: StorageSharedKeyCredential | AnonymousCredential | TokenCredential;
/**
* StorageClient is a reference to protocol layer operations entry, which is
* generated by AutoRest generator.
*
* @protected
* @type {StorageClientContext}
* @memberof StorageClient
*/
protected readonly storageClientContext: StorageClientContext;
/**
* @protected
* @type {boolean}
* @memberof StorageClient
*/
protected readonly isHttps: boolean;
/**
* Creates an instance of StorageClient.
* @param {string} url url to resource
* @param {Pipeline} pipeline request policy pipeline.
* @memberof StorageClient
*/
protected constructor(url: string, pipeline: Pipeline) {
// URL should be encoded and only once, protocol layer shouldn't encode URL again
this.url = escapeURLPath(url);
this.accountName = getAccountNameFromUrl(url);
this.pipeline = pipeline;
this.storageClientContext = new StorageClientContext(
this.url,
pipeline.toServiceClientOptions()
);
this.isHttps = iEqual(getURLScheme(this.url) || "", "https");
this.credential = new AnonymousCredential();
for (const factory of this.pipeline.factories) {
if (
(isNode && factory instanceof StorageSharedKeyCredential) ||
factory instanceof AnonymousCredential ||
isTokenCredential(factory)
) {
this.credential = factory;
}
}
// Override protocol layer's default content-type
const storageClientContext = this.storageClientContext as any;
storageClientContext.requestContentType = undefined;
}
}