@ms-cloudpack/remote-cache 0.3.2 → 0.4.1
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/lib/AzureRemoteCacheClient.d.ts +1 -1
- package/lib/AzureRemoteCacheClient.d.ts.map +1 -1
- package/lib/AzureRemoteCacheClient.js +5 -3
- package/lib/AzureRemoteCacheClient.js.map +1 -1
- package/lib/authentication/getAuthenticationRecord.d.ts +7 -0
- package/lib/authentication/getAuthenticationRecord.d.ts.map +1 -0
- package/lib/authentication/getAuthenticationRecord.js +17 -0
- package/lib/authentication/getAuthenticationRecord.js.map +1 -0
- package/lib/authentication/getAuthenticationRecordPath.d.ts +7 -0
- package/lib/authentication/getAuthenticationRecordPath.d.ts.map +1 -0
- package/lib/authentication/getAuthenticationRecordPath.js +10 -0
- package/lib/authentication/getAuthenticationRecordPath.js.map +1 -0
- package/lib/authentication/getCredential.d.ts +7 -1
- package/lib/authentication/getCredential.d.ts.map +1 -1
- package/lib/authentication/getCredential.js +41 -7
- package/lib/authentication/getCredential.js.map +1 -1
- package/lib/authentication/saveAuthenticationRecord.d.ts +9 -0
- package/lib/authentication/saveAuthenticationRecord.d.ts.map +1 -0
- package/lib/authentication/saveAuthenticationRecord.js +17 -0
- package/lib/authentication/saveAuthenticationRecord.js.map +1 -0
- package/lib/cache-persistance/{index.d.ts → cachePersistencePlugin.d.ts} +1 -1
- package/lib/cache-persistance/cachePersistencePlugin.d.ts.map +1 -0
- package/lib/cache-persistance/{index.js → cachePersistencePlugin.js} +1 -1
- package/lib/cache-persistance/cachePersistencePlugin.js.map +1 -0
- package/lib/cache-persistance/platforms.js.map +1 -1
- package/lib/cache-persistance/provider.js.map +1 -1
- package/lib/createBlobStorageUrl.d.ts +2 -0
- package/lib/createBlobStorageUrl.d.ts.map +1 -0
- package/lib/createBlobStorageUrl.js +4 -0
- package/lib/createBlobStorageUrl.js.map +1 -0
- package/lib/createRemoteCacheClient.d.ts +10 -4
- package/lib/createRemoteCacheClient.d.ts.map +1 -1
- package/lib/createRemoteCacheClient.js +10 -9
- package/lib/createRemoteCacheClient.js.map +1 -1
- package/lib/decorators/InMemoryDecorator.js.map +1 -1
- package/lib/decorators/ReporterDecorator.js.map +1 -1
- package/lib/decorators/RetryDecorator.js.map +1 -1
- package/lib/getListOfBlobs.d.ts +1 -1
- package/lib/getListOfBlobs.d.ts.map +1 -1
- package/lib/getListOfBlobs.js +3 -2
- package/lib/getListOfBlobs.js.map +1 -1
- package/lib/index.d.ts +1 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/types/RemoteCacheClientOptions.d.ts +3 -1
- package/lib/types/RemoteCacheClientOptions.d.ts.map +1 -1
- package/lib/types/RemoteCacheClientOptions.js.map +1 -1
- package/package.json +3 -4
- package/lib/authentication/KeyRingLocalTokenCache.d.ts +0 -14
- package/lib/authentication/KeyRingLocalTokenCache.d.ts.map +0 -1
- package/lib/authentication/KeyRingLocalTokenCache.js +0 -37
- package/lib/authentication/KeyRingLocalTokenCache.js.map +0 -1
- package/lib/authentication/acquireSasToken.d.ts +0 -3
- package/lib/authentication/acquireSasToken.d.ts.map +0 -1
- package/lib/authentication/acquireSasToken.js +0 -27
- package/lib/authentication/acquireSasToken.js.map +0 -1
- package/lib/authentication/createBlobStorageUrl.d.ts +0 -2
- package/lib/authentication/createBlobStorageUrl.d.ts.map +0 -1
- package/lib/authentication/createBlobStorageUrl.js +0 -4
- package/lib/authentication/createBlobStorageUrl.js.map +0 -1
- package/lib/authentication/getAuthenticatedConnectionString.d.ts +0 -3
- package/lib/authentication/getAuthenticatedConnectionString.d.ts.map +0 -1
- package/lib/authentication/getAuthenticatedConnectionString.js +0 -21
- package/lib/authentication/getAuthenticatedConnectionString.js.map +0 -1
- package/lib/authentication/getSasToken.d.ts +0 -12
- package/lib/authentication/getSasToken.d.ts.map +0 -1
- package/lib/authentication/getSasToken.js +0 -16
- package/lib/authentication/getSasToken.js.map +0 -1
- package/lib/authentication/isExpired.d.ts +0 -2
- package/lib/authentication/isExpired.d.ts.map +0 -1
- package/lib/authentication/isExpired.js +0 -10
- package/lib/authentication/isExpired.js.map +0 -1
- package/lib/cache-persistance/index.d.ts.map +0 -1
- package/lib/cache-persistance/index.js.map +0 -1
- package/lib/types/ConnectionStringOptions.d.ts +0 -13
- package/lib/types/ConnectionStringOptions.d.ts.map +0 -1
- package/lib/types/ConnectionStringOptions.js +0 -2
- package/lib/types/ConnectionStringOptions.js.map +0 -1
- package/lib/types/LocalTokenCacheProvider.d.ts +0 -6
- package/lib/types/LocalTokenCacheProvider.d.ts.map +0 -1
- package/lib/types/LocalTokenCacheProvider.js +0 -2
- package/lib/types/LocalTokenCacheProvider.js.map +0 -1
|
@@ -3,7 +3,7 @@ import type { RemoteCacheClient, RemoteCacheClientOperationOptions, RemoteCacheC
|
|
|
3
3
|
export declare class AzureRemoteCacheClient implements RemoteCacheClient {
|
|
4
4
|
private readonly logger;
|
|
5
5
|
private readonly config;
|
|
6
|
-
constructor({ container,
|
|
6
|
+
constructor({ container, storageAccount, credential }: RemoteCacheClientOptions);
|
|
7
7
|
/**
|
|
8
8
|
* Uploads the folder to the remote cache.
|
|
9
9
|
* @param folderName - The name of the folder to upload.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AzureRemoteCacheClient.d.ts","sourceRoot":"","sources":["../src/AzureRemoteCacheClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAGpF,OAAO,KAAK,EACV,iBAAiB,EACjB,iCAAiC,EACjC,yCAAyC,EAC1C,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"AzureRemoteCacheClient.d.ts","sourceRoot":"","sources":["../src/AzureRemoteCacheClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAGpF,OAAO,KAAK,EACV,iBAAiB,EACjB,iCAAiC,EACjC,yCAAyC,EAC1C,MAAM,8BAA8B,CAAC;AAGtC,qBAAa,sBAAuB,YAAW,iBAAiB;IAC9D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsD;IAC7E,OAAO,CAAC,QAAQ,CAAC,MAAM,CAIrB;gBAEU,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,EAAE,wBAAwB;IAe/E;;;;;;OAMG;IACG,YAAY,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,yCAAyC;IAS/F;;;;;OAKG;IACG,cAAc,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,iCAAiC;CAY7E"}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { makeLogger, put, fetch } from 'backfill/lib/api.js';
|
|
2
2
|
import { existsSync } from 'fs';
|
|
3
|
+
import { createBlobStorageUrl } from './createBlobStorageUrl.js';
|
|
3
4
|
export class AzureRemoteCacheClient {
|
|
4
|
-
constructor({ container,
|
|
5
|
+
constructor({ container, storageAccount, credential }) {
|
|
5
6
|
this.logger = makeLogger('mute', process.stdout, process.stderr);
|
|
6
7
|
this.config = {
|
|
7
8
|
incrementalCaching: true,
|
|
8
|
-
internalCacheFolder: '',
|
|
9
|
+
internalCacheFolder: '', // not used by azure-blob
|
|
9
10
|
cacheStorageConfig: {
|
|
10
11
|
provider: 'azure-blob',
|
|
11
12
|
options: {
|
|
12
|
-
connectionString,
|
|
13
|
+
connectionString: createBlobStorageUrl(storageAccount),
|
|
14
|
+
credential,
|
|
13
15
|
container,
|
|
14
16
|
},
|
|
15
17
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AzureRemoteCacheClient.js","sourceRoot":"","sources":["../src/AzureRemoteCacheClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAG7D,OAAO,EAAE,UAAU,EAAE,MA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B,OAAO,eAAe,CAAC;QACzB,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACvE,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,WAAW,CAAC;QACrB,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["import { makeLogger, put, fetch } from 'backfill/lib/api.js';\nimport type { RemoteCacheClientOptions } from './types/RemoteCacheClientOptions.js';\nimport type { AzureBlobCacheStorageConfig } from 'backfill-config';\nimport { existsSync } from 'fs';\nimport type {\n RemoteCacheClient,\n RemoteCacheClientOperationOptions,\n RemoteCacheClientDownloadOperationOptions,\n} from './types/RemoteCacheClient.js';\nimport { createBlobStorageUrl } from './createBlobStorageUrl.js';\n\nexport class AzureRemoteCacheClient implements RemoteCacheClient {\n private readonly logger = makeLogger('mute', process.stdout, process.stderr);\n private readonly config: {\n cacheStorageConfig: AzureBlobCacheStorageConfig;\n incrementalCaching: boolean;\n internalCacheFolder: string;\n };\n\n constructor({ container, storageAccount, credential }: RemoteCacheClientOptions) {\n this.config = {\n incrementalCaching: true,\n internalCacheFolder: '', // not used by azure-blob\n cacheStorageConfig: {\n provider: 'azure-blob',\n options: {\n connectionString: createBlobStorageUrl(storageAccount),\n credential,\n container,\n },\n },\n };\n }\n\n /**\n * Uploads the folder to the remote cache.\n * @param folderName - The name of the folder to upload.\n * @param path - The path to the folder to upload.\n * @param globMatches - The glob pattern to use when uploading the folder.\n * @returns - A promise that resolves when the folder has been uploaded.\n */\n async uploadFolder({ folderName, path, globMatches }: RemoteCacheClientDownloadOperationOptions) {\n if (!existsSync(path)) {\n return 'not-found';\n }\n\n await put(path, folderName, this.logger, { ...this.config, outputGlob: globMatches });\n return 'success';\n }\n\n /**\n * Downloads the folder from the remote cache.\n * @param folderName - The name of the folder to download.\n * @param path - The path to download the folder to.\n * @returns - A promise that resolves when the folder has been downloaded.\n */\n async downloadFolder({ folderName, path }: RemoteCacheClientOperationOptions) {\n if (existsSync(path)) {\n return 'already-exist';\n }\n\n const result = await fetch(path, folderName, this.logger, this.config);\n if (!result) {\n return 'not-found';\n }\n\n return 'success';\n }\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieves the authentication record from Cloudpack's global cache folder.
|
|
3
|
+
* @param cachePath - The path to Cloudpack's cache folder.
|
|
4
|
+
* @returns - The authentication record if it exists; otherwise, returns `undefined`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getAuthenticationRecord(cachePath: string): import("@azure/identity").AuthenticationRecord | undefined;
|
|
7
|
+
//# sourceMappingURL=getAuthenticationRecord.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAuthenticationRecord.d.ts","sourceRoot":"","sources":["../../src/authentication/getAuthenticationRecord.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,8DAQxD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { deserializeAuthenticationRecord } from '@azure/identity';
|
|
2
|
+
import { existsSync, readFileSync } from 'fs';
|
|
3
|
+
import { getAuthenticationRecordPath } from './getAuthenticationRecordPath.js';
|
|
4
|
+
/**
|
|
5
|
+
* Retrieves the authentication record from Cloudpack's global cache folder.
|
|
6
|
+
* @param cachePath - The path to Cloudpack's cache folder.
|
|
7
|
+
* @returns - The authentication record if it exists; otherwise, returns `undefined`.
|
|
8
|
+
*/
|
|
9
|
+
export function getAuthenticationRecord(cachePath) {
|
|
10
|
+
const fullPath = getAuthenticationRecordPath(cachePath);
|
|
11
|
+
if (!existsSync(fullPath)) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
const content = readFileSync(fullPath, 'utf-8');
|
|
15
|
+
return deserializeAuthenticationRecord(content);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=getAuthenticationRecord.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAuthenticationRecord.js","sourceRoot":"","sources":["../../src/authentication/getAuthenticationRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,SAAiB;IACvD,MAAM,QAAQ,GAAG,2BAA2B,CAAC,SAAS,CAAC,CAAC;IACxD,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,OAAO,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAChD,OAAO,+BAA+B,CAAC,OAAO,CAAC,CAAC;AAClD,CAAC","sourcesContent":["import { deserializeAuthenticationRecord } from '@azure/identity';\nimport { existsSync, readFileSync } from 'fs';\nimport { getAuthenticationRecordPath } from './getAuthenticationRecordPath.js';\n\n/**\n * Retrieves the authentication record from Cloudpack's global cache folder.\n * @param cachePath - The path to Cloudpack's cache folder.\n * @returns - The authentication record if it exists; otherwise, returns `undefined`.\n */\nexport function getAuthenticationRecord(cachePath: string) {\n const fullPath = getAuthenticationRecordPath(cachePath);\n if (!existsSync(fullPath)) {\n return undefined;\n }\n\n const content = readFileSync(fullPath, 'utf-8');\n return deserializeAuthenticationRecord(content);\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constructs and returns the full path to the authentication record file within the specified cache folder.
|
|
3
|
+
* @param cachePath - The path to Cloudpack's cache folder.
|
|
4
|
+
* @returns - The full path to the authentication record file.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getAuthenticationRecordPath(cachePath: string): string;
|
|
7
|
+
//# sourceMappingURL=getAuthenticationRecordPath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAuthenticationRecordPath.d.ts","sourceRoot":"","sources":["../../src/authentication/getAuthenticationRecordPath.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,MAAM,UAE5D"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
/**
|
|
3
|
+
* Constructs and returns the full path to the authentication record file within the specified cache folder.
|
|
4
|
+
* @param cachePath - The path to Cloudpack's cache folder.
|
|
5
|
+
* @returns - The full path to the authentication record file.
|
|
6
|
+
*/
|
|
7
|
+
export function getAuthenticationRecordPath(cachePath) {
|
|
8
|
+
return path.join(cachePath, 'tokencache.bin');
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=getAuthenticationRecordPath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAuthenticationRecordPath.js","sourceRoot":"","sources":["../../src/authentication/getAuthenticationRecordPath.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CAAC,SAAiB;IAC3D,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import path from 'path';\n\n/**\n * Constructs and returns the full path to the authentication record file within the specified cache folder.\n * @param cachePath - The path to Cloudpack's cache folder.\n * @returns - The full path to the authentication record file.\n */\nexport function getAuthenticationRecordPath(cachePath: string) {\n return path.join(cachePath, 'tokencache.bin');\n}\n"]}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { AzureCliCredential, DeviceCodeCredential, InteractiveBrowserCredential } from '@azure/identity';
|
|
2
2
|
import type { LoginMethod } from '../types/LoginMethod.js';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Gets a credential for the given login method.
|
|
5
|
+
* If the login method is 'azure-cli', it will return an AzureCliCredential.
|
|
6
|
+
* Otherwise, it will return an InteractiveBrowserCredential or a DeviceCodeCredential with persistent token settings.
|
|
7
|
+
* If an authentication record has never been saved before, it will authenticate the credential and save the authentication record.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getCredential(loginMethod: LoginMethod, cachePath: string): Promise<InteractiveBrowserCredential | DeviceCodeCredential | AzureCliCredential>;
|
|
4
10
|
//# sourceMappingURL=getCredential.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCredential.d.ts","sourceRoot":"","sources":["../../src/authentication/getCredential.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"getCredential.d.ts","sourceRoot":"","sources":["../../src/authentication/getCredential.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,4BAA4B,EAI7B,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AA4B3D;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,qFA4B9E"}
|
|
@@ -1,17 +1,51 @@
|
|
|
1
|
-
import { AzureCliCredential, DeviceCodeCredential, InteractiveBrowserCredential } from '@azure/identity';
|
|
2
|
-
|
|
1
|
+
import { AzureCliCredential, DeviceCodeCredential, InteractiveBrowserCredential, useIdentityPlugin, } from '@azure/identity';
|
|
2
|
+
import { cachePersistencePlugin } from '../cache-persistance/cachePersistencePlugin.js';
|
|
3
|
+
import { getAuthenticationRecord } from './getAuthenticationRecord.js';
|
|
4
|
+
import { saveAuthenticationRecord } from './saveAuthenticationRecord.js';
|
|
5
|
+
const tokenCachePersistenceOptions = {
|
|
6
|
+
enabled: true,
|
|
7
|
+
name: 'cloudpack',
|
|
8
|
+
};
|
|
9
|
+
function getCredentialInternal(loginMethod, authenticationRecord) {
|
|
3
10
|
switch (loginMethod) {
|
|
4
11
|
case 'interactive':
|
|
5
12
|
return new InteractiveBrowserCredential({
|
|
6
13
|
redirectUri: 'http://localhost:1337',
|
|
14
|
+
authenticationRecord,
|
|
15
|
+
tokenCachePersistenceOptions,
|
|
7
16
|
});
|
|
8
17
|
case 'device-code':
|
|
9
|
-
return new DeviceCodeCredential(
|
|
10
|
-
|
|
11
|
-
|
|
18
|
+
return new DeviceCodeCredential({
|
|
19
|
+
authenticationRecord,
|
|
20
|
+
tokenCachePersistenceOptions,
|
|
21
|
+
});
|
|
12
22
|
default:
|
|
13
|
-
|
|
14
|
-
|
|
23
|
+
throw new Error(`Invalid login method: ${loginMethod}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Gets a credential for the given login method.
|
|
28
|
+
* If the login method is 'azure-cli', it will return an AzureCliCredential.
|
|
29
|
+
* Otherwise, it will return an InteractiveBrowserCredential or a DeviceCodeCredential with persistent token settings.
|
|
30
|
+
* If an authentication record has never been saved before, it will authenticate the credential and save the authentication record.
|
|
31
|
+
*/
|
|
32
|
+
export async function getCredential(loginMethod, cachePath) {
|
|
33
|
+
if (loginMethod == 'azure-cli') {
|
|
34
|
+
return new AzureCliCredential();
|
|
35
|
+
}
|
|
36
|
+
useIdentityPlugin(cachePersistencePlugin);
|
|
37
|
+
let authenticationRecord = getAuthenticationRecord(cachePath);
|
|
38
|
+
const credential = getCredentialInternal(loginMethod, authenticationRecord);
|
|
39
|
+
if (!authenticationRecord) {
|
|
40
|
+
console.warn('Cloudpack requires authentication to access Azure resources.');
|
|
41
|
+
if (loginMethod == 'interactive') {
|
|
42
|
+
console.warn("Prepare to sign in – we're launching a browser page for you. Simply follow the instructions on the login page to seamlessly complete the authentication process.");
|
|
43
|
+
}
|
|
44
|
+
authenticationRecord = await credential.authenticate('https://storage.azure.com/.default');
|
|
45
|
+
if (authenticationRecord) {
|
|
46
|
+
saveAuthenticationRecord(cachePath, authenticationRecord);
|
|
47
|
+
}
|
|
15
48
|
}
|
|
49
|
+
return credential;
|
|
16
50
|
}
|
|
17
51
|
//# sourceMappingURL=getCredential.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCredential.js","sourceRoot":"","sources":["../../src/authentication/getCredential.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"getCredential.js","sourceRoot":"","sources":["../../src/authentication/getCredential.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,4BAA4B,EAC5B,iBAAiB,GAGlB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,sBAAsB,EAAE,MAAM,gDAAgD,CAAC;AACxF,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,MAAM,4BAA4B,GAAiC;IACjE,OAAO,EAAE,IAAI;IACb,IAAI,EAAE,WAAW;CAClB,CAAC;AAEF,SAAS,qBAAqB,CAAC,WAAwB,EAAE,oBAA2C;IAClG,QAAQ,WAAW,EAAE,CAAC;QACpB,KAAK,aAAa;YAChB,OAAO,IAAI,4BAA4B,CAAC;gBACtC,WAAW,EAAE,uBAAuB;gBACpC,oBAAoB;gBACpB,4BAA4B;aAC7B,CAAC,CAAC;QACL,KAAK,aAAa;YAChB,OAAO,IAAI,oBAAoB,CAAC;gBAC9B,oBAAoB;gBACpB,4BAA4B;aAC7B,CAAC,CAAC;QACL;YACE,MAAM,IAAI,KAAK,CAAC,yBAAyB,WAAW,EAAE,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,WAAwB,EAAE,SAAiB;IAC7E,IAAI,WAAW,IAAI,WAAW,EAAE,CAAC;QAC/B,OAAO,IAAI,kBAAkB,EAAE,CAAC;IAClC,CAAC;IAED,iBAAiB,CAAC,sBAAsB,CAAC,CAAC;IAE1C,IAAI,oBAAoB,GAAG,uBAAuB,CAAC,SAAS,CAAC,CAAC;IAE9D,MAAM,UAAU,GAAG,qBAAqB,CAAC,WAAW,EAAE,oBAAoB,CAAC,CAAC;IAE5E,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC1B,OAAO,CAAC,IAAI,CAAC,8DAA8D,CAAC,CAAC;QAE7E,IAAI,WAAW,IAAI,aAAa,EAAE,CAAC;YACjC,OAAO,CAAC,IAAI,CACV,kKAAkK,CACnK,CAAC;QACJ,CAAC;QAED,oBAAoB,GAAG,MAAM,UAAU,CAAC,YAAY,CAAC,oCAAoC,CAAC,CAAC;QAE3F,IAAI,oBAAoB,EAAE,CAAC;YACzB,wBAAwB,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;QAC5D,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import {\n AzureCliCredential,\n DeviceCodeCredential,\n InteractiveBrowserCredential,\n useIdentityPlugin,\n type AuthenticationRecord,\n type TokenCachePersistenceOptions,\n} from '@azure/identity';\nimport type { LoginMethod } from '../types/LoginMethod.js';\nimport { cachePersistencePlugin } from '../cache-persistance/cachePersistencePlugin.js';\nimport { getAuthenticationRecord } from './getAuthenticationRecord.js';\nimport { saveAuthenticationRecord } from './saveAuthenticationRecord.js';\n\nconst tokenCachePersistenceOptions: TokenCachePersistenceOptions = {\n enabled: true,\n name: 'cloudpack',\n};\n\nfunction getCredentialInternal(loginMethod: LoginMethod, authenticationRecord?: AuthenticationRecord) {\n switch (loginMethod) {\n case 'interactive':\n return new InteractiveBrowserCredential({\n redirectUri: 'http://localhost:1337',\n authenticationRecord,\n tokenCachePersistenceOptions,\n });\n case 'device-code':\n return new DeviceCodeCredential({\n authenticationRecord,\n tokenCachePersistenceOptions,\n });\n default:\n throw new Error(`Invalid login method: ${loginMethod}`);\n }\n}\n\n/**\n * Gets a credential for the given login method.\n * If the login method is 'azure-cli', it will return an AzureCliCredential.\n * Otherwise, it will return an InteractiveBrowserCredential or a DeviceCodeCredential with persistent token settings.\n * If an authentication record has never been saved before, it will authenticate the credential and save the authentication record.\n */\nexport async function getCredential(loginMethod: LoginMethod, cachePath: string) {\n if (loginMethod == 'azure-cli') {\n return new AzureCliCredential();\n }\n\n useIdentityPlugin(cachePersistencePlugin);\n\n let authenticationRecord = getAuthenticationRecord(cachePath);\n\n const credential = getCredentialInternal(loginMethod, authenticationRecord);\n\n if (!authenticationRecord) {\n console.warn('Cloudpack requires authentication to access Azure resources.');\n\n if (loginMethod == 'interactive') {\n console.warn(\n \"Prepare to sign in – we're launching a browser page for you. Simply follow the instructions on the login page to seamlessly complete the authentication process.\",\n );\n }\n\n authenticationRecord = await credential.authenticate('https://storage.azure.com/.default');\n\n if (authenticationRecord) {\n saveAuthenticationRecord(cachePath, authenticationRecord);\n }\n }\n\n return credential;\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type AuthenticationRecord } from '@azure/identity';
|
|
2
|
+
/**
|
|
3
|
+
* Saves the provided authentication record to Cloudpack's global cache folder.
|
|
4
|
+
* Creates the cache folder if it doesn't exist.
|
|
5
|
+
* @param cachePath - The path to Cloudpack's cache folder.
|
|
6
|
+
* @param authRecord - The authentication record to save.
|
|
7
|
+
*/
|
|
8
|
+
export declare function saveAuthenticationRecord(cachePath: string, authRecord: AuthenticationRecord): void;
|
|
9
|
+
//# sourceMappingURL=saveAuthenticationRecord.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"saveAuthenticationRecord.d.ts","sourceRoot":"","sources":["../../src/authentication/saveAuthenticationRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,KAAK,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAI3F;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,oBAAoB,QAQ3F"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { serializeAuthenticationRecord } from '@azure/identity';
|
|
2
|
+
import { existsSync, mkdirSync, writeFileSync } from 'fs';
|
|
3
|
+
import { getAuthenticationRecordPath } from './getAuthenticationRecordPath.js';
|
|
4
|
+
/**
|
|
5
|
+
* Saves the provided authentication record to Cloudpack's global cache folder.
|
|
6
|
+
* Creates the cache folder if it doesn't exist.
|
|
7
|
+
* @param cachePath - The path to Cloudpack's cache folder.
|
|
8
|
+
* @param authRecord - The authentication record to save.
|
|
9
|
+
*/
|
|
10
|
+
export function saveAuthenticationRecord(cachePath, authRecord) {
|
|
11
|
+
const content = serializeAuthenticationRecord(authRecord);
|
|
12
|
+
if (!existsSync(cachePath)) {
|
|
13
|
+
mkdirSync(cachePath, { recursive: true });
|
|
14
|
+
}
|
|
15
|
+
writeFileSync(getAuthenticationRecordPath(cachePath), content);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=saveAuthenticationRecord.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"saveAuthenticationRecord.js","sourceRoot":"","sources":["../../src/authentication/saveAuthenticationRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAA6B,MAAM,iBAAiB,CAAC;AAC3F,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAC1D,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,SAAiB,EAAE,UAAgC;IAC1F,MAAM,OAAO,GAAG,6BAA6B,CAAC,UAAU,CAAC,CAAC;IAE1D,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC3B,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,aAAa,CAAC,2BAA2B,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { serializeAuthenticationRecord, type AuthenticationRecord } from '@azure/identity';\nimport { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { getAuthenticationRecordPath } from './getAuthenticationRecordPath.js';\n\n/**\n * Saves the provided authentication record to Cloudpack's global cache folder.\n * Creates the cache folder if it doesn't exist.\n * @param cachePath - The path to Cloudpack's cache folder.\n * @param authRecord - The authentication record to save.\n */\nexport function saveAuthenticationRecord(cachePath: string, authRecord: AuthenticationRecord) {\n const content = serializeAuthenticationRecord(authRecord);\n\n if (!existsSync(cachePath)) {\n mkdirSync(cachePath, { recursive: true });\n }\n\n writeFileSync(getAuthenticationRecordPath(cachePath), content);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cachePersistencePlugin.d.ts","sourceRoot":"","sources":["../../src/cache-persistance/cachePersistencePlugin.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGtD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,eAAO,MAAM,sBAAsB,EAAE,cAGpC,CAAC"}
|
|
@@ -32,4 +32,4 @@ export const cachePersistencePlugin = (context) => {
|
|
|
32
32
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
|
|
33
33
|
context.cachePluginControl.setPersistence(createPersistenceCachePlugin);
|
|
34
34
|
};
|
|
35
|
-
//# sourceMappingURL=
|
|
35
|
+
//# sourceMappingURL=cachePersistencePlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cachePersistencePlugin.js","sourceRoot":"","sources":["../../src/cache-persistance/cachePersistencePlugin.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,MAAM,CAAC,MAAM,sBAAsB,GAAmB,CAAC,OAAO,EAAE,EAAE;IAChE,6IAA6I;IAC5I,OAAe,CAAC,kBAAkB,CAAC,cAAc,CAAC,4BAA4B,CAAC,CAAC;AACnF,CAAC,CAAC","sourcesContent":["/**\n * This file is a fork of https://github.com/altinokdarici/azure-sdk-for-js/tree/main/sdk/identity/identity-cache-persistence\n */\n\n// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n// import { AzurePluginContext } from '../../identity/src/plugins/provider';\nimport type { IdentityPlugin } from '@azure/identity';\nimport { createPersistenceCachePlugin } from './provider.js';\n\n/**\n * A plugin that provides persistent token caching for `@azure/identity`\n * credentials. The plugin API is compatible with `@azure/identity` versions\n * 2.0.0 and later. Load this plugin using the `useIdentityPlugin`\n * function, imported from `@azure/identity`.\n *\n * In order to enable this functionality, you must also pass\n * `tokenCachePersistenceOptions` to your credential constructors with an\n * `enabled` property set to true.\n *\n * Example:\n *\n * ```javascript\n * import { useIdentityPlugin, DeviceCodeCredential } from \"@azure/identity\";\n * import { cachePersistencePlugin } from \"@azure/identity-cache-persistence\";\n *\n * // Load the plugin\n * useIdentityPlugin(cachePersistencePlugin);\n *\n * const credential = new DeviceCodeCredential({\n * tokenCachePersistenceOptions: {\n * enabled: true\n * }\n * });\n * ```\n */\n\nexport const cachePersistencePlugin: IdentityPlugin = (context) => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n (context as any).cachePluginControl.setPersistence(createPersistenceCachePlugin);\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platforms.js","sourceRoot":"","sources":["../../src/cache-persistance/platforms.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,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AE,EAAwB,EAAE;QAC1E,MAAM,EAAE,IAAI,EAAE,6BAA6B,EAAE,GAAG,OAAO,CAAC;QACxD,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,iBAAiB,CAAC,OAAO,CAAC;QACvD,MAAM,eAAe,GAAG,kBAAkB,CAAC,IAAI,IAAI,iBAAiB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAEtF,IAAI,CAAC;YACH,MAAM,WAAW,GAAG,MAAM,oBAAoB,CAAC,MAAM,CAAC,eAAe,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YACzF,qGAAqG;YACrG,MAAM,WAAW,CAAC,IAAI,EAAE,CAAC;YACzB,OAAO,WAAW,CAAC;QACrB,CAAC;QAAC,MAAM,CAAC;YACP,4DAA4D;YAC5D,sFAAsF;YACtF,IAAI,CAAC,6BAA6B,EAAE,CAAC;gBACnC,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;YACzE,CAAC;YACD,OAAO,eAAe,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;CACF,CAAC","sourcesContent":["/**\n * This file is a fork of https://github.com/altinokdarici/azure-sdk-for-js/tree/main/sdk/identity/identity-cache-persistence\n */\n\n// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport * as path from 'path';\nimport {\n DataProtectionScope,\n FilePersistence,\n FilePersistenceWithDataProtection,\n KeychainPersistence,\n LibSecretPersistence,\n type IPersistence as Persistence,\n} from '@azure/msal-node-extensions';\nimport type { TokenCachePersistenceOptions } from '@azure/identity';\n\n/**\n * Local application data folder\n * Expected values:\n * - Darwin: '/Users/user/'\n * - Windows 8+: 'C:\\Users\\user\\AppData\\Local'\n * - Linux: '/home/user/.local/share'\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\nconst localApplicationDataFolder = process.env.APPDATA?.replace?.(/(.Roaming)*$/, '\\\\Local') ?? process.env.HOME!;\n\n/**\n * Dictionary of values that we use as default as we discover, pick and enable the persistence layer.\n * @internal\n */\nexport const defaultMsalValues = {\n tokenCache: {\n name: 'msal.cache',\n // Expected values:\n // - Darwin: '/Users/user/.IdentityService'\n // - Windows 8+: 'C:\\Users\\user\\AppData\\Local\\.IdentityService'\n // - Linux: '/home/user/.IdentityService'\n directory: path.join(localApplicationDataFolder, '.IdentityService'),\n },\n keyRing: {\n label: 'MSALCache',\n schema: 'msal.cache',\n collection: 'default',\n attributes: {\n MsalClientID: 'Microsoft.Developer.IdentityService',\n 'Microsoft.Developer.IdentityService': '1.0.0.0',\n },\n service: 'Microsoft.Developer.IdentityService',\n account: 'MSALCache',\n },\n keyChain: {\n service: 'Microsoft.Developer.IdentityService',\n account: 'MSALCache',\n },\n};\n\n/**\n * Options that are used by the underlying MSAL cache provider.\n * @internal\n */\nexport type MsalPersistenceOptions = Omit<TokenCachePersistenceOptions, 'enabled'>;\n\n/**\n * A function that returns a persistent token cache instance.\n * @internal\n */\ntype MsalPersistenceFactory = (options?: MsalPersistenceOptions) => Promise<Persistence>;\n\n/**\n * Expected responses:\n * - Darwin: '/Users/user/.IdentityService/<name>'\n * - Windows 8+: 'C:\\Users\\user\\AppData\\Local\\.IdentityService\\<name>'\n * - Linux: '/home/user/.IdentityService/<name>'\n * @internal\n */\nfunction getPersistencePath(name: string): string {\n return path.join(defaultMsalValues.tokenCache.directory, name);\n}\n\n/**\n * Set of the platforms we attempt to deliver persistence on.\n *\n * - On Windows we use DPAPI.\n * - On OSX (Darwin), we try to use the system's Keychain, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.\n * - On Linux, we try to use the system's Keyring, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.\n *\n * Other platforms _are not supported_ at this time.\n *\n * @internal\n */\nexport const msalPersistencePlatforms: Partial<Record<NodeJS.Platform, MsalPersistenceFactory>> = {\n win32: ({ name = defaultMsalValues.tokenCache.name } = {}): Promise<Persistence> =>\n FilePersistenceWithDataProtection.create(getPersistencePath(name), DataProtectionScope.CurrentUser),\n\n darwin: async (options: MsalPersistenceOptions = {}): Promise<Persistence> => {\n const { name, unsafeAllowUnencryptedStorage } = options;\n const { service, account } = defaultMsalValues.keyChain;\n const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);\n\n try {\n const persistence = await KeychainPersistence.create(persistencePath, service, account);\n // If we don't encounter an error when trying to read from the keychain, then we should be good to go.\n await persistence.load();\n return persistence;\n } catch {\n // If we got an error while trying to read from the keyring,\n // we will proceed only if the user has specified that unencrypted storage is allowed.\n if (!unsafeAllowUnencryptedStorage) {\n throw new Error('Unable to read from the macOS Keychain.');\n }\n return FilePersistence.create(persistencePath);\n }\n },\n\n linux: async (options: MsalPersistenceOptions = {}): Promise<Persistence> => {\n const { name, unsafeAllowUnencryptedStorage } = options;\n const { service, account } = defaultMsalValues.keyRing;\n const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);\n\n try {\n const persistence = await LibSecretPersistence.create(persistencePath, service, account);\n // If we don't encounter an error when trying to read from the keyring, then we should be good to go.\n await persistence.load();\n return persistence;\n } catch {\n // If we got an error while trying to read from the keyring,\n // we will proceed only if the user has specified that unencrypted storage is allowed.\n if (!unsafeAllowUnencryptedStorage) {\n throw new Error('Unable to read from the system keyring (libsecret).');\n }\n return FilePersistence.create(persistencePath);\n }\n },\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/cache-persistance/provider.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAGrE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAA+B;IACrE,MAAM,WAAW,GAAG,MAAM,wBAAwB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;IAEhF,IAAI,WAAW,KAAK,SAAS,EAAE;
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/cache-persistance/provider.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAGrE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAA+B;IACrE,MAAM,WAAW,GAAG,MAAM,wBAAwB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;IAEhF,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC7E,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAAC,OAAgC;IACjF,MAAM,WAAW,GAAG,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IAE3D,OAAO,IAAI,sBAAsB,CAAC,WAAW,EAAE;QAC7C,WAAW,EAAE,GAAG;QAChB,UAAU,EAAE,EAAE;KACf,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * This file is a fork of https://github.com/altinokdarici/azure-sdk-for-js/tree/main/sdk/identity/identity-cache-persistence\n */\n\n// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport type { MsalPersistenceOptions } from './platforms.js';\nimport { msalPersistencePlatforms } from './platforms.js';\nimport type { IPersistence as Persistence } from '@azure/msal-node-extensions';\nimport { PersistenceCachePlugin } from '@azure/msal-node-extensions';\nimport type { ICachePlugin as CachePlugin } from '@azure/msal-node';\n\n/**\n * This is used to gain access to the underlying Persistence instance, which we use for testing\n *\n * @returns a raw persistence instance\n * @internal\n */\nexport async function createPersistence(options: MsalPersistenceOptions): Promise<Persistence> {\n const persistence = await msalPersistencePlatforms[process.platform]?.(options);\n\n if (persistence === undefined) {\n throw new Error('no persistence providers are available on this platform');\n }\n\n return persistence;\n}\n\nexport async function createPersistenceCachePlugin(options?: MsalPersistenceOptions): Promise<CachePlugin> {\n const persistence = await createPersistence(options ?? {});\n\n return new PersistenceCachePlugin(persistence, {\n retryNumber: 100,\n retryDelay: 50,\n });\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBlobStorageUrl.d.ts","sourceRoot":"","sources":["../src/createBlobStorageUrl.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAAC,cAAc,EAAE,MAAM,UAE1D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBlobStorageUrl.js","sourceRoot":"","sources":["../src/createBlobStorageUrl.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,oBAAoB,CAAC,cAAsB;IACzD,OAAO,WAAW,cAAc,wBAAwB,CAAC;AAC3D,CAAC","sourcesContent":["export function createBlobStorageUrl(storageAccount: string) {\n return `https://${storageAccount}.blob.core.windows.net`;\n}\n"]}
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import type { TaskReporter } from '@ms-cloudpack/task-reporter';
|
|
2
|
-
import type { ConnectionStringOptions } from './types/ConnectionStringOptions.js';
|
|
3
2
|
import type { RemoteCacheClient } from './types/RemoteCacheClient.js';
|
|
4
3
|
import type { TelemetryClient } from '@ms-cloudpack/telemetry';
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import type { LoginMethod } from './types/LoginMethod.js';
|
|
5
|
+
export interface CreateRemoteCacheClientParams {
|
|
6
|
+
options: {
|
|
7
|
+
storageAccount: string;
|
|
8
|
+
container: string;
|
|
9
|
+
loginMethod: LoginMethod;
|
|
10
|
+
cachePath: string;
|
|
11
|
+
};
|
|
7
12
|
context: {
|
|
8
13
|
reporter: TaskReporter;
|
|
9
14
|
telemetryClient: TelemetryClient;
|
|
10
15
|
};
|
|
11
|
-
}
|
|
16
|
+
}
|
|
17
|
+
export declare function createRemoteCacheClient(params: CreateRemoteCacheClientParams): Promise<RemoteCacheClient>;
|
|
12
18
|
//# sourceMappingURL=createRemoteCacheClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRemoteCacheClient.d.ts","sourceRoot":"","sources":["../src/createRemoteCacheClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"createRemoteCacheClient.d.ts","sourceRoot":"","sources":["../src/createRemoteCacheClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAKhE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAMtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D,MAAM,WAAW,6BAA6B;IAC5C,OAAO,EAAE;QACP,cAAc,EAAE,MAAM,CAAC;QACvB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,WAAW,CAAC;QACzB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,OAAO,EAAE;QACP,QAAQ,EAAE,YAAY,CAAC;QACvB,eAAe,EAAE,eAAe,CAAC;KAClC,CAAC;CACH;AAED,wBAAsB,uBAAuB,CAAC,MAAM,EAAE,6BAA6B,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAwB/G"}
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import { AzureRemoteCacheClient } from './AzureRemoteCacheClient.js';
|
|
2
|
-
import { getAuthenticatedConnectionString } from './authentication/getAuthenticatedConnectionString.js';
|
|
3
2
|
import { InMemoryDecorator } from './decorators/InMemoryDecorator.js';
|
|
4
3
|
import { ReporterDecorator } from './decorators/ReporterDecorator.js';
|
|
5
4
|
import { getListOfBlobs } from './getListOfBlobs.js';
|
|
6
5
|
import { RetryDecorator } from './decorators/RetryDecorator.js';
|
|
7
6
|
import { blockListIsInvalidRetryPolicy } from './retry/blockListIsInvalidRetryPolicy.js';
|
|
8
7
|
import { RetryManager } from '@ms-cloudpack/retry';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const {
|
|
12
|
-
const
|
|
13
|
-
const
|
|
8
|
+
import { getCredential } from './authentication/getCredential.js';
|
|
9
|
+
export async function createRemoteCacheClient(params) {
|
|
10
|
+
const { context, options } = params;
|
|
11
|
+
const { container, loginMethod, storageAccount, cachePath } = options;
|
|
12
|
+
const credential = await getCredential(loginMethod, cachePath);
|
|
13
|
+
const remoteCacheClientOptions = {
|
|
14
|
+
storageAccount,
|
|
14
15
|
container,
|
|
15
|
-
|
|
16
|
+
credential,
|
|
16
17
|
};
|
|
17
18
|
const client = new ReporterDecorator(new RetryDecorator({
|
|
18
19
|
retryManager: new RetryManager([blockListIsInvalidRetryPolicy]),
|
|
19
20
|
cacheClient: new InMemoryDecorator({
|
|
20
|
-
cacheClient: new AzureRemoteCacheClient(
|
|
21
|
-
getList: () => getListOfBlobs(
|
|
21
|
+
cacheClient: new AzureRemoteCacheClient(remoteCacheClientOptions),
|
|
22
|
+
getList: () => getListOfBlobs(remoteCacheClientOptions),
|
|
22
23
|
}),
|
|
23
24
|
}), context);
|
|
24
25
|
return client;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRemoteCacheClient.js","sourceRoot":"","sources":["../src/createRemoteCacheClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"createRemoteCacheClient.js","sourceRoot":"","sources":["../src/createRemoteCacheClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAiBlE,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,MAAqC;IACjF,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IACpC,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAEtE,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IAE/D,MAAM,wBAAwB,GAA6B;QACzD,cAAc;QACd,SAAS;QACT,UAAU;KACX,CAAC;IAEF,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAClC,IAAI,cAAc,CAAC;QACjB,YAAY,EAAE,IAAI,YAAY,CAAC,CAAC,6BAA6B,CAAC,CAAC;QAC/D,WAAW,EAAE,IAAI,iBAAiB,CAAC;YACjC,WAAW,EAAE,IAAI,sBAAsB,CAAC,wBAAwB,CAAC;YACjE,OAAO,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,wBAAwB,CAAC;SACxD,CAAC;KACH,CAAC,EACF,OAAO,CACR,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport { AzureRemoteCacheClient } from './AzureRemoteCacheClient.js';\nimport { InMemoryDecorator } from './decorators/InMemoryDecorator.js';\nimport { ReporterDecorator } from './decorators/ReporterDecorator.js';\nimport { getListOfBlobs } from './getListOfBlobs.js';\nimport type { RemoteCacheClient } from './types/RemoteCacheClient.js';\nimport { RetryDecorator } from './decorators/RetryDecorator.js';\nimport { blockListIsInvalidRetryPolicy } from './retry/blockListIsInvalidRetryPolicy.js';\nimport { RetryManager } from '@ms-cloudpack/retry';\nimport type { RemoteCacheClientOptions } from './types/RemoteCacheClientOptions.js';\nimport { getCredential } from './authentication/getCredential.js';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport type { LoginMethod } from './types/LoginMethod.js';\n\nexport interface CreateRemoteCacheClientParams {\n options: {\n storageAccount: string;\n container: string;\n loginMethod: LoginMethod;\n cachePath: string;\n };\n context: {\n reporter: TaskReporter;\n telemetryClient: TelemetryClient;\n };\n}\n\nexport async function createRemoteCacheClient(params: CreateRemoteCacheClientParams): Promise<RemoteCacheClient> {\n const { context, options } = params;\n const { container, loginMethod, storageAccount, cachePath } = options;\n\n const credential = await getCredential(loginMethod, cachePath);\n\n const remoteCacheClientOptions: RemoteCacheClientOptions = {\n storageAccount,\n container,\n credential,\n };\n\n const client = new ReporterDecorator(\n new RetryDecorator({\n retryManager: new RetryManager([blockListIsInvalidRetryPolicy]),\n cacheClient: new InMemoryDecorator({\n cacheClient: new AzureRemoteCacheClient(remoteCacheClientOptions),\n getList: () => getListOfBlobs(remoteCacheClientOptions),\n }),\n }),\n context,\n );\n\n return client;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InMemoryDecorator.js","sourceRoot":"","sources":["../../src/decorators/InMemoryDecorator.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAI5B,YAAY,OAAgF;QAC1F,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAAkD;QACnE,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"InMemoryDecorator.js","sourceRoot":"","sources":["../../src/decorators/InMemoryDecorator.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAI5B,YAAY,OAAgF;QAC1F,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAAkD;QACnE,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9C,gFAAgF;YAChF,OAAO,eAAe,CAAC;QACzB,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAE5D,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,0DAA0D;YAC1D,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC5C,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAA0C;QAC7D,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;YAC/C,sEAAsE;YACtE,OAAO,WAAW,CAAC;QACrB,CAAC;QAED,OAAO,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IAClD,CAAC;CACF","sourcesContent":["import type {\n RemoteCacheClient,\n RemoteCacheClientDownloadOperationOptions,\n RemoteCacheClientOperationOptions,\n RemoteCacheClientOperationResult,\n} from '../types/RemoteCacheClient.js';\n\n/**\n * A decorator for a RemoteCacheClient that keeps a list of remote resources locally.\n */\nexport class InMemoryDecorator implements RemoteCacheClient {\n private readonly cacheClient: RemoteCacheClient;\n private readonly list: Promise<Set<string>>;\n\n constructor(options: { cacheClient: RemoteCacheClient; getList: () => Promise<Set<string>> }) {\n this.cacheClient = options.cacheClient;\n this.list = options.getList();\n }\n\n async uploadFolder(options: RemoteCacheClientDownloadOperationOptions): Promise<RemoteCacheClientOperationResult> {\n if ((await this.list).has(options.folderName)) {\n // This resource already exists in the remote cache, no need to upload it again.\n return 'already-exist';\n }\n\n const result = await this.cacheClient.uploadFolder(options);\n\n if (result === 'success') {\n // The upload is successful, add the resource to the list.\n (await this.list).add(options.folderName);\n }\n\n return result;\n }\n\n async downloadFolder(options: RemoteCacheClientOperationOptions): Promise<RemoteCacheClientOperationResult> {\n if (!(await this.list).has(options.folderName)) {\n // This resource doesn't exist in the remote cache, can't download it.\n return 'not-found';\n }\n\n return this.cacheClient.downloadFolder(options);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReporterDecorator.js","sourceRoot":"","sources":["../../src/decorators/ReporterDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAQ9E,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,IAAI,mBAAmB,GAAY,KAAK,CAAC;AAEzC;;;;GAIG;AACH,SAAS,WAAW,CAAC,eAAgC,EAAE,KAAY;IACjE,MAAM,WAAW,GAAG,KAAK,YAAY,SAAS,IAAI,KAAK,CAAC,UAAU,KAAK,GAAG,CAAC;IAE3E,IAAI,WAAW,IAAI,mBAAmB,EAAE;
|
|
1
|
+
{"version":3,"file":"ReporterDecorator.js","sourceRoot":"","sources":["../../src/decorators/ReporterDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAQ9E,OAAO,EAAE,SAAS,EAAE,M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YACH,cAAc,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAC7D,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;gBACvB,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC;YAC/C,CAAC;YAED,IAAI,CAAC,QAAQ,CAAC;gBACZ,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,CAAC,CAAC;aAC9C,CAAC,CAAC;YACH,MAAM,CAAC,CAAC;QACV,CAAC;QAED,QAAQ,cAAc,EAAE,CAAC;YACvB,KAAK,SAAS;gBACZ,IAAI,CAAC,QAAQ,CAAC;oBACZ,MAAM,EAAE,UAAU;oBAClB,OAAO,EAAE,YAAY,CAAC,CAAC,eAAe,UAAU,EAAE,EAAE,SAAS,IAAI,EAAE,EAAE,SAAS,YAAY,EAAE,CAAC,CAAC;iBAC/F,CAAC,CAAC;gBACH,MAAM;YACR,KAAK,WAAW;gBACd,IAAI,CAAC,QAAQ,CAAC;oBACZ,MAAM,EAAE,MAAM;oBACd,OAAO,EAAE,gCAAgC;iBAC1C,CAAC,CAAC;gBACH,MAAM;YACR,KAAK,eAAe;gBAClB,IAAI,CAAC,QAAQ,CAAC;oBACZ,MAAM,EAAE,MAAM;oBACd,OAAO,EAAE,8CAA8C;iBACxD,CAAC,CAAC;gBACH,MAAM;YACR;gBACE,MAAM,IAAI,KAAK,CAAC,4BAA4B,cAAc,EAAE,CAAC,CAAC;QAClE,CAAC;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;CACF","sourcesContent":["import { bulletedList, type TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type {\n RemoteCacheClient,\n RemoteCacheClientDownloadOperationOptions,\n RemoteCacheClientOperationOptions,\n RemoteCacheClientOperationResult,\n} from '../types/RemoteCacheClient.js';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport { RestError } from '@azure/storage-blob';\n\nlet isAuthErrorReported: boolean = false;\n\n/**\n * Reports an error to the telemetry client. If the error is an auth error, it will be reported only once.\n * @param telemetryClient - The telemetry client to report the error to.\n * @param error - The error to report.\n */\nfunction reportError(telemetryClient: TelemetryClient, error: Error) {\n const isAuthError = error instanceof RestError && error.statusCode === 403;\n\n if (isAuthError && isAuthErrorReported) {\n return; // No need to proceed if auth error is already reported\n }\n\n telemetryClient.rootSpan.recordException(error);\n\n // Set isAuthErrorReported only if it's an auth error\n isAuthErrorReported = isAuthError;\n}\n\nexport class ReporterDecorator implements RemoteCacheClient {\n constructor(\n private readonly client: RemoteCacheClient,\n private readonly context: {\n reporter: TaskReporter;\n telemetryClient: TelemetryClient;\n },\n ) {}\n\n private buildFailureMessage({ folderName, friendlyName, path }: RemoteCacheClientOperationOptions, error: unknown) {\n const list = bulletedList([\n `FolderName: ${folderName}`,\n `Path: ${path}`,\n `Name: ${friendlyName}`,\n `Error: ${error instanceof Error ? error.message : '<Unknown>'}`,\n ]);\n\n return `\\n${list}`;\n }\n\n async uploadFolder(options: RemoteCacheClientDownloadOperationOptions) {\n const { folderName, path, friendlyName } = options;\n const task = this.context.reporter.addTask(`Uploading to remote cache: ${friendlyName}`);\n\n let uploadResult: RemoteCacheClientOperationResult;\n\n try {\n uploadResult = await this.client.uploadFolder(options);\n } catch (e) {\n if (e instanceof Error) {\n reportError(this.context.telemetryClient, e);\n }\n task.complete({\n status: 'fail',\n message: this.buildFailureMessage(options, e),\n });\n throw e;\n }\n\n switch (uploadResult) {\n case 'success':\n task.complete({\n status: 'complete',\n details: bulletedList([`FolderName: ${folderName}`, `Path: ${path}`, `Name: ${friendlyName}`]),\n });\n break;\n case 'not-found':\n task.complete({\n status: 'skip',\n message: `Not found in the local cache.`,\n });\n break;\n case 'already-exist':\n task.complete({\n status: 'skip',\n message: `Package is already exist in the remote cache.`,\n });\n break;\n default:\n throw new Error(`Unknown upload result: ${uploadResult}`);\n }\n\n return uploadResult;\n }\n\n async downloadFolder(options: RemoteCacheClientOperationOptions) {\n const { folderName, path, friendlyName } = options;\n const task = this.context.reporter.addTask(`Downloading from remote cache: ${friendlyName}`);\n\n let downloadResult: RemoteCacheClientOperationResult;\n\n try {\n downloadResult = await this.client.downloadFolder(options);\n } catch (e) {\n if (e instanceof Error) {\n reportError(this.context.telemetryClient, e);\n }\n\n task.complete({\n status: 'fail',\n message: this.buildFailureMessage(options, e),\n });\n throw e;\n }\n\n switch (downloadResult) {\n case 'success':\n task.complete({\n status: 'complete',\n details: bulletedList([`FolderName: ${folderName}`, `Path: ${path}`, `Name: ${friendlyName}`]),\n });\n break;\n case 'not-found':\n task.complete({\n status: 'skip',\n message: `Not found in the remote cache.`,\n });\n break;\n case 'already-exist':\n task.complete({\n status: 'skip',\n message: `Package is already exist in the local cache.`,\n });\n break;\n default:\n throw new Error(`Unknown download result: ${downloadResult}`);\n }\n\n return downloadResult;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RetryDecorator.js","sourceRoot":"","sources":["../../src/decorators/RetryDecorator.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,OAAO,cAAc;IAIzB,YAAY,OAAuE;QACjF,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC3C,CAAC;IAEO,iBAAiB,CACvB,aAAqB,EACrB,OAA0C,EAC1C,YAA2D;QAE3D,IAAI,YAAY,EAAE;
|
|
1
|
+
{"version":3,"file":"RetryDecorator.js","sourceRoot":"","sources":["../../src/decorators/RetryDecorator.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,OAAO,cAAc;IAIzB,YAAY,OAAuE;QACjF,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC3C,CAAC;IAEO,iBAAiB,CACvB,aAAqB,EACrB,OAA0C,EAC1C,YAA2D;QAE3D,IAAI,YAAY,EAAE,CAAC;YACjB,OAAO,CAAC,IAAI,CACV,YAAY,aAAa,IAAI,OAAO,CAAC,YAAY,SAAS,YAAY,CAAC,YAAY,IAAI,YAAY,CAAC,UAAU,GAAG,CAClH,CAAC;QACJ,CAAC;IACH,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAAkD;QACnE,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,EAAE;YAC9C,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;YACxD,OAAO,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAA0C;QAC7D,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,EAAE;YAC9C,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;YAC1D,OAAO,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type {\n RemoteCacheClient,\n RemoteCacheClientDownloadOperationOptions,\n RemoteCacheClientOperationOptions,\n RemoteCacheClientOperationResult,\n} from '../types/RemoteCacheClient.js';\nimport type { RetryManager } from '@ms-cloudpack/retry';\n\n/**\n * A decorator that retries the upload/download operation if it fails.\n */\nexport class RetryDecorator implements RemoteCacheClient {\n private readonly cacheClient: RemoteCacheClient;\n private readonly retryManager: RetryManager;\n\n constructor(options: { cacheClient: RemoteCacheClient; retryManager: RetryManager }) {\n this.cacheClient = options.cacheClient;\n this.retryManager = options.retryManager;\n }\n\n private printRetryContext(\n operationName: string,\n options: RemoteCacheClientOperationOptions,\n retryContext?: { retryAttempt: number; maxRetries: number },\n ) {\n if (retryContext) {\n console.warn(\n `Retrying ${operationName} ${options.friendlyName} ... [${retryContext.retryAttempt}/${retryContext.maxRetries}]`,\n );\n }\n }\n\n async uploadFolder(options: RemoteCacheClientDownloadOperationOptions): Promise<RemoteCacheClientOperationResult> {\n return this.retryManager.retry((retryContext) => {\n this.printRetryContext('upload', options, retryContext);\n return this.cacheClient.uploadFolder(options);\n });\n }\n\n async downloadFolder(options: RemoteCacheClientOperationOptions): Promise<RemoteCacheClientOperationResult> {\n return this.retryManager.retry((retryContext) => {\n this.printRetryContext('download', options, retryContext);\n return this.cacheClient.downloadFolder(options);\n });\n }\n}\n"]}
|
package/lib/getListOfBlobs.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import type { RemoteCacheClientOptions } from './types/RemoteCacheClientOptions.
|
|
|
2
2
|
/**
|
|
3
3
|
* Gets all the blobs in the remote cache.
|
|
4
4
|
*/
|
|
5
|
-
export declare function getListOfBlobs({ container,
|
|
5
|
+
export declare function getListOfBlobs({ container, storageAccount, credential }: RemoteCacheClientOptions): Promise<Set<string>>;
|
|
6
6
|
//# sourceMappingURL=getListOfBlobs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getListOfBlobs.d.ts","sourceRoot":"","sources":["../src/getListOfBlobs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getListOfBlobs.d.ts","sourceRoot":"","sources":["../src/getListOfBlobs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAGpF;;GAEG;AACH,wBAAsB,cAAc,CAAC,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,EAAE,wBAAwB,wBAQvG"}
|
package/lib/getListOfBlobs.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { createBlobStorageUrl } from './createBlobStorageUrl.js';
|
|
1
2
|
import { BlobServiceClient } from '@azure/storage-blob';
|
|
2
3
|
/**
|
|
3
4
|
* Gets all the blobs in the remote cache.
|
|
4
5
|
*/
|
|
5
|
-
export async function getListOfBlobs({ container,
|
|
6
|
-
const blobStorageClient = BlobServiceClient
|
|
6
|
+
export async function getListOfBlobs({ container, storageAccount, credential }) {
|
|
7
|
+
const blobStorageClient = new BlobServiceClient(createBlobStorageUrl(storageAccount), credential);
|
|
7
8
|
const containerClient = blobStorageClient.getContainerClient(container);
|
|
8
9
|
const blobs = new Set();
|
|
9
10
|
for await (const blob of containerClient.listBlobsFlat()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getListOfBlobs.js","sourceRoot":"","sources":["../src/getListOfBlobs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getListOfBlobs.js","sourceRoot":"","sources":["../src/getListOfBlobs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAA4B;IACtG,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,oBAAoB,CAAC,cAAc,CAAC,EAAE,UAAU,CAAC,CAAC;IAClG,MAAM,eAAe,GAAG,iBAAiB,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IACxE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,eAAe,CAAC,aAAa,EAAE,EAAE,CAAC;QACzD,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { createBlobStorageUrl } from './createBlobStorageUrl.js';\nimport type { RemoteCacheClientOptions } from './types/RemoteCacheClientOptions.js';\nimport { BlobServiceClient } from '@azure/storage-blob';\n\n/**\n * Gets all the blobs in the remote cache.\n */\nexport async function getListOfBlobs({ container, storageAccount, credential }: RemoteCacheClientOptions) {\n const blobStorageClient = new BlobServiceClient(createBlobStorageUrl(storageAccount), credential);\n const containerClient = blobStorageClient.getContainerClient(container);\n const blobs = new Set<string>();\n for await (const blob of containerClient.listBlobsFlat()) {\n blobs.add(blob.name);\n }\n return blobs;\n}\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export { createRemoteCacheClient } from './createRemoteCacheClient.js';
|
|
1
|
+
export { createRemoteCacheClient, type CreateRemoteCacheClientParams } from './createRemoteCacheClient.js';
|
|
2
2
|
export type { RemoteCacheClient, RemoteCacheClientDownloadOperationOptions, RemoteCacheClientOperationOptions, RemoteCacheClientOperationResult, } from './types/RemoteCacheClient.js';
|
|
3
|
-
export type { ConnectionStringOptions } from './types/ConnectionStringOptions.js';
|
|
4
3
|
export type { LoginMethod } from './types/LoginMethod.js';
|
|
5
4
|
export type { RemoteCacheClientOptions } from './types/RemoteCacheClientOptions.js';
|
|
6
5
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,KAAK,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AAE3G,YAAY,EACV,iBAAiB,EACjB,yCAAyC,EACzC,iCAAiC,EACjC,gCAAgC,GACjC,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC"}
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAsC,MAAM,8BAA8B,CAAC","sourcesContent":["export { createRemoteCacheClient, type CreateRemoteCacheClientParams } from './createRemoteCacheClient.js';\n\nexport type {\n RemoteCacheClient,\n RemoteCacheClientDownloadOperationOptions,\n RemoteCacheClientOperationOptions,\n RemoteCacheClientOperationResult,\n} from './types/RemoteCacheClient.js';\nexport type { LoginMethod } from './types/LoginMethod.js';\nexport type { RemoteCacheClientOptions } from './types/RemoteCacheClientOptions.js';\n"]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { TokenCredential } from '@azure/identity';
|
|
1
2
|
export interface RemoteCacheClientOptions {
|
|
2
|
-
|
|
3
|
+
storageAccount: string;
|
|
3
4
|
container: string;
|
|
5
|
+
credential: TokenCredential;
|
|
4
6
|
}
|
|
5
7
|
//# sourceMappingURL=RemoteCacheClientOptions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteCacheClientOptions.d.ts","sourceRoot":"","sources":["../../src/types/RemoteCacheClientOptions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,wBAAwB;IACvC,
|
|
1
|
+
{"version":3,"file":"RemoteCacheClientOptions.d.ts","sourceRoot":"","sources":["../../src/types/RemoteCacheClientOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD,MAAM,WAAW,wBAAwB;IACvC,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,eAAe,CAAC;CAC7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteCacheClientOptions.js","sourceRoot":"","sources":["../../src/types/RemoteCacheClientOptions.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"RemoteCacheClientOptions.js","sourceRoot":"","sources":["../../src/types/RemoteCacheClientOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { TokenCredential } from '@azure/identity';\n\nexport interface RemoteCacheClientOptions {\n storageAccount: string;\n container: string;\n credential: TokenCredential;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/remote-cache",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Manages syncing the local Cloudpack cached assets to/from a remote storage service.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -32,13 +32,12 @@
|
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@azure/msal-node": "^2.6.0",
|
|
35
|
-
"@azure/msal-node-extensions": "^1.0.
|
|
35
|
+
"@azure/msal-node-extensions": "^1.0.8",
|
|
36
36
|
"@ms-cloudpack/task-reporter": "^0.10.2",
|
|
37
|
-
"@ms-cloudpack/telemetry": "^0.4.
|
|
37
|
+
"@ms-cloudpack/telemetry": "^0.4.5",
|
|
38
38
|
"@ms-cloudpack/retry": "^0.1.1",
|
|
39
39
|
"@azure/identity": "^3.4.0",
|
|
40
40
|
"@azure/storage-blob": "^12.17.0",
|
|
41
|
-
"@napi-rs/keyring": "^1.1.3",
|
|
42
41
|
"backfill": "^6.2.1",
|
|
43
42
|
"backfill-config": "^6.4.1"
|
|
44
43
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { LocalTokenCacheProvider } from '../types/LocalTokenCacheProvider.js';
|
|
2
|
-
/**
|
|
3
|
-
* This class is responsible to read and store tokens in a key ring provided by operating system.
|
|
4
|
-
*/
|
|
5
|
-
export declare class KeyRingLocalTokenCache implements LocalTokenCacheProvider {
|
|
6
|
-
private readonly service;
|
|
7
|
-
private readonly key;
|
|
8
|
-
private readonly entry;
|
|
9
|
-
constructor(service: string, key: string);
|
|
10
|
-
get(): string | undefined;
|
|
11
|
-
set(value: string): void;
|
|
12
|
-
delete(): void;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=KeyRingLocalTokenCache.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"KeyRingLocalTokenCache.d.ts","sourceRoot":"","sources":["../../src/authentication/KeyRingLocalTokenCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAGnF;;GAEG;AACH,qBAAa,sBAAuB,YAAW,uBAAuB;IAIlE,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAJtB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;gBAGX,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM;IAK9B,GAAG;IAiBH,GAAG,CAAC,KAAK,EAAE,MAAM;IAIjB,MAAM;CAOP"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Entry } from '@napi-rs/keyring';
|
|
2
|
-
/**
|
|
3
|
-
* This class is responsible to read and store tokens in a key ring provided by operating system.
|
|
4
|
-
*/
|
|
5
|
-
export class KeyRingLocalTokenCache {
|
|
6
|
-
constructor(service, key) {
|
|
7
|
-
this.service = service;
|
|
8
|
-
this.key = key;
|
|
9
|
-
this.entry = new Entry(service, key);
|
|
10
|
-
}
|
|
11
|
-
get() {
|
|
12
|
-
try {
|
|
13
|
-
const result = this.entry.getPassword();
|
|
14
|
-
console.debug(`KeyRingLocalTokenCache.get service:${this.service} key:${this.key} result:${result}`);
|
|
15
|
-
if (!result) {
|
|
16
|
-
return undefined;
|
|
17
|
-
}
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
catch {
|
|
21
|
-
// If the entry does not exist getPassword might throw an error, return undefined.
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
set(value) {
|
|
26
|
-
this.entry.setPassword(value);
|
|
27
|
-
}
|
|
28
|
-
delete() {
|
|
29
|
-
try {
|
|
30
|
-
this.entry.deletePassword();
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
// If the entry does not exist deletePassword might throw an error, do nothing.
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=KeyRingLocalTokenCache.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"KeyRingLocalTokenCache.js","sourceRoot":"","sources":["../../src/authentication/KeyRingLocalTokenCache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,sBAAsB;IAGjC,YACmB,OAAe,EACf,GAAW;QADX,YAAO,GAAP,OAAO,CAAQ;QACf,QAAG,GAAH,GAAG,CAAQ;QAE5B,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IACvC,CAAC;IAED,GAAG;QACD,IAAI;YACF,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;YAExC,OAAO,CAAC,KAAK,CAAC,sCAAsC,IAAI,CAAC,OAAO,QAAQ,IAAI,CAAC,GAAG,WAAW,MAAM,EAAE,CAAC,CAAC;YAErG,IAAI,CAAC,MAAM,EAAE;gBACX,OAAO,SAAS,CAAC;aAClB;YAED,OAAO,MAAM,CAAC;SACf;QAAC,MAAM;YACN,kFAAkF;YAClF,OAAO,SAAS,CAAC;SAClB;IACH,CAAC;IAED,GAAG,CAAC,KAAa;QACf,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;IAED,MAAM;QACJ,IAAI;YACF,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC;SAC7B;QAAC,MAAM;YACN,+EAA+E;SAChF;IACH,CAAC;CACF","sourcesContent":["import type { LocalTokenCacheProvider } from '../types/LocalTokenCacheProvider.js';\nimport { Entry } from '@napi-rs/keyring';\n\n/**\n * This class is responsible to read and store tokens in a key ring provided by operating system.\n */\nexport class KeyRingLocalTokenCache implements LocalTokenCacheProvider {\n private readonly entry: Entry;\n\n constructor(\n private readonly service: string,\n private readonly key: string,\n ) {\n this.entry = new Entry(service, key);\n }\n\n get() {\n try {\n const result = this.entry.getPassword();\n\n console.debug(`KeyRingLocalTokenCache.get service:${this.service} key:${this.key} result:${result}`);\n\n if (!result) {\n return undefined;\n }\n\n return result;\n } catch {\n // If the entry does not exist getPassword might throw an error, return undefined.\n return undefined;\n }\n }\n\n set(value: string) {\n this.entry.setPassword(value);\n }\n\n delete() {\n try {\n this.entry.deletePassword();\n } catch {\n // If the entry does not exist deletePassword might throw an error, do nothing.\n }\n }\n}\n"]}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { ConnectionStringOptions } from '../types/ConnectionStringOptions.js';
|
|
2
|
-
export declare function acquireSasToken({ storageAccount: account, container, permissions, loginMethod, tokenExpiresInMs, }: ConnectionStringOptions): Promise<string>;
|
|
3
|
-
//# sourceMappingURL=acquireSasToken.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"acquireSasToken.d.ts","sourceRoot":"","sources":["../../src/authentication/acquireSasToken.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAInF,wBAAsB,eAAe,CAAC,EACpC,cAAc,EAAE,OAAO,EACvB,SAAS,EACT,WAAW,EACX,WAAW,EACX,gBAAgB,GACjB,EAAE,uBAAuB,mBAgCzB"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { BlobServiceClient, ContainerSASPermissions, SASProtocol, generateBlobSASQueryParameters, } from '@azure/storage-blob';
|
|
2
|
-
import { createBlobStorageUrl } from './createBlobStorageUrl.js';
|
|
3
|
-
import { getCredential } from './getCredential.js';
|
|
4
|
-
export async function acquireSasToken({ storageAccount: account, container, permissions, loginMethod, tokenExpiresInMs, }) {
|
|
5
|
-
const credential = getCredential(loginMethod);
|
|
6
|
-
const blobStorage = new BlobServiceClient(createBlobStorageUrl(account), credential);
|
|
7
|
-
const containerClient = blobStorage.getContainerClient(container);
|
|
8
|
-
const startsOn = new Date(); // now
|
|
9
|
-
const hourInMs = 3600000;
|
|
10
|
-
const dayInMs = 24 * hourInMs;
|
|
11
|
-
const expiresInMs = 7 * dayInMs; // 7 days (maximum allowed by Azure)
|
|
12
|
-
if (tokenExpiresInMs && tokenExpiresInMs > expiresInMs) {
|
|
13
|
-
console.warn('Maximum allowed token expiration is 7 days. Using 7 days instead.');
|
|
14
|
-
tokenExpiresInMs = expiresInMs;
|
|
15
|
-
}
|
|
16
|
-
const expiresOn = new Date(startsOn.valueOf() + (tokenExpiresInMs ?? expiresInMs));
|
|
17
|
-
const userDelegationKey = await blobStorage.getUserDelegationKey(startsOn, expiresOn);
|
|
18
|
-
const sasQueryParams = generateBlobSASQueryParameters({
|
|
19
|
-
containerName: containerClient.containerName,
|
|
20
|
-
permissions: ContainerSASPermissions.from(permissions),
|
|
21
|
-
expiresOn,
|
|
22
|
-
startsOn,
|
|
23
|
-
protocol: SASProtocol.Https,
|
|
24
|
-
}, userDelegationKey, account);
|
|
25
|
-
return sasQueryParams.toString();
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=acquireSasToken.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"acquireSasToken.js","sourceRoot":"","sources":["../../src/authentication/acquireSasToken.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBA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;QACR,QAAQ,EAAE,WAAW,CAAC,KAAK;KAC5B,EACD,iBAAiB,EACjB,OAAO,CACR,CAAC;IAEF,OAAO,cAAc,CAAC,QAAQ,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import {\n BlobServiceClient,\n ContainerSASPermissions,\n SASProtocol,\n generateBlobSASQueryParameters,\n} from '@azure/storage-blob';\nimport type { ConnectionStringOptions } from '../types/ConnectionStringOptions.js';\nimport { createBlobStorageUrl } from './createBlobStorageUrl.js';\nimport { getCredential } from './getCredential.js';\n\nexport async function acquireSasToken({\n storageAccount: account,\n container,\n permissions,\n loginMethod,\n tokenExpiresInMs,\n}: ConnectionStringOptions) {\n const credential = getCredential(loginMethod);\n const blobStorage = new BlobServiceClient(createBlobStorageUrl(account), credential);\n const containerClient = blobStorage.getContainerClient(container);\n\n const startsOn = new Date(); // now\n const hourInMs = 3600000;\n const dayInMs = 24 * hourInMs;\n const expiresInMs = 7 * dayInMs; // 7 days (maximum allowed by Azure)\n\n if (tokenExpiresInMs && tokenExpiresInMs > expiresInMs) {\n console.warn('Maximum allowed token expiration is 7 days. Using 7 days instead.');\n tokenExpiresInMs = expiresInMs;\n }\n\n const expiresOn = new Date(startsOn.valueOf() + (tokenExpiresInMs ?? expiresInMs));\n\n const userDelegationKey = await blobStorage.getUserDelegationKey(startsOn, expiresOn);\n\n const sasQueryParams = generateBlobSASQueryParameters(\n {\n containerName: containerClient.containerName,\n permissions: ContainerSASPermissions.from(permissions),\n expiresOn,\n startsOn,\n protocol: SASProtocol.Https,\n },\n userDelegationKey,\n account,\n );\n\n return sasQueryParams.toString();\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createBlobStorageUrl.d.ts","sourceRoot":"","sources":["../../src/authentication/createBlobStorageUrl.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,UAEnD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createBlobStorageUrl.js","sourceRoot":"","sources":["../../src/authentication/createBlobStorageUrl.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,oBAAoB,CAAC,OAAe;IAClD,OAAO,WAAW,OAAO,wBAAwB,CAAC;AACpD,CAAC","sourcesContent":["export function createBlobStorageUrl(account: string) {\n return `https://${account}.blob.core.windows.net`;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getAuthenticatedConnectionString.d.ts","sourceRoot":"","sources":["../../src/authentication/getAuthenticatedConnectionString.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAenF,wBAAsB,gCAAgC,CAAC,uBAAuB,EAAE,uBAAuB,mBAWtG"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { createBlobStorageUrl } from './createBlobStorageUrl.js';
|
|
2
|
-
import { getSasToken } from './getSasToken.js';
|
|
3
|
-
import { acquireSasToken } from './acquireSasToken.js';
|
|
4
|
-
import { isExpired } from './isExpired.js';
|
|
5
|
-
import { ContainerSASPermissions } from '@azure/storage-blob';
|
|
6
|
-
async function createLocalTokenCacheLazy({ storageAccount, container, permissions }) {
|
|
7
|
-
const { KeyRingLocalTokenCache } = await import('./KeyRingLocalTokenCache.js');
|
|
8
|
-
const service = `cloudpack-cache-${storageAccount}`;
|
|
9
|
-
const key = `container:${container};permission:${ContainerSASPermissions.from(permissions).toString()}`;
|
|
10
|
-
return new KeyRingLocalTokenCache(service, key);
|
|
11
|
-
}
|
|
12
|
-
export async function getAuthenticatedConnectionString(connectionStringOptions) {
|
|
13
|
-
// No need to cache tokens if the user is NOT running in interactive mode.
|
|
14
|
-
const tokenCache = connectionStringOptions.loginMethod == 'interactive' || connectionStringOptions.loginMethod == 'azure-cli'
|
|
15
|
-
? await createLocalTokenCacheLazy(connectionStringOptions)
|
|
16
|
-
: undefined;
|
|
17
|
-
const sasToken = await getSasToken({ connectionStringOptions }, { tokenCache, acquireSasToken, isExpired });
|
|
18
|
-
const { storageAccount } = connectionStringOptions;
|
|
19
|
-
return `BlobEndpoint=${createBlobStorageUrl(storageAccount)};SharedAccessSignature=${sasToken}`;
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=getAuthenticatedConnectionString.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getAuthenticatedConnectionString.js","sourceRoot":"","sources":["../../src/authentication/getAuthenticatedConnectionString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,KAAK,UAAU,yBAAyB,CAAC,EAAE,cAAc,EAAE,SAAS,EAAE,WAAW,EAA2B;IAC1G,MAAM,EAAE,sBAAsB,EAAE,GAAG,MAAM,MAAM,CAAC,6BAA6B,CAAC,CAAC;IAE/E,MAAM,OAAO,GAAG,mBAAmB,cAAc,EAAE,CAAC;IACpD,MAAM,GAAG,GAAG,aAAa,SAAS,eAAe,uBAAuB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;IAExG,OAAO,IAAI,sBAAsB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gCAAgC,CAAC,uBAAgD;IACrG,0EAA0E;IAC1E,MAAM,UAAU,GACd,uBAAuB,CAAC,WAAW,IAAI,aAAa,IAAI,uBAAuB,CAAC,WAAW,IAAI,WAAW;QACxG,CAAC,CAAC,MAAM,yBAAyB,CAAC,uBAAuB,CAAC;QAC1D,CAAC,CAAC,SAAS,CAAC;IAEhB,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,EAAE,uBAAuB,EAAE,EAAE,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC,CAAC;IAE5G,MAAM,EAAE,cAAc,EAAE,GAAG,uBAAuB,CAAC;IACnD,OAAO,gBAAgB,oBAAoB,CAAC,cAAc,CAAC,0BAA0B,QAAQ,EAAE,CAAC;AAClG,CAAC","sourcesContent":["import { createBlobStorageUrl } from './createBlobStorageUrl.js';\nimport type { ConnectionStringOptions } from '../types/ConnectionStringOptions.js';\nimport { getSasToken } from './getSasToken.js';\nimport { acquireSasToken } from './acquireSasToken.js';\nimport { isExpired } from './isExpired.js';\nimport { ContainerSASPermissions } from '@azure/storage-blob';\n\nasync function createLocalTokenCacheLazy({ storageAccount, container, permissions }: ConnectionStringOptions) {\n const { KeyRingLocalTokenCache } = await import('./KeyRingLocalTokenCache.js');\n\n const service = `cloudpack-cache-${storageAccount}`;\n const key = `container:${container};permission:${ContainerSASPermissions.from(permissions).toString()}`;\n\n return new KeyRingLocalTokenCache(service, key);\n}\n\nexport async function getAuthenticatedConnectionString(connectionStringOptions: ConnectionStringOptions) {\n // No need to cache tokens if the user is NOT running in interactive mode.\n const tokenCache =\n connectionStringOptions.loginMethod == 'interactive' || connectionStringOptions.loginMethod == 'azure-cli'\n ? await createLocalTokenCacheLazy(connectionStringOptions)\n : undefined;\n\n const sasToken = await getSasToken({ connectionStringOptions }, { tokenCache, acquireSasToken, isExpired });\n\n const { storageAccount } = connectionStringOptions;\n return `BlobEndpoint=${createBlobStorageUrl(storageAccount)};SharedAccessSignature=${sasToken}`;\n}\n"]}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { LocalTokenCacheProvider } from '../types/LocalTokenCacheProvider.js';
|
|
2
|
-
import type { ConnectionStringOptions } from '../types/ConnectionStringOptions.js';
|
|
3
|
-
export interface GetSasTokenOptions {
|
|
4
|
-
connectionStringOptions: ConnectionStringOptions;
|
|
5
|
-
}
|
|
6
|
-
export interface GetSasTokenDependencies {
|
|
7
|
-
tokenCache?: LocalTokenCacheProvider;
|
|
8
|
-
acquireSasToken: (options: ConnectionStringOptions) => Promise<string>;
|
|
9
|
-
isExpired: (token: string) => boolean;
|
|
10
|
-
}
|
|
11
|
-
export declare function getSasToken({ connectionStringOptions }: GetSasTokenOptions, { tokenCache, acquireSasToken, isExpired }: GetSasTokenDependencies): Promise<string>;
|
|
12
|
-
//# sourceMappingURL=getSasToken.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getSasToken.d.ts","sourceRoot":"","sources":["../../src/authentication/getSasToken.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAEnF,MAAM,WAAW,kBAAkB;IACjC,uBAAuB,EAAE,uBAAuB,CAAC;CAClD;AAED,MAAM,WAAW,uBAAuB;IACtC,UAAU,CAAC,EAAE,uBAAuB,CAAC;IACrC,eAAe,EAAE,CAAC,OAAO,EAAE,uBAAuB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACvE,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;CACvC;AAED,wBAAsB,WAAW,CAC/B,EAAE,uBAAuB,EAAE,EAAE,kBAAkB,EAC/C,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,EAAE,EAAE,uBAAuB,mBAepE"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export async function getSasToken({ connectionStringOptions }, { tokenCache, acquireSasToken, isExpired }) {
|
|
2
|
-
try {
|
|
3
|
-
const localToken = tokenCache?.get();
|
|
4
|
-
if (localToken && !isExpired(localToken)) {
|
|
5
|
-
return localToken;
|
|
6
|
-
}
|
|
7
|
-
const token = await acquireSasToken(connectionStringOptions);
|
|
8
|
-
tokenCache?.set(token);
|
|
9
|
-
return token;
|
|
10
|
-
}
|
|
11
|
-
catch (error) {
|
|
12
|
-
console.error(`Failed to get SAS token for storage account.`, error);
|
|
13
|
-
throw error;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=getSasToken.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getSasToken.js","sourceRoot":"","sources":["../../src/authentication/getSasToken.ts"],"names":[],"mappings":"AAaA,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,EAAE,uBAAuB,EAAsB,EAC/C,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,EAA2B;IAEnE,IAAI;QACF,MAAM,UAAU,GAAG,UAAU,EAAE,GAAG,EAAE,CAAC;QACrC,IAAI,UAAU,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE;YACxC,OAAO,UAAU,CAAC;SACnB;QAED,MAAM,KAAK,GAAG,MAAM,eAAe,CAAC,uBAAuB,CAAC,CAAC;QAC7D,UAAU,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;QACvB,OAAO,KAAK,CAAC;KACd;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,8CAA8C,EAAE,KAAK,CAAC,CAAC;QACrE,MAAM,KAAK,CAAC;KACb;AACH,CAAC","sourcesContent":["import type { LocalTokenCacheProvider } from '../types/LocalTokenCacheProvider.js';\nimport type { ConnectionStringOptions } from '../types/ConnectionStringOptions.js';\n\nexport interface GetSasTokenOptions {\n connectionStringOptions: ConnectionStringOptions;\n}\n\nexport interface GetSasTokenDependencies {\n tokenCache?: LocalTokenCacheProvider;\n acquireSasToken: (options: ConnectionStringOptions) => Promise<string>;\n isExpired: (token: string) => boolean;\n}\n\nexport async function getSasToken(\n { connectionStringOptions }: GetSasTokenOptions,\n { tokenCache, acquireSasToken, isExpired }: GetSasTokenDependencies,\n) {\n try {\n const localToken = tokenCache?.get();\n if (localToken && !isExpired(localToken)) {\n return localToken;\n }\n\n const token = await acquireSasToken(connectionStringOptions);\n tokenCache?.set(token);\n return token;\n } catch (error) {\n console.error(`Failed to get SAS token for storage account.`, error);\n throw error;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isExpired.d.ts","sourceRoot":"","sources":["../../src/authentication/isExpired.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,WAQzC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isExpired.js","sourceRoot":"","sources":["../../src/authentication/isExpired.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,SAAS,CAAC,QAAgB;IACxC,MAAM,EAAE,GAAG,IAAI,eAAe,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACnD,IAAI,CAAC,EAAE,EAAE;QACP,OAAO,IAAI,CAAC;KACb;IACD,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC;IAC5B,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,OAAO,MAAM,GAAG,GAAG,CAAC;AACtB,CAAC","sourcesContent":["export function isExpired(sasToken: string) {\n const se = new URLSearchParams(sasToken).get('se');\n if (!se) {\n return true;\n }\n const expiry = new Date(se);\n const now = new Date();\n return expiry < now;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cache-persistance/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGtD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,eAAO,MAAM,sBAAsB,EAAE,cAGpC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cache-persistance/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,MAAM,CAAC,MAAM,sBAAsB,GAAmB,CAAC,OAAO,EAAE,EAAE;IAChE,6IAA6I;IAC5I,OAAe,CAAC,kBAAkB,CAAC,cAAc,CAAC,4BAA4B,CAAC,CAAC;AACnF,CAAC,CAAC","sourcesContent":["/**\n * This file is a fork of https://github.com/altinokdarici/azure-sdk-for-js/tree/main/sdk/identity/identity-cache-persistence\n */\n\n// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n// import { AzurePluginContext } from '../../identity/src/plugins/provider';\nimport type { IdentityPlugin } from '@azure/identity';\nimport { createPersistenceCachePlugin } from './provider.js';\n\n/**\n * A plugin that provides persistent token caching for `@azure/identity`\n * credentials. The plugin API is compatible with `@azure/identity` versions\n * 2.0.0 and later. Load this plugin using the `useIdentityPlugin`\n * function, imported from `@azure/identity`.\n *\n * In order to enable this functionality, you must also pass\n * `tokenCachePersistenceOptions` to your credential constructors with an\n * `enabled` property set to true.\n *\n * Example:\n *\n * ```javascript\n * import { useIdentityPlugin, DeviceCodeCredential } from \"@azure/identity\";\n * import { cachePersistencePlugin } from \"@azure/identity-cache-persistence\";\n *\n * // Load the plugin\n * useIdentityPlugin(cachePersistencePlugin);\n *\n * const credential = new DeviceCodeCredential({\n * tokenCachePersistenceOptions: {\n * enabled: true\n * }\n * });\n * ```\n */\n\nexport const cachePersistencePlugin: IdentityPlugin = (context) => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n (context as any).cachePluginControl.setPersistence(createPersistenceCachePlugin);\n};\n"]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { LoginMethod } from './LoginMethod.js';
|
|
2
|
-
export interface ConnectionStringOptions {
|
|
3
|
-
storageAccount: string;
|
|
4
|
-
container: string;
|
|
5
|
-
permissions: {
|
|
6
|
-
read: boolean;
|
|
7
|
-
write: boolean;
|
|
8
|
-
list: boolean;
|
|
9
|
-
};
|
|
10
|
-
tokenExpiresInMs?: number;
|
|
11
|
-
loginMethod: LoginMethod;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=ConnectionStringOptions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionStringOptions.d.ts","sourceRoot":"","sources":["../../src/types/ConnectionStringOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,MAAM,WAAW,uBAAuB;IACtC,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE;QACX,IAAI,EAAE,OAAO,CAAC;QACd,KAAK,EAAE,OAAO,CAAC;QACf,IAAI,EAAE,OAAO,CAAC;KACf,CAAC;IACF,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,WAAW,CAAC;CAC1B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionStringOptions.js","sourceRoot":"","sources":["../../src/types/ConnectionStringOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { LoginMethod } from './LoginMethod.js';\n\nexport interface ConnectionStringOptions {\n storageAccount: string;\n container: string;\n permissions: {\n read: boolean;\n write: boolean;\n list: boolean;\n };\n tokenExpiresInMs?: number;\n loginMethod: LoginMethod;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LocalTokenCacheProvider.d.ts","sourceRoot":"","sources":["../../src/types/LocalTokenCacheProvider.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,uBAAuB;IACtC,GAAG,IAAI,MAAM,GAAG,SAAS,CAAC;IAC1B,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,MAAM,IAAI,IAAI,CAAC;CAChB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LocalTokenCacheProvider.js","sourceRoot":"","sources":["../../src/types/LocalTokenCacheProvider.ts"],"names":[],"mappings":"","sourcesContent":["export interface LocalTokenCacheProvider {\n get(): string | undefined;\n set(value: string): void;\n delete(): void;\n}\n"]}
|