@ms-cloudpack/remote-cache 0.5.1-beta.2 → 0.5.2
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.map +1 -0
- package/lib/AzureRemoteCacheClient.js +51 -0
- package/lib/AzureRemoteCacheClient.js.map +1 -0
- package/lib/Task.d.ts.map +1 -0
- package/lib/Task.js +2 -0
- package/lib/Task.js.map +1 -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.map +1 -0
- package/lib/authentication/getAuthenticationRecordPath.js +10 -0
- package/lib/authentication/getAuthenticationRecordPath.js.map +1 -0
- package/lib/authentication/getCredential.d.ts.map +1 -0
- package/lib/authentication/getCredential.js +61 -0
- package/lib/authentication/getCredential.js.map +1 -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/cachePersistencePlugin.d.ts.map +1 -0
- package/lib/cache-persistance/cachePersistencePlugin.js +35 -0
- package/lib/cache-persistance/cachePersistencePlugin.js.map +1 -0
- package/lib/cache-persistance/platforms.d.ts.map +1 -0
- package/lib/cache-persistance/platforms.js +109 -0
- package/lib/cache-persistance/platforms.js.map +1 -0
- package/lib/cache-persistance/provider.d.ts.map +1 -0
- package/lib/cache-persistance/provider.js +26 -0
- package/lib/cache-persistance/provider.js.map +1 -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.map +1 -0
- package/lib/createRemoteCacheClient.js +27 -0
- package/lib/createRemoteCacheClient.js.map +1 -0
- package/lib/decorators/InMemoryDecorator.d.ts.map +1 -0
- package/lib/decorators/InMemoryDecorator.js +29 -0
- package/lib/decorators/InMemoryDecorator.js.map +1 -0
- package/lib/decorators/ReporterDecorator.d.ts +1 -1
- package/lib/decorators/ReporterDecorator.d.ts.map +1 -0
- package/lib/decorators/ReporterDecorator.js +126 -0
- package/lib/decorators/ReporterDecorator.js.map +1 -0
- package/lib/decorators/RetryDecorator.d.ts.map +1 -0
- package/lib/decorators/RetryDecorator.js +27 -0
- package/lib/decorators/RetryDecorator.js.map +1 -0
- package/lib/getListOfBlobs.d.ts.map +1 -0
- package/lib/getListOfBlobs.js +15 -0
- package/lib/getListOfBlobs.js.map +1 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/lib/retry/blockListIsInvalidRetryPolicy.d.ts.map +1 -0
- package/lib/retry/blockListIsInvalidRetryPolicy.js +8 -0
- package/lib/retry/blockListIsInvalidRetryPolicy.js.map +1 -0
- package/lib/tsdoc-metadata.json +11 -0
- package/lib/types/LoginMethod.d.ts.map +1 -0
- package/lib/types/LoginMethod.js +2 -0
- package/lib/types/LoginMethod.js.map +1 -0
- package/lib/types/RemoteCacheClient.d.ts.map +1 -0
- package/lib/types/RemoteCacheClient.js +2 -0
- package/lib/types/RemoteCacheClient.js.map +1 -0
- package/lib/types/RemoteCacheClientOptions.d.ts.map +1 -0
- package/lib/types/RemoteCacheClientOptions.js +2 -0
- package/lib/types/RemoteCacheClientOptions.js.map +1 -0
- package/lib/types/RetryPolicy.d.ts.map +1 -0
- package/lib/types/RetryPolicy.js +2 -0
- package/lib/types/RetryPolicy.js.map +1 -0
- package/package.json +13 -14
- package/dist/AzureRemoteCacheClient-AE2VSZ7M.js +0 -52517
- package/dist/ReporterDecorator-IPB43LAC.js +0 -127
- package/dist/chunk-7DWZ2KJB.js +0 -49702
- package/dist/chunk-IG2LEA6S.js +0 -185
- package/dist/chunk-N2VHZU53.js +0 -63
- package/dist/chunk-X5NZ4TUB.js +0 -1075
- package/dist/chunk-YE3TMZ3A.js +0 -13
- package/dist/getCredential-63JEO57N.js +0 -24180
- package/dist/getListOfBlobs-BZCK6WJA.js +0 -27
- package/dist/index.js +0 -103
- package/lib/decorators/InMemoryDecorator.test.d.ts +0 -2
- package/lib/decorators/RetryDecorator.test.d.ts +0 -2
|
@@ -0,0 +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,uCAAuC,EACxC,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,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,uCAAuC;IASrF;;;;;OAKG;IACG,cAAc,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,iCAAiC;CAYrE"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { makeLogger, put, fetch } from 'backfill/lib/api.js';
|
|
2
|
+
import { existsSync } from 'fs';
|
|
3
|
+
import { createBlobStorageUrl } from './createBlobStorageUrl.js';
|
|
4
|
+
export class AzureRemoteCacheClient {
|
|
5
|
+
constructor({ container, storageAccount, credential }) {
|
|
6
|
+
this.logger = makeLogger('mute', process.stdout, process.stderr);
|
|
7
|
+
this.config = {
|
|
8
|
+
incrementalCaching: true,
|
|
9
|
+
internalCacheFolder: '', // not used by azure-blob
|
|
10
|
+
cacheStorageConfig: {
|
|
11
|
+
provider: 'azure-blob',
|
|
12
|
+
options: {
|
|
13
|
+
connectionString: createBlobStorageUrl(storageAccount),
|
|
14
|
+
credential,
|
|
15
|
+
container,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Uploads the folder to the remote cache.
|
|
22
|
+
* @param id - The unique identifier of the asset to upload.
|
|
23
|
+
* @param path - The path to the folder to upload.
|
|
24
|
+
* @param globMatches - The glob pattern to use when uploading the folder.
|
|
25
|
+
* @returns - A promise that resolves when the folder has been uploaded.
|
|
26
|
+
*/
|
|
27
|
+
async uploadFolder({ id, path, globMatches }) {
|
|
28
|
+
if (!existsSync(path)) {
|
|
29
|
+
return 'not-found';
|
|
30
|
+
}
|
|
31
|
+
await put(path, id, this.logger, { ...this.config, outputGlob: globMatches });
|
|
32
|
+
return 'success';
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Downloads the folder from the remote cache.
|
|
36
|
+
* @param id - The unique identifier of the asset to download.
|
|
37
|
+
* @param path - The path to download the folder to.
|
|
38
|
+
* @returns - A promise that resolves when the folder has been downloaded.
|
|
39
|
+
*/
|
|
40
|
+
async downloadFolder({ id, path }) {
|
|
41
|
+
if (existsSync(path)) {
|
|
42
|
+
return 'already-exist';
|
|
43
|
+
}
|
|
44
|
+
const result = await fetch(path, id, this.logger, this.config);
|
|
45
|
+
if (!result) {
|
|
46
|
+
return 'not-found';
|
|
47
|
+
}
|
|
48
|
+
return 'success';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=AzureRemoteCacheClient.js.map
|
|
@@ -0,0 +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,MAAM,IAAI,CAAC;AAMhC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,MAAM,OAAO,sBAAsB;IAQjC,YAAY,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAA4B;QAP9D,WAAM,GAAG,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QAQ3E,IAAI,CAAC,MAAM,GAAG;YACZ,kBAAkB,EAAE,IAAI;YACxB,mBAAmB,EAAE,EAAE,EAAE,yBAAyB;YAClD,kBAAkB,EAAE;gBAClB,QAAQ,EAAE,YAAY;gBACtB,OAAO,EAAE;oBACP,gBAAgB,EAAE,oBAAoB,CAAC,cAAc,CAAC;oBACtD,UAAU;oBACV,SAAS;iBACV;aACF;SACF,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,YAAY,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,WAAW,EAA2C;QACnF,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACtB,OAAO,WAAW,CAAC;QACrB,CAAC;QAED,MAAM,GAAG,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;QAC9E,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,cAAc,CAAC,EAAE,EAAE,EAAE,IAAI,EAAqC;QAClE,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACrB,OAAO,eAAe,CAAC;QACzB,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAC/D,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 RemoteCacheClientUploadOperationOptions,\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 id - The unique identifier of the asset 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({ id, path, globMatches }: RemoteCacheClientUploadOperationOptions) {\n if (!existsSync(path)) {\n return 'not-found';\n }\n\n await put(path, id, this.logger, { ...this.config, outputGlob: globMatches });\n return 'success';\n }\n\n /**\n * Downloads the folder from the remote cache.\n * @param id - The unique identifier of the asset 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({ id, path }: RemoteCacheClientOperationOptions) {\n if (existsSync(path)) {\n return 'already-exist';\n }\n\n const result = await fetch(path, id, this.logger, this.config);\n if (!result) {\n return 'not-found';\n }\n\n return 'success';\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Task.d.ts","sourceRoot":"","sources":["../src/Task.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAE1E,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,OAAO,CAAC,sBAAsB,CAAC,CAAC;CAChD"}
|
package/lib/Task.js
ADDED
package/lib/Task.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Task.js","sourceRoot":"","sources":["../src/Task.ts"],"names":[],"mappings":"","sourcesContent":["import type { TaskReporterTaskResult } from '@ms-cloudpack/task-reporter';\n\nexport interface Task {\n name: string;\n execute: () => Promise<TaskReporterTaskResult>;\n}\n"]}
|
|
@@ -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 @@
|
|
|
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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCredential.d.ts","sourceRoot":"","sources":["../../src/authentication/getCredential.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,eAAe,EACrB,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,4BAwC9E"}
|
|
@@ -0,0 +1,61 @@
|
|
|
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) {
|
|
10
|
+
switch (loginMethod) {
|
|
11
|
+
case 'interactive':
|
|
12
|
+
return new InteractiveBrowserCredential({
|
|
13
|
+
redirectUri: 'http://localhost:1337',
|
|
14
|
+
authenticationRecord,
|
|
15
|
+
tokenCachePersistenceOptions,
|
|
16
|
+
});
|
|
17
|
+
case 'device-code':
|
|
18
|
+
return new DeviceCodeCredential({
|
|
19
|
+
authenticationRecord,
|
|
20
|
+
tokenCachePersistenceOptions,
|
|
21
|
+
});
|
|
22
|
+
default:
|
|
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
|
+
const storageScope = 'https://storage.azure.com/.default';
|
|
45
|
+
authenticationRecord = await credential.authenticate(storageScope);
|
|
46
|
+
const token = await credential.getToken(storageScope);
|
|
47
|
+
// Creating a custom credential with the token from the authentication record.
|
|
48
|
+
// This ensures that we can use the token without having to authenticate again. Otherwise, we may have to authenticate again to get the token which can create concurrency issues.
|
|
49
|
+
const storageCustomCredential = {
|
|
50
|
+
getToken: async () => {
|
|
51
|
+
return Promise.resolve(token);
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
if (authenticationRecord) {
|
|
55
|
+
saveAuthenticationRecord(cachePath, authenticationRecord);
|
|
56
|
+
}
|
|
57
|
+
return storageCustomCredential;
|
|
58
|
+
}
|
|
59
|
+
return credential;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=getCredential.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCredential.js","sourceRoot":"","sources":["../../src/authentication/getCredential.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,4BAA4B,EAC5B,iBAAiB,GAIlB,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,MAAM,YAAY,GAAG,oCAAoC,CAAC;QAC1D,oBAAoB,GAAG,MAAM,UAAU,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QACnE,MAAM,KAAK,GAAG,MAAM,UAAU,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QAEtD,8EAA8E;QAC9E,kLAAkL;QAClL,MAAM,uBAAuB,GAAoB;YAC/C,QAAQ,EAAE,KAAK,IAAI,EAAE;gBACnB,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAChC,CAAC;SACF,CAAC;QAEF,IAAI,oBAAoB,EAAE,CAAC;YACzB,wBAAwB,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,uBAAuB,CAAC;IACjC,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import {\n AzureCliCredential,\n DeviceCodeCredential,\n InteractiveBrowserCredential,\n useIdentityPlugin,\n type AuthenticationRecord,\n type TokenCachePersistenceOptions,\n type TokenCredential,\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 const storageScope = 'https://storage.azure.com/.default';\n authenticationRecord = await credential.authenticate(storageScope);\n const token = await credential.getToken(storageScope);\n\n // Creating a custom credential with the token from the authentication record.\n // This ensures that we can use the token without having to authenticate again. Otherwise, we may have to authenticate again to get the token which can create concurrency issues.\n const storageCustomCredential: TokenCredential = {\n getToken: async () => {\n return Promise.resolve(token);\n },\n };\n\n if (authenticationRecord) {\n saveAuthenticationRecord(cachePath, authenticationRecord);\n }\n\n return storageCustomCredential;\n }\n\n return credential;\n}\n"]}
|
|
@@ -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"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is a fork of https://github.com/altinokdarici/azure-sdk-for-js/tree/main/sdk/identity/identity-cache-persistence
|
|
3
|
+
*/
|
|
4
|
+
import { createPersistenceCachePlugin } from './provider.js';
|
|
5
|
+
/**
|
|
6
|
+
* A plugin that provides persistent token caching for `@azure/identity`
|
|
7
|
+
* credentials. The plugin API is compatible with `@azure/identity` versions
|
|
8
|
+
* 2.0.0 and later. Load this plugin using the `useIdentityPlugin`
|
|
9
|
+
* function, imported from `@azure/identity`.
|
|
10
|
+
*
|
|
11
|
+
* In order to enable this functionality, you must also pass
|
|
12
|
+
* `tokenCachePersistenceOptions` to your credential constructors with an
|
|
13
|
+
* `enabled` property set to true.
|
|
14
|
+
*
|
|
15
|
+
* Example:
|
|
16
|
+
*
|
|
17
|
+
* ```javascript
|
|
18
|
+
* import { useIdentityPlugin, DeviceCodeCredential } from "@azure/identity";
|
|
19
|
+
* import { cachePersistencePlugin } from "@azure/identity-cache-persistence";
|
|
20
|
+
*
|
|
21
|
+
* // Load the plugin
|
|
22
|
+
* useIdentityPlugin(cachePersistencePlugin);
|
|
23
|
+
*
|
|
24
|
+
* const credential = new DeviceCodeCredential({
|
|
25
|
+
* tokenCachePersistenceOptions: {
|
|
26
|
+
* enabled: true
|
|
27
|
+
* }
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export const cachePersistencePlugin = (context) => {
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
|
|
33
|
+
context.cachePluginControl.setPersistence(createPersistenceCachePlugin);
|
|
34
|
+
};
|
|
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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platforms.d.ts","sourceRoot":"","sources":["../../src/cache-persistance/platforms.ts"],"names":[],"mappings":"AAAA;;GAEG;;AAKH,OAAO,EAML,KAAK,YAAY,IAAI,WAAW,EACjC,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAapE;;;GAGG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;CAwB7B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,4BAA4B,EAAE,SAAS,CAAC,CAAC;AAEnF;;;GAGG;AACH,KAAK,sBAAsB,GAAG,CAAC,OAAO,CAAC,EAAE,sBAAsB,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;AAazF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,wBAAwB,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CA2C7F,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is a fork of https://github.com/altinokdarici/azure-sdk-for-js/tree/main/sdk/identity/identity-cache-persistence
|
|
3
|
+
*/
|
|
4
|
+
// Copyright (c) Microsoft Corporation.
|
|
5
|
+
// Licensed under the MIT license.
|
|
6
|
+
import * as path from 'path';
|
|
7
|
+
import { DataProtectionScope, FilePersistence, FilePersistenceWithDataProtection, KeychainPersistence, LibSecretPersistence, } from '@azure/msal-node-extensions';
|
|
8
|
+
/**
|
|
9
|
+
* Local application data folder
|
|
10
|
+
* Expected values:
|
|
11
|
+
* - Darwin: '/Users/user/'
|
|
12
|
+
* - Windows 8+: 'C:\Users\user\AppData\Local'
|
|
13
|
+
* - Linux: '/home/user/.local/share'
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
17
|
+
const localApplicationDataFolder = process.env.APPDATA?.replace?.(/(.Roaming)*$/, '\\Local') ?? process.env.HOME;
|
|
18
|
+
/**
|
|
19
|
+
* Dictionary of values that we use as default as we discover, pick and enable the persistence layer.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export const defaultMsalValues = {
|
|
23
|
+
tokenCache: {
|
|
24
|
+
name: 'msal.cache',
|
|
25
|
+
// Expected values:
|
|
26
|
+
// - Darwin: '/Users/user/.IdentityService'
|
|
27
|
+
// - Windows 8+: 'C:\Users\user\AppData\Local\.IdentityService'
|
|
28
|
+
// - Linux: '/home/user/.IdentityService'
|
|
29
|
+
directory: path.join(localApplicationDataFolder, '.IdentityService'),
|
|
30
|
+
},
|
|
31
|
+
keyRing: {
|
|
32
|
+
label: 'MSALCache',
|
|
33
|
+
schema: 'msal.cache',
|
|
34
|
+
collection: 'default',
|
|
35
|
+
attributes: {
|
|
36
|
+
MsalClientID: 'Microsoft.Developer.IdentityService',
|
|
37
|
+
'Microsoft.Developer.IdentityService': '1.0.0.0',
|
|
38
|
+
},
|
|
39
|
+
service: 'Microsoft.Developer.IdentityService',
|
|
40
|
+
account: 'MSALCache',
|
|
41
|
+
},
|
|
42
|
+
keyChain: {
|
|
43
|
+
service: 'Microsoft.Developer.IdentityService',
|
|
44
|
+
account: 'MSALCache',
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Expected responses:
|
|
49
|
+
* - Darwin: '/Users/user/.IdentityService/<name>'
|
|
50
|
+
* - Windows 8+: 'C:\Users\user\AppData\Local\.IdentityService\<name>'
|
|
51
|
+
* - Linux: '/home/user/.IdentityService/<name>'
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
function getPersistencePath(name) {
|
|
55
|
+
return path.join(defaultMsalValues.tokenCache.directory, name);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Set of the platforms we attempt to deliver persistence on.
|
|
59
|
+
*
|
|
60
|
+
* - On Windows we use DPAPI.
|
|
61
|
+
* - 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.
|
|
62
|
+
* - On Linux, we try to use the system's Keyring, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.
|
|
63
|
+
*
|
|
64
|
+
* Other platforms _are not supported_ at this time.
|
|
65
|
+
*
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
export const msalPersistencePlatforms = {
|
|
69
|
+
win32: ({ name = defaultMsalValues.tokenCache.name } = {}) => FilePersistenceWithDataProtection.create(getPersistencePath(name), DataProtectionScope.CurrentUser),
|
|
70
|
+
darwin: async (options = {}) => {
|
|
71
|
+
const { name, unsafeAllowUnencryptedStorage } = options;
|
|
72
|
+
const { service, account } = defaultMsalValues.keyChain;
|
|
73
|
+
const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);
|
|
74
|
+
try {
|
|
75
|
+
const persistence = await KeychainPersistence.create(persistencePath, service, account);
|
|
76
|
+
// If we don't encounter an error when trying to read from the keychain, then we should be good to go.
|
|
77
|
+
await persistence.load();
|
|
78
|
+
return persistence;
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
// If we got an error while trying to read from the keyring,
|
|
82
|
+
// we will proceed only if the user has specified that unencrypted storage is allowed.
|
|
83
|
+
if (!unsafeAllowUnencryptedStorage) {
|
|
84
|
+
throw new Error('Unable to read from the macOS Keychain.');
|
|
85
|
+
}
|
|
86
|
+
return FilePersistence.create(persistencePath);
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
linux: async (options = {}) => {
|
|
90
|
+
const { name, unsafeAllowUnencryptedStorage } = options;
|
|
91
|
+
const { service, account } = defaultMsalValues.keyRing;
|
|
92
|
+
const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);
|
|
93
|
+
try {
|
|
94
|
+
const persistence = await LibSecretPersistence.create(persistencePath, service, account);
|
|
95
|
+
// If we don't encounter an error when trying to read from the keyring, then we should be good to go.
|
|
96
|
+
await persistence.load();
|
|
97
|
+
return persistence;
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
// If we got an error while trying to read from the keyring,
|
|
101
|
+
// we will proceed only if the user has specified that unencrypted storage is allowed.
|
|
102
|
+
if (!unsafeAllowUnencryptedStorage) {
|
|
103
|
+
throw new Error('Unable to read from the system keyring (libsecret).');
|
|
104
|
+
}
|
|
105
|
+
return FilePersistence.create(persistencePath);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=platforms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platforms.js","sourceRoot":"","sources":["../../src/cache-persistance/platforms.ts"],"names":[],"mappings":"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","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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/cache-persistance/provider.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAE7D,OAAO,KAAK,EAAE,YAAY,IAAI,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/E,OAAO,KAAK,EAAE,YAAY,IAAI,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpE;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,WAAW,CAAC,CAQ7F;AAED,wBAAsB,4BAA4B,CAAC,OAAO,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,WAAW,CAAC,CAOzG"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is a fork of https://github.com/altinokdarici/azure-sdk-for-js/tree/main/sdk/identity/identity-cache-persistence
|
|
3
|
+
*/
|
|
4
|
+
import { msalPersistencePlatforms } from './platforms.js';
|
|
5
|
+
import { PersistenceCachePlugin } from '@azure/msal-node-extensions';
|
|
6
|
+
/**
|
|
7
|
+
* This is used to gain access to the underlying Persistence instance, which we use for testing
|
|
8
|
+
*
|
|
9
|
+
* @returns a raw persistence instance
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export async function createPersistence(options) {
|
|
13
|
+
const persistence = await msalPersistencePlatforms[process.platform]?.(options);
|
|
14
|
+
if (persistence === undefined) {
|
|
15
|
+
throw new Error('no persistence providers are available on this platform');
|
|
16
|
+
}
|
|
17
|
+
return persistence;
|
|
18
|
+
}
|
|
19
|
+
export async function createPersistenceCachePlugin(options) {
|
|
20
|
+
const persistence = await createPersistence(options ?? {});
|
|
21
|
+
return new PersistenceCachePlugin(persistence, {
|
|
22
|
+
retryNumber: 100,
|
|
23
|
+
retryDelay: 50,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +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,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"]}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AzureRemoteCacheClient } from './AzureRemoteCacheClient.js';
|
|
2
|
+
import { InMemoryDecorator } from './decorators/InMemoryDecorator.js';
|
|
3
|
+
import { ReporterDecorator } from './decorators/ReporterDecorator.js';
|
|
4
|
+
import { getListOfBlobs } from './getListOfBlobs.js';
|
|
5
|
+
import { RetryDecorator } from './decorators/RetryDecorator.js';
|
|
6
|
+
import { blockListIsInvalidRetryPolicy } from './retry/blockListIsInvalidRetryPolicy.js';
|
|
7
|
+
import { RetryManager } from '@ms-cloudpack/retry';
|
|
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,
|
|
15
|
+
container,
|
|
16
|
+
credential,
|
|
17
|
+
};
|
|
18
|
+
const client = new ReporterDecorator(new RetryDecorator({
|
|
19
|
+
retryManager: new RetryManager([blockListIsInvalidRetryPolicy]),
|
|
20
|
+
cacheClient: new InMemoryDecorator({
|
|
21
|
+
cacheClient: new AzureRemoteCacheClient(remoteCacheClientOptions),
|
|
22
|
+
getList: () => getListOfBlobs(remoteCacheClientOptions),
|
|
23
|
+
}),
|
|
24
|
+
}), context);
|
|
25
|
+
return client;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=createRemoteCacheClient.js.map
|
|
@@ -0,0 +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,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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryDecorator.d.ts","sourceRoot":"","sources":["../../src/decorators/InMemoryDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,uCAAuC,EACvC,iCAAiC,EACjC,gCAAgC,EACjC,MAAM,+BAA+B,CAAC;AAEvC;;GAEG;AACH,qBAAa,iBAAkB,YAAW,iBAAiB;IACzD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAChD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAuB;gBAEhC,OAAO,EAAE;QAAE,WAAW,EAAE,iBAAiB,CAAC;QAAC,OAAO,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;KAAE;IAKtF,YAAY,CAAC,OAAO,EAAE,uCAAuC,GAAG,OAAO,CAAC,gCAAgC,CAAC;IAgBzG,cAAc,CAAC,OAAO,EAAE,iCAAiC,GAAG,OAAO,CAAC,gCAAgC,CAAC;CAQ5G"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A decorator for a RemoteCacheClient that keeps a list of remote resources locally.
|
|
3
|
+
*/
|
|
4
|
+
export class InMemoryDecorator {
|
|
5
|
+
constructor(options) {
|
|
6
|
+
this.cacheClient = options.cacheClient;
|
|
7
|
+
this.list = options.getList();
|
|
8
|
+
}
|
|
9
|
+
async uploadFolder(options) {
|
|
10
|
+
if ((await this.list).has(options.id)) {
|
|
11
|
+
// This resource already exists in the remote cache, no need to upload it again.
|
|
12
|
+
return 'already-exist';
|
|
13
|
+
}
|
|
14
|
+
const result = await this.cacheClient.uploadFolder(options);
|
|
15
|
+
if (result === 'success') {
|
|
16
|
+
// The upload is successful, add the resource to the list.
|
|
17
|
+
(await this.list).add(options.id);
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
async downloadFolder(options) {
|
|
22
|
+
if (!(await this.list).has(options.id)) {
|
|
23
|
+
// This resource doesn't exist in the remote cache, can't download it.
|
|
24
|
+
return 'not-found';
|
|
25
|
+
}
|
|
26
|
+
return this.cacheClient.downloadFolder(options);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=InMemoryDecorator.js.map
|
|
@@ -0,0 +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,OAAgD;QACjE,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;YACtC,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,EAAE,CAAC,CAAC;QACpC,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,EAAE,CAAC,EAAE,CAAC;YACvC,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 RemoteCacheClientUploadOperationOptions,\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: RemoteCacheClientUploadOperationOptions): Promise<RemoteCacheClientOperationResult> {\n if ((await this.list).has(options.id)) {\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.id);\n }\n\n return result;\n }\n\n async downloadFolder(options: RemoteCacheClientOperationOptions): Promise<RemoteCacheClientOperationResult> {\n if (!(await this.list).has(options.id)) {\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"]}
|
|
@@ -8,7 +8,7 @@ export declare class ReporterDecorator implements RemoteCacheClient {
|
|
|
8
8
|
reporter: TaskReporter;
|
|
9
9
|
telemetryClient: TelemetryClient;
|
|
10
10
|
});
|
|
11
|
-
private
|
|
11
|
+
private buildFailureResult;
|
|
12
12
|
uploadFolder(options: RemoteCacheClientUploadOperationOptions): Promise<RemoteCacheClientOperationResult>;
|
|
13
13
|
downloadFolder(options: RemoteCacheClientOperationOptions): Promise<RemoteCacheClientOperationResult>;
|
|
14
14
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReporterDecorator.d.ts","sourceRoot":"","sources":["../../src/decorators/ReporterDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,YAAY,EAA+B,MAAM,6BAA6B,CAAC;AAC3G,OAAO,KAAK,EACV,iBAAiB,EACjB,uCAAuC,EACvC,iCAAiC,EACjC,gCAAgC,EACjC,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAuB/D,qBAAa,iBAAkB,YAAW,iBAAiB;IAEvD,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBADP,MAAM,EAAE,iBAAiB,EACzB,OAAO,EAAE;QACxB,QAAQ,EAAE,YAAY,CAAC;QACvB,eAAe,EAAE,eAAe,CAAC;KAClC;IAGH,OAAO,CAAC,kBAAkB;IAuBpB,YAAY,CAAC,OAAO,EAAE,uCAAuC;IAgD7D,cAAc,CAAC,OAAO,EAAE,iCAAiC;CA+ChE"}
|