@azure/storage-common 12.2.0-beta.1 → 12.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/StorageRetryPolicyFactory.d.ts +2 -2
- package/dist/browser/StorageRetryPolicyFactory.d.ts.map +1 -1
- package/dist/browser/StorageRetryPolicyFactory.js +2 -2
- package/dist/browser/StorageRetryPolicyFactory.js.map +1 -1
- package/dist/browser/index-browser.d.mts.map +1 -1
- package/dist/browser/index-browser.mjs.map +1 -1
- package/dist/browser/index.d.ts +0 -4
- package/dist/browser/index.js +0 -4
- package/dist/browser/interfaces.d.ts +12 -0
- package/dist/browser/interfaces.d.ts.map +1 -0
- package/dist/browser/interfaces.js +4 -0
- package/dist/browser/interfaces.js.map +1 -0
- package/dist/commonjs/StorageRetryPolicyFactory.d.ts +2 -2
- package/dist/commonjs/StorageRetryPolicyFactory.d.ts.map +1 -1
- package/dist/commonjs/StorageRetryPolicyFactory.js +2 -1
- package/dist/commonjs/StorageRetryPolicyFactory.js.map +1 -1
- package/dist/commonjs/index.d.ts +1 -4
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +1 -4
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/interfaces.d.ts +12 -0
- package/dist/commonjs/interfaces.d.ts.map +1 -0
- package/dist/commonjs/interfaces.js +5 -0
- package/dist/commonjs/interfaces.js.map +1 -0
- package/dist/commonjs/tsdoc-metadata.json +1 -1
- package/dist/esm/StorageRetryPolicyFactory.d.ts +2 -2
- package/dist/esm/StorageRetryPolicyFactory.d.ts.map +1 -1
- package/dist/esm/StorageRetryPolicyFactory.js +2 -2
- package/dist/esm/StorageRetryPolicyFactory.js.map +1 -1
- package/dist/esm/index.d.ts +1 -4
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interfaces.d.ts +12 -0
- package/dist/esm/interfaces.d.ts.map +1 -0
- package/dist/esm/interfaces.js +4 -0
- package/dist/esm/interfaces.js.map +1 -0
- package/dist/react-native/BufferScheduler-react-native.d.mts.map +1 -0
- package/dist/react-native/BufferScheduler-react-native.mjs.map +1 -0
- package/dist/react-native/BufferScheduler.d.ts +1 -155
- package/dist/react-native/BufferScheduler.js +4 -274
- package/dist/react-native/StorageRetryPolicyFactory.d.ts +2 -2
- package/dist/react-native/StorageRetryPolicyFactory.d.ts.map +1 -1
- package/dist/react-native/StorageRetryPolicyFactory.js +2 -2
- package/dist/react-native/StorageRetryPolicyFactory.js.map +1 -1
- package/dist/react-native/credentials/StorageSharedKeyCredential-react-native.d.mts.map +1 -0
- package/dist/react-native/credentials/StorageSharedKeyCredential-react-native.mjs.map +1 -0
- package/dist/react-native/credentials/StorageSharedKeyCredential.d.ts +2 -37
- package/dist/react-native/credentials/StorageSharedKeyCredential.js +2 -45
- package/dist/react-native/credentials/UserDelegationKeyCredential-react-native.d.mts.map +1 -0
- package/dist/react-native/credentials/UserDelegationKeyCredential-react-native.mjs.map +1 -0
- package/dist/react-native/credentials/UserDelegationKeyCredential.d.ts +1 -64
- package/dist/react-native/credentials/UserDelegationKeyCredential.js +1 -39
- package/dist/react-native/index.d.ts +1 -4
- package/dist/react-native/index.d.ts.map +1 -1
- package/dist/react-native/index.js +1 -4
- package/dist/react-native/index.js.map +1 -1
- package/dist/react-native/interfaces.d.ts +12 -0
- package/dist/react-native/interfaces.d.ts.map +1 -0
- package/dist/react-native/interfaces.js +4 -0
- package/dist/react-native/interfaces.js.map +1 -0
- package/dist/react-native/policies/StorageSharedKeyCredentialPolicyV2-react-native.d.mts.map +1 -0
- package/dist/react-native/policies/StorageSharedKeyCredentialPolicyV2-react-native.mjs.map +1 -0
- package/dist/react-native/policies/StorageSharedKeyCredentialPolicyV2.d.ts +2 -2
- package/dist/react-native/policies/StorageSharedKeyCredentialPolicyV2.js +2 -116
- package/package.json +4 -4
- package/dist/react-native/BufferScheduler.d.ts.map +0 -1
- package/dist/react-native/BufferScheduler.js.map +0 -1
- package/dist/react-native/credentials/StorageSharedKeyCredential.d.ts.map +0 -1
- package/dist/react-native/credentials/StorageSharedKeyCredential.js.map +0 -1
- package/dist/react-native/credentials/UserDelegationKeyCredential.d.ts.map +0 -1
- package/dist/react-native/credentials/UserDelegationKeyCredential.js.map +0 -1
- package/dist/react-native/policies/StorageSharedKeyCredentialPolicyV2.d.ts.map +0 -1
- package/dist/react-native/policies/StorageSharedKeyCredentialPolicyV2.js.map +0 -1
|
@@ -1,43 +1,5 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
|
-
import { createHmac } from "node:crypto";
|
|
4
|
-
/**
|
|
5
|
-
* ONLY AVAILABLE IN NODE.JS RUNTIME.
|
|
6
|
-
*
|
|
7
|
-
* UserDelegationKeyCredential is only used for generation of user delegation SAS.
|
|
8
|
-
* @see https://learn.microsoft.com/rest/api/storageservices/create-user-delegation-sas
|
|
9
|
-
*/
|
|
10
3
|
export class UserDelegationKeyCredential {
|
|
11
|
-
/**
|
|
12
|
-
* Azure Storage account name; readonly.
|
|
13
|
-
*/
|
|
14
|
-
accountName;
|
|
15
|
-
/**
|
|
16
|
-
* Azure Storage user delegation key; readonly.
|
|
17
|
-
*/
|
|
18
|
-
userDelegationKey;
|
|
19
|
-
/**
|
|
20
|
-
* Key value in Buffer type.
|
|
21
|
-
*/
|
|
22
|
-
key;
|
|
23
|
-
/**
|
|
24
|
-
* Creates an instance of UserDelegationKeyCredential.
|
|
25
|
-
* @param accountName -
|
|
26
|
-
* @param userDelegationKey -
|
|
27
|
-
*/
|
|
28
|
-
constructor(accountName, userDelegationKey) {
|
|
29
|
-
this.accountName = accountName;
|
|
30
|
-
this.userDelegationKey = userDelegationKey;
|
|
31
|
-
this.key = Buffer.from(userDelegationKey.value, "base64");
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Generates a hash signature for an HTTP request or for a SAS.
|
|
35
|
-
*
|
|
36
|
-
* @param stringToSign -
|
|
37
|
-
*/
|
|
38
|
-
computeHMACSHA256(stringToSign) {
|
|
39
|
-
// console.log(`stringToSign: ${JSON.stringify(stringToSign)}`);
|
|
40
|
-
return createHmac("sha256", this.key).update(stringToSign, "utf8").digest("base64");
|
|
41
|
-
}
|
|
42
4
|
}
|
|
43
|
-
//# sourceMappingURL=UserDelegationKeyCredential.
|
|
5
|
+
//# sourceMappingURL=UserDelegationKeyCredential-react-native.mjs.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./BufferScheduler.js";
|
|
2
2
|
export { getCachedDefaultHttpClient } from "./cache.js";
|
|
3
|
+
export * from "./interfaces.js";
|
|
3
4
|
export * from "./StorageBrowserPolicyFactory.js";
|
|
4
5
|
export * from "./credentials/AnonymousCredential.js";
|
|
5
6
|
export * from "./credentials/Credential.js";
|
|
@@ -8,15 +9,11 @@ export * from "./StorageRetryPolicyFactory.js";
|
|
|
8
9
|
export { BaseRequestPolicy } from "./policies/RequestPolicy.js";
|
|
9
10
|
export * from "./policies/AnonymousCredentialPolicy.js";
|
|
10
11
|
export * from "./policies/CredentialPolicy.js";
|
|
11
|
-
export * from "./policies/StorageBrowserPolicy.js";
|
|
12
12
|
export * from "./policies/StorageBrowserPolicyV2.js";
|
|
13
13
|
export * from "./policies/StorageCorrectContentLengthPolicy.js";
|
|
14
|
-
export * from "./policies/StorageRetryPolicyType.js";
|
|
15
|
-
export * from "./policies/StorageRetryPolicy.js";
|
|
16
14
|
export * from "./policies/StorageRetryPolicyV2.js";
|
|
17
15
|
export * from "./policies/StorageSharedKeyCredentialPolicy.js";
|
|
18
16
|
export * from "./policies/StorageSharedKeyCredentialPolicyV2.js";
|
|
19
|
-
export * from "./StorageRetryPolicyFactory.js";
|
|
20
17
|
export * from "./policies/StorageRequestFailureDetailsParserPolicy.js";
|
|
21
18
|
export * from "./credentials/UserDelegationKeyCredential.js";
|
|
22
19
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AACxD,cAAc,iBAAiB,CAAC;AAEhC,cAAc,kCAAkC,CAAC;AACjD,cAAc,sCAAsC,CAAC;AACrD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6CAA6C,CAAC;AAE5D,cAAc,gCAAgC,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,cAAc,yCAAyC,CAAC;AACxD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sCAAsC,CAAC;AACrD,cAAc,iDAAiD,CAAC;AAChE,cAAc,oCAAoC,CAAC;AACnD,cAAc,gDAAgD,CAAC;AAC/D,cAAc,kDAAkD,CAAC;AACjE,cAAc,wDAAwD,CAAC;AACvE,cAAc,8CAA8C,CAAC"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
export * from "./BufferScheduler.js";
|
|
4
4
|
export { getCachedDefaultHttpClient } from "./cache.js";
|
|
5
|
+
export * from "./interfaces.js";
|
|
5
6
|
export * from "./StorageBrowserPolicyFactory.js";
|
|
6
7
|
export * from "./credentials/AnonymousCredential.js";
|
|
7
8
|
export * from "./credentials/Credential.js";
|
|
@@ -10,15 +11,11 @@ export * from "./StorageRetryPolicyFactory.js";
|
|
|
10
11
|
export { BaseRequestPolicy } from "./policies/RequestPolicy.js";
|
|
11
12
|
export * from "./policies/AnonymousCredentialPolicy.js";
|
|
12
13
|
export * from "./policies/CredentialPolicy.js";
|
|
13
|
-
export * from "./policies/StorageBrowserPolicy.js";
|
|
14
14
|
export * from "./policies/StorageBrowserPolicyV2.js";
|
|
15
15
|
export * from "./policies/StorageCorrectContentLengthPolicy.js";
|
|
16
|
-
export * from "./policies/StorageRetryPolicyType.js";
|
|
17
|
-
export * from "./policies/StorageRetryPolicy.js";
|
|
18
16
|
export * from "./policies/StorageRetryPolicyV2.js";
|
|
19
17
|
export * from "./policies/StorageSharedKeyCredentialPolicy.js";
|
|
20
18
|
export * from "./policies/StorageSharedKeyCredentialPolicyV2.js";
|
|
21
|
-
export * from "./StorageRetryPolicyFactory.js";
|
|
22
19
|
export * from "./policies/StorageRequestFailureDetailsParserPolicy.js";
|
|
23
20
|
export * from "./credentials/UserDelegationKeyCredential.js";
|
|
24
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AACxD,cAAc,iBAAiB,CAAC;AAEhC,cAAc,kCAAkC,CAAC;AACjD,cAAc,sCAAsC,CAAC;AACrD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6CAA6C,CAAC;AAE5D,cAAc,gCAAgC,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,cAAc,yCAAyC,CAAC;AACxD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sCAAsC,CAAC;AACrD,cAAc,iDAAiD,CAAC;AAChE,cAAc,oCAAoC,CAAC;AACnD,cAAc,gDAAgD,CAAC;AAC/D,cAAc,kDAAkD,CAAC;AACjE,cAAc,wDAAwD,CAAC;AACvE,cAAc,8CAA8C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport * from \"./BufferScheduler.js\";\nexport { getCachedDefaultHttpClient } from \"./cache.js\";\nexport * from \"./interfaces.js\";\n\nexport * from \"./StorageBrowserPolicyFactory.js\";\nexport * from \"./credentials/AnonymousCredential.js\";\nexport * from \"./credentials/Credential.js\";\nexport * from \"./credentials/StorageSharedKeyCredential.js\";\n\nexport * from \"./StorageRetryPolicyFactory.js\";\nexport { BaseRequestPolicy } from \"./policies/RequestPolicy.js\";\nexport * from \"./policies/AnonymousCredentialPolicy.js\";\nexport * from \"./policies/CredentialPolicy.js\";\nexport * from \"./policies/StorageBrowserPolicyV2.js\";\nexport * from \"./policies/StorageCorrectContentLengthPolicy.js\";\nexport * from \"./policies/StorageRetryPolicyV2.js\";\nexport * from \"./policies/StorageSharedKeyCredentialPolicy.js\";\nexport * from \"./policies/StorageSharedKeyCredentialPolicyV2.js\";\nexport * from \"./policies/StorageRequestFailureDetailsParserPolicy.js\";\nexport * from \"./credentials/UserDelegationKeyCredential.js\";\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Node.js Readable stream that also has a `destroy` method.
|
|
3
|
+
*/
|
|
4
|
+
export interface NodeJSReadableStream extends NodeJS.ReadableStream {
|
|
5
|
+
/**
|
|
6
|
+
* Destroy the stream. Optionally emit an 'error' event, and emit a
|
|
7
|
+
* 'close' event (unless emitClose is set to false). After this call,
|
|
8
|
+
* internal resources will be released.
|
|
9
|
+
*/
|
|
10
|
+
destroy(error?: Error): this;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,MAAM,CAAC,cAAc;IACjE;;;;OAIG;IACH,OAAO,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;CAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * A Node.js Readable stream that also has a `destroy` method.\n */\nexport interface NodeJSReadableStream extends NodeJS.ReadableStream {\n /**\n * Destroy the stream. Optionally emit an 'error' event, and emit a\n * 'close' event (unless emitClose is set to false). After this call,\n * internal resources will be released.\n */\n destroy(error?: Error): this;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageSharedKeyCredentialPolicyV2-react-native.d.mts","sourceRoot":"","sources":["../../../src/policies/StorageSharedKeyCredentialPolicyV2-react-native.mts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAIV,cAAc,EACf,MAAM,2BAA2B,CAAC;AACnC;;GAEG;AACH,eAAO,MAAM,oCAAoC,qCAAqC,CAAC;AAEvF;;GAEG;AACH,MAAM,WAAW,uCAAuC;IACtD,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,gCAAgC,CAC9C,QAAQ,EAAE,uCAAuC,GAChD,cAAc,CAOhB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageSharedKeyCredentialPolicyV2-react-native.mjs","sourceRoot":"","sources":["../../../src/policies/StorageSharedKeyCredentialPolicyV2-react-native.mts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAQlC;;GAEG;AACH,MAAM,CAAC,MAAM,oCAAoC,GAAG,kCAAkC,CAAC;AAUvF;;GAEG;AACH,MAAM,UAAU,gCAAgC,CAC9C,QAAiD;IAEjD,OAAO;QACL,IAAI,EAAE,oCAAoC;QAC1C,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YAC3D,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n PipelinePolicy,\n} from \"@azure/core-rest-pipeline\";\n/**\n * The programmatic identifier of the storageSharedKeyCredentialPolicy.\n */\nexport const storageSharedKeyCredentialPolicyName = \"storageSharedKeyCredentialPolicy\";\n\n/**\n * Options used to configure StorageSharedKeyCredentialPolicy.\n */\nexport interface StorageSharedKeyCredentialPolicyOptions {\n accountName: string;\n accountKey: Buffer;\n}\n\n/**\n * storageSharedKeyCredentialPolicy handles signing requests using storage account keys.\n */\nexport function storageSharedKeyCredentialPolicy(\n _options: StorageSharedKeyCredentialPolicyOptions,\n): PipelinePolicy {\n return {\n name: storageSharedKeyCredentialPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n return next(request);\n },\n };\n}\n"]}
|
|
@@ -13,5 +13,5 @@ export interface StorageSharedKeyCredentialPolicyOptions {
|
|
|
13
13
|
/**
|
|
14
14
|
* storageSharedKeyCredentialPolicy handles signing requests using storage account keys.
|
|
15
15
|
*/
|
|
16
|
-
export declare function storageSharedKeyCredentialPolicy(
|
|
17
|
-
//# sourceMappingURL=StorageSharedKeyCredentialPolicyV2.d.
|
|
16
|
+
export declare function storageSharedKeyCredentialPolicy(_options: StorageSharedKeyCredentialPolicyOptions): PipelinePolicy;
|
|
17
|
+
//# sourceMappingURL=StorageSharedKeyCredentialPolicyV2-react-native.d.mts.map
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
|
-
import { createHmac } from "node:crypto";
|
|
4
|
-
import { HeaderConstants } from "../utils/constants.js";
|
|
5
|
-
import { getURLPath, getURLQueries } from "../utils/utils.common.js";
|
|
6
|
-
import { compareHeader } from "../utils/SharedKeyComparator.js";
|
|
7
3
|
/**
|
|
8
4
|
* The programmatic identifier of the storageSharedKeyCredentialPolicy.
|
|
9
5
|
*/
|
|
@@ -11,122 +7,12 @@ export const storageSharedKeyCredentialPolicyName = "storageSharedKeyCredentialP
|
|
|
11
7
|
/**
|
|
12
8
|
* storageSharedKeyCredentialPolicy handles signing requests using storage account keys.
|
|
13
9
|
*/
|
|
14
|
-
export function storageSharedKeyCredentialPolicy(
|
|
15
|
-
function signRequest(request) {
|
|
16
|
-
request.headers.set(HeaderConstants.X_MS_DATE, new Date().toUTCString());
|
|
17
|
-
if (request.body &&
|
|
18
|
-
(typeof request.body === "string" || Buffer.isBuffer(request.body)) &&
|
|
19
|
-
request.body.length > 0) {
|
|
20
|
-
request.headers.set(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(request.body));
|
|
21
|
-
}
|
|
22
|
-
const stringToSign = [
|
|
23
|
-
request.method.toUpperCase(),
|
|
24
|
-
getHeaderValueToSign(request, HeaderConstants.CONTENT_LANGUAGE),
|
|
25
|
-
getHeaderValueToSign(request, HeaderConstants.CONTENT_ENCODING),
|
|
26
|
-
getHeaderValueToSign(request, HeaderConstants.CONTENT_LENGTH),
|
|
27
|
-
getHeaderValueToSign(request, HeaderConstants.CONTENT_MD5),
|
|
28
|
-
getHeaderValueToSign(request, HeaderConstants.CONTENT_TYPE),
|
|
29
|
-
getHeaderValueToSign(request, HeaderConstants.DATE),
|
|
30
|
-
getHeaderValueToSign(request, HeaderConstants.IF_MODIFIED_SINCE),
|
|
31
|
-
getHeaderValueToSign(request, HeaderConstants.IF_MATCH),
|
|
32
|
-
getHeaderValueToSign(request, HeaderConstants.IF_NONE_MATCH),
|
|
33
|
-
getHeaderValueToSign(request, HeaderConstants.IF_UNMODIFIED_SINCE),
|
|
34
|
-
getHeaderValueToSign(request, HeaderConstants.RANGE),
|
|
35
|
-
].join("\n") +
|
|
36
|
-
"\n" +
|
|
37
|
-
getCanonicalizedHeadersString(request) +
|
|
38
|
-
getCanonicalizedResourceString(request);
|
|
39
|
-
const signature = createHmac("sha256", options.accountKey)
|
|
40
|
-
.update(stringToSign, "utf8")
|
|
41
|
-
.digest("base64");
|
|
42
|
-
request.headers.set(HeaderConstants.AUTHORIZATION, `SharedKey ${options.accountName}:${signature}`);
|
|
43
|
-
// console.log(`[URL]:${request.url}`);
|
|
44
|
-
// console.log(`[HEADERS]:${request.headers.toString()}`);
|
|
45
|
-
// console.log(`[STRING TO SIGN]:${JSON.stringify(stringToSign)}`);
|
|
46
|
-
// console.log(`[KEY]: ${request.headers.get(HeaderConstants.AUTHORIZATION)}`);
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Retrieve header value according to shared key sign rules.
|
|
50
|
-
* @see https://learn.microsoft.com/rest/api/storageservices/authenticate-with-shared-key
|
|
51
|
-
*/
|
|
52
|
-
function getHeaderValueToSign(request, headerName) {
|
|
53
|
-
const value = request.headers.get(headerName);
|
|
54
|
-
if (!value) {
|
|
55
|
-
return "";
|
|
56
|
-
}
|
|
57
|
-
// When using version 2015-02-21 or later, if Content-Length is zero, then
|
|
58
|
-
// set the Content-Length part of the StringToSign to an empty string.
|
|
59
|
-
// https://learn.microsoft.com/rest/api/storageservices/authenticate-with-shared-key
|
|
60
|
-
if (headerName === HeaderConstants.CONTENT_LENGTH && value === "0") {
|
|
61
|
-
return "";
|
|
62
|
-
}
|
|
63
|
-
return value;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* To construct the CanonicalizedHeaders portion of the signature string, follow these steps:
|
|
67
|
-
* 1. Retrieve all headers for the resource that begin with x-ms-, including the x-ms-date header.
|
|
68
|
-
* 2. Convert each HTTP header name to lowercase.
|
|
69
|
-
* 3. Sort the headers lexicographically by header name, in ascending order.
|
|
70
|
-
* Each header may appear only once in the string.
|
|
71
|
-
* 4. Replace any linear whitespace in the header value with a single space.
|
|
72
|
-
* 5. Trim any whitespace around the colon in the header.
|
|
73
|
-
* 6. Finally, append a new-line character to each canonicalized header in the resulting list.
|
|
74
|
-
* Construct the CanonicalizedHeaders string by concatenating all headers in this list into a single string.
|
|
75
|
-
*
|
|
76
|
-
*/
|
|
77
|
-
function getCanonicalizedHeadersString(request) {
|
|
78
|
-
let headersArray = [];
|
|
79
|
-
for (const [name, value] of request.headers) {
|
|
80
|
-
if (name.toLowerCase().startsWith(HeaderConstants.PREFIX_FOR_STORAGE)) {
|
|
81
|
-
headersArray.push({ name, value });
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
headersArray.sort((a, b) => {
|
|
85
|
-
return compareHeader(a.name.toLowerCase(), b.name.toLowerCase());
|
|
86
|
-
});
|
|
87
|
-
// Remove duplicate headers
|
|
88
|
-
headersArray = headersArray.filter((value, index, array) => {
|
|
89
|
-
if (index > 0 && value.name.toLowerCase() === array[index - 1].name.toLowerCase()) {
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
return true;
|
|
93
|
-
});
|
|
94
|
-
let canonicalizedHeadersStringToSign = "";
|
|
95
|
-
headersArray.forEach((header) => {
|
|
96
|
-
canonicalizedHeadersStringToSign += `${header.name
|
|
97
|
-
.toLowerCase()
|
|
98
|
-
.trimRight()}:${header.value.trimLeft()}\n`;
|
|
99
|
-
});
|
|
100
|
-
return canonicalizedHeadersStringToSign;
|
|
101
|
-
}
|
|
102
|
-
function getCanonicalizedResourceString(request) {
|
|
103
|
-
const path = getURLPath(request.url) || "/";
|
|
104
|
-
let canonicalizedResourceString = "";
|
|
105
|
-
canonicalizedResourceString += `/${options.accountName}${path}`;
|
|
106
|
-
const queries = getURLQueries(request.url);
|
|
107
|
-
const lowercaseQueries = {};
|
|
108
|
-
if (queries) {
|
|
109
|
-
const queryKeys = [];
|
|
110
|
-
for (const key in queries) {
|
|
111
|
-
if (Object.prototype.hasOwnProperty.call(queries, key)) {
|
|
112
|
-
const lowercaseKey = key.toLowerCase();
|
|
113
|
-
lowercaseQueries[lowercaseKey] = queries[key];
|
|
114
|
-
queryKeys.push(lowercaseKey);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
queryKeys.sort();
|
|
118
|
-
for (const key of queryKeys) {
|
|
119
|
-
canonicalizedResourceString += `\n${key}:${decodeURIComponent(lowercaseQueries[key])}`;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return canonicalizedResourceString;
|
|
123
|
-
}
|
|
10
|
+
export function storageSharedKeyCredentialPolicy(_options) {
|
|
124
11
|
return {
|
|
125
12
|
name: storageSharedKeyCredentialPolicyName,
|
|
126
13
|
async sendRequest(request, next) {
|
|
127
|
-
signRequest(request);
|
|
128
14
|
return next(request);
|
|
129
15
|
},
|
|
130
16
|
};
|
|
131
17
|
}
|
|
132
|
-
//# sourceMappingURL=StorageSharedKeyCredentialPolicyV2.
|
|
18
|
+
//# sourceMappingURL=StorageSharedKeyCredentialPolicyV2-react-native.mjs.map
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"sdk-type": "client",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"author": "Microsoft Corporation",
|
|
6
|
-
"version": "12.
|
|
6
|
+
"version": "12.3.0",
|
|
7
7
|
"description": "Azure Storage Common Client Library for JavaScript",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"repository": "github:Azure/azure-sdk-for-js",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@types/node": "^20.19.25",
|
|
44
44
|
"@vitest/browser-playwright": "^4.0.8",
|
|
45
45
|
"@vitest/coverage-istanbul": "^4.0.8",
|
|
46
|
-
"cross-env": "^
|
|
46
|
+
"cross-env": "^10.1.0",
|
|
47
47
|
"eslint": "^9.39.1",
|
|
48
48
|
"playwright": "^1.56.1",
|
|
49
49
|
"prettier": "^3.6.2",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"typescript": "~5.9.3",
|
|
53
53
|
"vitest": "^4.0.8",
|
|
54
54
|
"@azure-tools/test-utils-vitest": "^2.0.1",
|
|
55
|
-
"@azure/
|
|
56
|
-
"@azure/
|
|
55
|
+
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
|
|
56
|
+
"@azure/dev-tool": "^1.0.0"
|
|
57
57
|
},
|
|
58
58
|
"type": "module",
|
|
59
59
|
"tshy": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BufferScheduler.d.ts","sourceRoot":"","sources":["../../src/BufferScheduler.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,CAAC,OAAO,MAAM,eAAe,GAAG,CACpC,IAAI,EAAE,MAAM,MAAM,CAAC,cAAc,EACjC,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,MAAM,KACZ,OAAO,CAAC,GAAG,CAAC,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,eAAe;IAC1B;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IAEpC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IAEpC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwB;IAEjD;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAkB;IAElD;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoC;IAE5D;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IAErC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAa;IAE3B;;OAEG;IACH,OAAO,CAAC,WAAW,CAAkB;IAErC;;OAEG;IACH,OAAO,CAAC,OAAO,CAAkB;IAEjC;;OAEG;IACH,OAAO,CAAC,yBAAyB,CAAa;IAE9C;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,CAAiB;IAElC;;OA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,GAAG,MAAM,CAAC,IAAI,CAAC;QAEjC,IAAI,CAAC,yBAAyB,EAAE,CAAC;QACjC,IAAI,CAAC,MAAM,IAAI,YAAY,CAAC;QAE5B,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,eAAe,CACxB,GAAG,EAAE,CAAC,MAAM,CAAC,iBAAiB,EAAE,EAChC,YAAY,EACZ,IAAI,CAAC,MAAM,GAAG,YAAY,CAC3B,CAAC;QACJ,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YAChC,OAAO;QACT,CAAC;QAED,IAAI,CAAC,yBAAyB,EAAE,CAAC;QACjC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACzB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACK,WAAW,CAAC,MAAoB;QACtC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC3B,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YAC7D,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;QACzB,CAAC;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { EventEmitter } from \"events\";\nimport { PooledBuffer } from \"./PooledBuffer.js\";\n\n/**\n * OutgoingHandler is an async function triggered by BufferScheduler.\n */\nexport declare type OutgoingHandler = (\n body: () => NodeJS.ReadableStream,\n length: number,\n offset?: number,\n) => Promise<any>;\n\n/**\n * This class accepts a Node.js Readable stream as input, and keeps reading data\n * from the stream into the internal buffer structure, until it reaches maxBuffers.\n * Every available buffer will try to trigger outgoingHandler.\n *\n * The internal buffer structure includes an incoming buffer array, and a outgoing\n * buffer array. The incoming buffer array includes the \"empty\" buffers can be filled\n * with new incoming data. The outgoing array includes the filled buffers to be\n * handled by outgoingHandler. Every above buffer size is defined by parameter bufferSize.\n *\n * NUM_OF_ALL_BUFFERS = BUFFERS_IN_INCOMING + BUFFERS_IN_OUTGOING + BUFFERS_UNDER_HANDLING\n *\n * NUM_OF_ALL_BUFFERS lesser than or equal to maxBuffers\n *\n * PERFORMANCE IMPROVEMENT TIPS:\n * 1. Input stream highWaterMark is better to set a same value with bufferSize\n * parameter, which will avoid Buffer.concat() operations.\n * 2. concurrency should set a smaller value than maxBuffers, which is helpful to\n * reduce the possibility when a outgoing handler waits for the stream data.\n * in this situation, outgoing handlers are blocked.\n * Outgoing queue shouldn't be empty.\n */\nexport class BufferScheduler {\n /**\n * Size of buffers in incoming and outgoing queues. This class will try to align\n * data read from Readable stream into buffer chunks with bufferSize defined.\n */\n private readonly bufferSize: number;\n\n /**\n * How many buffers can be created or maintained.\n */\n private readonly maxBuffers: number;\n\n /**\n * A Node.js Readable stream.\n */\n private readonly readable: NodeJS.ReadableStream;\n\n /**\n * OutgoingHandler is an async function triggered by BufferScheduler when there\n * are available buffers in outgoing array.\n */\n private readonly outgoingHandler: OutgoingHandler;\n\n /**\n * An internal event emitter.\n */\n private readonly emitter: EventEmitter = new EventEmitter();\n\n /**\n * Concurrency of executing outgoingHandlers. (0 lesser than concurrency lesser than or equal to maxBuffers)\n */\n private readonly concurrency: number;\n\n /**\n * An internal offset marker to track data offset in bytes of next outgoingHandler.\n */\n private offset: number = 0;\n\n /**\n * An internal marker to track whether stream is end.\n */\n private isStreamEnd: boolean = false;\n\n /**\n * An internal marker to track whether stream or outgoingHandler returns error.\n */\n private isError: boolean = false;\n\n /**\n * How many handlers are executing.\n */\n private executingOutgoingHandlers: number = 0;\n\n /**\n * Encoding of the input Readable stream which has string data type instead of Buffer.\n */\n private encoding?: BufferEncoding;\n\n /**\n * How many buffers have been allocated.\n */\n private numBuffers: number = 0;\n\n /**\n * Because this class doesn't know how much data every time stream pops, which\n * is defined by highWaterMarker of the stream. So BufferScheduler will cache\n * data received from the stream, when data in unresolvedDataArray exceeds the\n * blockSize defined, it will try to concat a blockSize of buffer, fill into available\n * buffers from incoming and push to outgoing array.\n */\n private unresolvedDataArray: Buffer[] = [];\n\n /**\n * How much data consisted in unresolvedDataArray.\n */\n private unresolvedLength: number = 0;\n\n /**\n * The array includes all the available buffers can be used to fill data from stream.\n */\n private incoming: PooledBuffer[] = [];\n\n /**\n * The array (queue) includes all the buffers filled from stream data.\n */\n private outgoing: PooledBuffer[] = [];\n\n /**\n * Creates an instance of BufferScheduler.\n *\n * @param readable - A Node.js Readable stream\n * @param bufferSize - Buffer size of every maintained buffer\n * @param maxBuffers - How many buffers can be allocated\n * @param outgoingHandler - An async function scheduled to be\n * triggered when a buffer fully filled\n * with stream data\n * @param concurrency - Concurrency of executing outgoingHandlers (>0)\n * @param encoding - [Optional] Encoding of Readable stream when it's a string stream\n */\n constructor(\n readable: NodeJS.ReadableStream,\n bufferSize: number,\n maxBuffers: number,\n outgoingHandler: OutgoingHandler,\n concurrency: number,\n encoding?: BufferEncoding,\n ) {\n if (bufferSize <= 0) {\n throw new RangeError(`bufferSize must be larger than 0, current is ${bufferSize}`);\n }\n\n if (maxBuffers <= 0) {\n throw new RangeError(`maxBuffers must be larger than 0, current is ${maxBuffers}`);\n }\n\n if (concurrency <= 0) {\n throw new RangeError(`concurrency must be larger than 0, current is ${concurrency}`);\n }\n\n this.bufferSize = bufferSize;\n this.maxBuffers = maxBuffers;\n this.readable = readable;\n this.outgoingHandler = outgoingHandler;\n this.concurrency = concurrency;\n this.encoding = encoding;\n }\n\n /**\n * Start the scheduler, will return error when stream of any of the outgoingHandlers\n * returns error.\n *\n */\n public async do(): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n this.readable.on(\"data\", (data) => {\n data = typeof data === \"string\" ? Buffer.from(data, this.encoding) : data;\n this.appendUnresolvedData(data);\n\n if (!this.resolveData()) {\n this.readable.pause();\n }\n });\n\n this.readable.on(\"error\", (err) => {\n this.emitter.emit(\"error\", err);\n });\n\n this.readable.on(\"end\", () => {\n this.isStreamEnd = true;\n this.emitter.emit(\"checkEnd\");\n });\n\n this.emitter.on(\"error\", (err) => {\n this.isError = true;\n this.readable.pause();\n reject(err);\n });\n\n this.emitter.on(\"checkEnd\", () => {\n if (this.outgoing.length > 0) {\n this.triggerOutgoingHandlers();\n return;\n }\n\n if (this.isStreamEnd && this.executingOutgoingHandlers === 0) {\n if (this.unresolvedLength > 0 && this.unresolvedLength < this.bufferSize) {\n const buffer = this.shiftBufferFromUnresolvedDataArray();\n this.outgoingHandler(() => buffer.getReadableStream(), buffer.size, this.offset)\n .then(resolve)\n .catch(reject);\n } else if (this.unresolvedLength >= this.bufferSize) {\n return;\n } else {\n resolve();\n }\n }\n });\n });\n }\n\n /**\n * Insert a new data into unresolved array.\n *\n * @param data -\n */\n private appendUnresolvedData(data: Buffer): void {\n this.unresolvedDataArray.push(data);\n this.unresolvedLength += data.length;\n }\n\n /**\n * Try to shift a buffer with size in blockSize. The buffer returned may be less\n * than blockSize when data in unresolvedDataArray is less than bufferSize.\n *\n */\n private shiftBufferFromUnresolvedDataArray(buffer?: PooledBuffer): PooledBuffer {\n if (!buffer) {\n buffer = new PooledBuffer(this.bufferSize, this.unresolvedDataArray, this.unresolvedLength);\n } else {\n buffer.fill(this.unresolvedDataArray, this.unresolvedLength);\n }\n\n this.unresolvedLength -= buffer.size;\n return buffer;\n }\n\n /**\n * Resolve data in unresolvedDataArray. For every buffer with size in blockSize\n * shifted, it will try to get (or allocate a buffer) from incoming, and fill it,\n * then push it into outgoing to be handled by outgoing handler.\n *\n * Return false when available buffers in incoming are not enough, else true.\n *\n * @returns Return false when buffers in incoming are not enough, else true.\n */\n private resolveData(): boolean {\n while (this.unresolvedLength >= this.bufferSize) {\n let buffer: PooledBuffer;\n\n if (this.incoming.length > 0) {\n buffer = this.incoming.shift()!;\n this.shiftBufferFromUnresolvedDataArray(buffer);\n } else {\n if (this.numBuffers < this.maxBuffers) {\n buffer = this.shiftBufferFromUnresolvedDataArray();\n this.numBuffers++;\n } else {\n // No available buffer, wait for buffer returned\n return false;\n }\n }\n\n this.outgoing.push(buffer);\n this.triggerOutgoingHandlers();\n }\n return true;\n }\n\n /**\n * Try to trigger a outgoing handler for every buffer in outgoing. Stop when\n * concurrency reaches.\n */\n private async triggerOutgoingHandlers(): Promise<void> {\n let buffer: PooledBuffer | undefined;\n do {\n if (this.executingOutgoingHandlers >= this.concurrency) {\n return;\n }\n\n buffer = this.outgoing.shift();\n if (buffer) {\n this.triggerOutgoingHandler(buffer);\n }\n } while (buffer);\n }\n\n /**\n * Trigger a outgoing handler for a buffer shifted from outgoing.\n *\n * @param buffer -\n */\n private async triggerOutgoingHandler(buffer: PooledBuffer): Promise<any> {\n const bufferLength = buffer.size;\n\n this.executingOutgoingHandlers++;\n this.offset += bufferLength;\n\n try {\n await this.outgoingHandler(\n () => buffer.getReadableStream(),\n bufferLength,\n this.offset - bufferLength,\n );\n } catch (err: any) {\n this.emitter.emit(\"error\", err);\n return;\n }\n\n this.executingOutgoingHandlers--;\n this.reuseBuffer(buffer);\n this.emitter.emit(\"checkEnd\");\n }\n\n /**\n * Return buffer used by outgoing handler into incoming.\n *\n * @param buffer -\n */\n private reuseBuffer(buffer: PooledBuffer): void {\n this.incoming.push(buffer);\n if (!this.isError && this.resolveData() && !this.isStreamEnd) {\n this.readable.resume();\n }\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StorageSharedKeyCredential.d.ts","sourceRoot":"","sources":["../../../src/credentials/StorageSharedKeyCredential.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,aAAa,EACb,wBAAwB,IAAI,oBAAoB,EACjD,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,gCAAgC,EAAE,MAAM,iDAAiD,CAAC;AACnG,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;;GAIG;AACH,qBAAa,0BAA2B,SAAQ,UAAU;IACxD;;OAEG;IACH,SAAgB,WAAW,EAAE,MAAM,CAAC;IAEpC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IAEpC;;;;OAIG;gBACS,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAMnD;;;;;OAKG;IACI,MAAM,CACX,UAAU,EAAE,aAAa,EACzB,OAAO,EAAE,oBAAoB,GAC5B,gCAAgC;IAInC;;;;OAIG;IACI,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;CAGvD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StorageSharedKeyCredential.js","sourceRoot":"","sources":["../../../src/credentials/StorageSharedKeyCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAKzC,OAAO,EAAE,gCAAgC,EAAE,MAAM,iDAAiD,CAAC;AACnG,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;;GAIG;AACH,MAAM,OAAO,0BAA2B,SAAQ,UAAU;IACxD;;OAEG;IACa,WAAW,CAAS;IAEpC;;OAEG;IACc,UAAU,CAAS;IAEpC;;;;OAIG;IACH,YAAY,WAAmB,EAAE,UAAkB;QACjD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IACtD,CAAC;IAED;;;;;OAKG;IACI,MAAM,CACX,UAAyB,EACzB,OAA6B;QAE7B,OAAO,IAAI,gCAAgC,CAAC,UAAU,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IACzE,CAAC;IAED;;;;OAIG;IACI,iBAAiB,CAAC,YAAoB;QAC3C,OAAO,UAAU,CAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC7F,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { createHmac } from \"node:crypto\";\nimport type {\n RequestPolicy,\n RequestPolicyOptionsLike as RequestPolicyOptions,\n} from \"@azure/core-http-compat\";\nimport { StorageSharedKeyCredentialPolicy } from \"../policies/StorageSharedKeyCredentialPolicy.js\";\nimport { Credential } from \"./Credential.js\";\n\n/**\n * ONLY AVAILABLE IN NODE.JS RUNTIME.\n *\n * StorageSharedKeyCredential for account key authorization of Azure Storage service.\n */\nexport class StorageSharedKeyCredential extends Credential {\n /**\n * Azure Storage account name; readonly.\n */\n public readonly accountName: string;\n\n /**\n * Azure Storage account key; readonly.\n */\n private readonly accountKey: Buffer;\n\n /**\n * Creates an instance of StorageSharedKeyCredential.\n * @param accountName -\n * @param accountKey -\n */\n constructor(accountName: string, accountKey: string) {\n super();\n this.accountName = accountName;\n this.accountKey = Buffer.from(accountKey, \"base64\");\n }\n\n /**\n * Creates a StorageSharedKeyCredentialPolicy object.\n *\n * @param nextPolicy -\n * @param options -\n */\n public create(\n nextPolicy: RequestPolicy,\n options: RequestPolicyOptions,\n ): StorageSharedKeyCredentialPolicy {\n return new StorageSharedKeyCredentialPolicy(nextPolicy, options, this);\n }\n\n /**\n * Generates a hash signature for an HTTP request or for a SAS.\n *\n * @param stringToSign -\n */\n public computeHMACSHA256(stringToSign: string): string {\n return createHmac(\"sha256\", this.accountKey).update(stringToSign, \"utf8\").digest(\"base64\");\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"UserDelegationKeyCredential.d.ts","sourceRoot":"","sources":["../../../src/credentials/UserDelegationKeyCredential.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,cAAc,EAAE,IAAI,CAAC;IACrB;;OAEG;IACH,eAAe,EAAE,IAAI,CAAC;IACtB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;GAKG;AACH,qBAAa,2BAA2B;IACtC;;OAEG;IACH,SAAgB,WAAW,EAAE,MAAM,CAAC;IAEpC;;OAEG;IACH,SAAgB,iBAAiB,EAAE,iBAAiB,CAAC;IAErD;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAE7B;;;;OAIG;gBACS,WAAW,EAAE,MAAM,EAAE,iBAAiB,EAAE,iBAAiB;IAMrE;;;;OAIG;IACI,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;CAKvD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"UserDelegationKeyCredential.js","sourceRoot":"","sources":["../../../src/credentials/UserDelegationKeyCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAoCzC;;;;;GAKG;AACH,MAAM,OAAO,2BAA2B;IACtC;;OAEG;IACa,WAAW,CAAS;IAEpC;;OAEG;IACa,iBAAiB,CAAoB;IAErD;;OAEG;IACc,GAAG,CAAS;IAE7B;;;;OAIG;IACH,YAAY,WAAmB,EAAE,iBAAoC;QACnE,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC5D,CAAC;IAED;;;;OAIG;IACI,iBAAiB,CAAC,YAAoB;QAC3C,gEAAgE;QAEhE,OAAO,UAAU,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACtF,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { createHmac } from \"node:crypto\";\n\n/**\n * A user delegation key.\n */\nexport interface UserDelegationKey {\n /**\n * The Azure Active Directory object ID in GUID format.\n */\n signedObjectId: string;\n /**\n * The Azure Active Directory tenant ID in GUID format.\n */\n signedTenantId: string;\n /**\n * The date-time the key is active.\n */\n signedStartsOn: Date;\n /**\n * The date-time the key expires.\n */\n signedExpiresOn: Date;\n /**\n * Abbreviation of the Azure Storage service that accepts the key.\n */\n signedService: string;\n /**\n * The service version that created the key.\n */\n signedVersion: string;\n /**\n * The key as a base64 string.\n */\n value: string;\n}\n\n/**\n * ONLY AVAILABLE IN NODE.JS RUNTIME.\n *\n * UserDelegationKeyCredential is only used for generation of user delegation SAS.\n * @see https://learn.microsoft.com/rest/api/storageservices/create-user-delegation-sas\n */\nexport class UserDelegationKeyCredential {\n /**\n * Azure Storage account name; readonly.\n */\n public readonly accountName: string;\n\n /**\n * Azure Storage user delegation key; readonly.\n */\n public readonly userDelegationKey: UserDelegationKey;\n\n /**\n * Key value in Buffer type.\n */\n private readonly key: Buffer;\n\n /**\n * Creates an instance of UserDelegationKeyCredential.\n * @param accountName -\n * @param userDelegationKey -\n */\n constructor(accountName: string, userDelegationKey: UserDelegationKey) {\n this.accountName = accountName;\n this.userDelegationKey = userDelegationKey;\n this.key = Buffer.from(userDelegationKey.value, \"base64\");\n }\n\n /**\n * Generates a hash signature for an HTTP request or for a SAS.\n *\n * @param stringToSign -\n */\n public computeHMACSHA256(stringToSign: string): string {\n // console.log(`stringToSign: ${JSON.stringify(stringToSign)}`);\n\n return createHmac(\"sha256\", this.key).update(stringToSign, \"utf8\").digest(\"base64\");\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StorageSharedKeyCredentialPolicyV2.d.ts","sourceRoot":"","sources":["../../../src/policies/StorageSharedKeyCredentialPolicyV2.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAIV,cAAc,EACf,MAAM,2BAA2B,CAAC;AAKnC;;GAEG;AACH,eAAO,MAAM,oCAAoC,qCAAqC,CAAC;AAEvF;;GAEG;AACH,MAAM,WAAW,uCAAuC;IACtD,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,uCAAuC,GAC/C,cAAc,CA8IhB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StorageSharedKeyCredentialPolicyV2.js","sourceRoot":"","sources":["../../../src/policies/StorageSharedKeyCredentialPolicyV2.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAOzC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAEhE;;GAEG;AACH,MAAM,CAAC,MAAM,oCAAoC,GAAG,kCAAkC,CAAC;AAUvF;;GAEG;AACH,MAAM,UAAU,gCAAgC,CAC9C,OAAgD;IAEhD,SAAS,WAAW,CAAC,OAAwB;QAC3C,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;QAEzE,IACE,OAAO,CAAC,IAAI;YACZ,CAAC,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,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CAAC;oBAC9C,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;gBAC/B,CAAC;YACH,CAAC;YAED,SAAS,CAAC,IAAI,EAAE,CAAC;YACjB,KAAK,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;gBAC5B,2BAA2B,IAAI,KAAK,GAAG,IAAI,kBAAkB,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YACzF,CAAC;QACH,CAAC;QAED,OAAO,2BAA2B,CAAC;IACrC,CAAC;IAED,OAAO;QACL,IAAI,EAAE,oCAAoC;QAC1C,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YAC3D,WAAW,CAAC,OAAO,CAAC,CAAC;YACrB,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { createHmac } from \"node:crypto\";\nimport type {\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n PipelinePolicy,\n} from \"@azure/core-rest-pipeline\";\nimport { HeaderConstants } from \"../utils/constants.js\";\nimport { getURLPath, getURLQueries } from \"../utils/utils.common.js\";\nimport { compareHeader } from \"../utils/SharedKeyComparator.js\";\n\n/**\n * The programmatic identifier of the storageSharedKeyCredentialPolicy.\n */\nexport const storageSharedKeyCredentialPolicyName = \"storageSharedKeyCredentialPolicy\";\n\n/**\n * Options used to configure StorageSharedKeyCredentialPolicy.\n */\nexport interface StorageSharedKeyCredentialPolicyOptions {\n accountName: string;\n accountKey: Buffer;\n}\n\n/**\n * storageSharedKeyCredentialPolicy handles signing requests using storage account keys.\n */\nexport function storageSharedKeyCredentialPolicy(\n options: StorageSharedKeyCredentialPolicyOptions,\n): PipelinePolicy {\n function signRequest(request: PipelineRequest): void {\n request.headers.set(HeaderConstants.X_MS_DATE, new Date().toUTCString());\n\n if (\n request.body &&\n (typeof request.body === \"string\" || Buffer.isBuffer(request.body)) &&\n request.body.length > 0\n ) {\n request.headers.set(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(request.body));\n }\n\n const stringToSign: string =\n [\n request.method.toUpperCase(),\n getHeaderValueToSign(request, HeaderConstants.CONTENT_LANGUAGE),\n getHeaderValueToSign(request, HeaderConstants.CONTENT_ENCODING),\n getHeaderValueToSign(request, HeaderConstants.CONTENT_LENGTH),\n getHeaderValueToSign(request, HeaderConstants.CONTENT_MD5),\n getHeaderValueToSign(request, HeaderConstants.CONTENT_TYPE),\n getHeaderValueToSign(request, HeaderConstants.DATE),\n getHeaderValueToSign(request, HeaderConstants.IF_MODIFIED_SINCE),\n getHeaderValueToSign(request, HeaderConstants.IF_MATCH),\n getHeaderValueToSign(request, HeaderConstants.IF_NONE_MATCH),\n getHeaderValueToSign(request, HeaderConstants.IF_UNMODIFIED_SINCE),\n getHeaderValueToSign(request, HeaderConstants.RANGE),\n ].join(\"\\n\") +\n \"\\n\" +\n getCanonicalizedHeadersString(request) +\n getCanonicalizedResourceString(request);\n\n const signature: string = createHmac(\"sha256\", options.accountKey)\n .update(stringToSign, \"utf8\")\n .digest(\"base64\");\n request.headers.set(\n HeaderConstants.AUTHORIZATION,\n `SharedKey ${options.accountName}:${signature}`,\n );\n\n // console.log(`[URL]:${request.url}`);\n // console.log(`[HEADERS]:${request.headers.toString()}`);\n // console.log(`[STRING TO SIGN]:${JSON.stringify(stringToSign)}`);\n // console.log(`[KEY]: ${request.headers.get(HeaderConstants.AUTHORIZATION)}`);\n }\n\n /**\n * Retrieve header value according to shared key sign rules.\n * @see https://learn.microsoft.com/rest/api/storageservices/authenticate-with-shared-key\n */\n function getHeaderValueToSign(request: PipelineRequest, headerName: string): string {\n const value = request.headers.get(headerName);\n\n if (!value) {\n return \"\";\n }\n\n // When using version 2015-02-21 or later, if Content-Length is zero, then\n // set the Content-Length part of the StringToSign to an empty string.\n // https://learn.microsoft.com/rest/api/storageservices/authenticate-with-shared-key\n if (headerName === HeaderConstants.CONTENT_LENGTH && value === \"0\") {\n return \"\";\n }\n\n return value;\n }\n\n /**\n * To construct the CanonicalizedHeaders portion of the signature string, follow these steps:\n * 1. Retrieve all headers for the resource that begin with x-ms-, including the x-ms-date header.\n * 2. Convert each HTTP header name to lowercase.\n * 3. Sort the headers lexicographically by header name, in ascending order.\n * Each header may appear only once in the string.\n * 4. Replace any linear whitespace in the header value with a single space.\n * 5. Trim any whitespace around the colon in the header.\n * 6. Finally, append a new-line character to each canonicalized header in the resulting list.\n * Construct the CanonicalizedHeaders string by concatenating all headers in this list into a single string.\n *\n */\n function getCanonicalizedHeadersString(request: PipelineRequest): string {\n let headersArray: Array<{ name: string; value: string }> = [];\n for (const [name, value] of request.headers) {\n if (name.toLowerCase().startsWith(HeaderConstants.PREFIX_FOR_STORAGE)) {\n headersArray.push({ name, value });\n }\n }\n\n headersArray.sort((a, b): number => {\n return compareHeader(a.name.toLowerCase(), b.name.toLowerCase());\n });\n\n // Remove duplicate headers\n headersArray = headersArray.filter((value, index, array) => {\n if (index > 0 && value.name.toLowerCase() === array[index - 1].name.toLowerCase()) {\n return false;\n }\n return true;\n });\n\n let canonicalizedHeadersStringToSign: string = \"\";\n headersArray.forEach((header) => {\n canonicalizedHeadersStringToSign += `${header.name\n .toLowerCase()\n .trimRight()}:${header.value.trimLeft()}\\n`;\n });\n\n return canonicalizedHeadersStringToSign;\n }\n\n function getCanonicalizedResourceString(request: PipelineRequest): string {\n const path = getURLPath(request.url) || \"/\";\n\n let canonicalizedResourceString: string = \"\";\n canonicalizedResourceString += `/${options.accountName}${path}`;\n\n const queries = getURLQueries(request.url);\n const lowercaseQueries: { [key: string]: string } = {};\n if (queries) {\n const queryKeys: string[] = [];\n for (const key in queries) {\n if (Object.prototype.hasOwnProperty.call(queries, key)) {\n const lowercaseKey = key.toLowerCase();\n lowercaseQueries[lowercaseKey] = queries[key];\n queryKeys.push(lowercaseKey);\n }\n }\n\n queryKeys.sort();\n for (const key of queryKeys) {\n canonicalizedResourceString += `\\n${key}:${decodeURIComponent(lowercaseQueries[key])}`;\n }\n }\n\n return canonicalizedResourceString;\n }\n\n return {\n name: storageSharedKeyCredentialPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n signRequest(request);\n return next(request);\n },\n };\n}\n"]}
|