@azure/msal-node-extensions 1.0.0-alpha.12 → 1.0.0-alpha.13
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/CHANGELOG.json +261 -226
- package/CHANGELOG.md +111 -102
- package/LICENSE +21 -21
- package/README.md +192 -192
- package/binding.gyp +29 -29
- package/dist/msal-node-extensions.cjs.development.js.map +1 -1
- package/dist/msal-node-extensions.cjs.production.min.js.map +1 -1
- package/dist/msal-node-extensions.esm.js.map +1 -1
- package/package.json +64 -59
- package/src/dpapi-addon/Dpapi.ts +17 -17
- package/src/dpapi-addon/dpapi_addon.h +6 -6
- package/src/dpapi-addon/dpapi_not_supported.cpp +19 -19
- package/src/dpapi-addon/dpapi_win.cpp +114 -114
- package/src/dpapi-addon/main.cpp +32 -32
- package/src/error/PersistenceError.ts +101 -101
- package/src/index.ts +16 -16
- package/src/lock/CrossPlatformLock.ts +89 -89
- package/src/lock/CrossPlatformLockOptions.ts +15 -15
- package/src/persistence/BasePersistence.ts +41 -41
- package/src/persistence/DataProtectionScope.ts +20 -20
- package/src/persistence/FilePersistence.ts +140 -140
- package/src/persistence/FilePersistenceWithDataProtection.ts +92 -92
- package/src/persistence/IPersistence.ts +17 -17
- package/src/persistence/IPersistenceConfiguration.ts +14 -14
- package/src/persistence/KeychainPersistence.ts +86 -86
- package/src/persistence/LibSecretPersistence.ts +87 -87
- package/src/persistence/PersistenceCachePlugin.ts +106 -106
- package/src/persistence/PersistenceCreator.ts +73 -73
- package/src/utils/Constants.ts +62 -62
- package/src/utils/Environment.ts +99 -99
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Error thrown when trying to write MSAL cache to persistence.
|
|
8
|
-
*/
|
|
9
|
-
export class PersistenceError extends Error {
|
|
10
|
-
|
|
11
|
-
// Short string denoting error
|
|
12
|
-
errorCode: string;
|
|
13
|
-
// Detailed description of error
|
|
14
|
-
errorMessage: string;
|
|
15
|
-
|
|
16
|
-
constructor(errorCode: string, errorMessage: string) {
|
|
17
|
-
const errorString = errorMessage ? `${errorCode}: ${errorMessage}` : errorCode;
|
|
18
|
-
super(errorString);
|
|
19
|
-
Object.setPrototypeOf(this, PersistenceError.prototype);
|
|
20
|
-
|
|
21
|
-
this.errorCode = errorCode;
|
|
22
|
-
this.errorMessage = errorMessage;
|
|
23
|
-
this.name = "PersistenceError";
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Error thrown when trying to access the file system.
|
|
28
|
-
*/
|
|
29
|
-
static createFileSystemError(errorCode: string, errorMessage: string): PersistenceError {
|
|
30
|
-
return new PersistenceError(errorCode, errorMessage);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Error thrown when trying to write, load, or delete data from secret service on linux.
|
|
35
|
-
* Libsecret is used to access secret service.
|
|
36
|
-
*/
|
|
37
|
-
static createLibSecretError(errorMessage: string): PersistenceError {
|
|
38
|
-
return new PersistenceError("GnomeKeyringError", errorMessage);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Error thrown when trying to write, load, or delete data from keychain on macOs.
|
|
43
|
-
*/
|
|
44
|
-
static createKeychainPersistenceError(errorMessage: string): PersistenceError {
|
|
45
|
-
return new PersistenceError("KeychainError", errorMessage);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Error thrown when trying to encrypt or decrypt data using DPAPI on Windows.
|
|
50
|
-
*/
|
|
51
|
-
static createFilePersistenceWithDPAPIError(errorMessage: string): PersistenceError {
|
|
52
|
-
return new PersistenceError("DPAPIEncryptedFileError", errorMessage);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Error thrown when using the cross platform lock.
|
|
57
|
-
*/
|
|
58
|
-
static createCrossPlatformLockError(errorMessage: string): PersistenceError {
|
|
59
|
-
return new PersistenceError("CrossPlatformLockError", errorMessage);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Throw cache persistence error
|
|
64
|
-
*
|
|
65
|
-
* @param errorMessage string
|
|
66
|
-
* @returns PersistenceError
|
|
67
|
-
*/
|
|
68
|
-
static createCachePersistenceError(errorMessage: string): PersistenceError {
|
|
69
|
-
return new PersistenceError("CachePersistenceError", errorMessage);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Throw unsupported error
|
|
74
|
-
*
|
|
75
|
-
* @param errorMessage string
|
|
76
|
-
* @returns PersistenceError
|
|
77
|
-
*/
|
|
78
|
-
static createNotSupportedError(errorMessage: string): PersistenceError {
|
|
79
|
-
return new PersistenceError("NotSupportedError", errorMessage);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Throw persistence not verified error
|
|
84
|
-
*
|
|
85
|
-
* @param errorMessage string
|
|
86
|
-
* @returns PersistenceError
|
|
87
|
-
*/
|
|
88
|
-
static createPersistenceNotVerifiedError(errorMessage: string): PersistenceError {
|
|
89
|
-
return new PersistenceError("PersistenceNotVerifiedError", errorMessage);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Throw persistence creation validation error
|
|
94
|
-
*
|
|
95
|
-
* @param errorMessage string
|
|
96
|
-
* @returns PersistenceError
|
|
97
|
-
*/
|
|
98
|
-
static createPersistenceNotValidatedError(errorMessage: string): PersistenceError {
|
|
99
|
-
return new PersistenceError("PersistenceNotValidatedError", errorMessage);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Error thrown when trying to write MSAL cache to persistence.
|
|
8
|
+
*/
|
|
9
|
+
export class PersistenceError extends Error {
|
|
10
|
+
|
|
11
|
+
// Short string denoting error
|
|
12
|
+
errorCode: string;
|
|
13
|
+
// Detailed description of error
|
|
14
|
+
errorMessage: string;
|
|
15
|
+
|
|
16
|
+
constructor(errorCode: string, errorMessage: string) {
|
|
17
|
+
const errorString = errorMessage ? `${errorCode}: ${errorMessage}` : errorCode;
|
|
18
|
+
super(errorString);
|
|
19
|
+
Object.setPrototypeOf(this, PersistenceError.prototype);
|
|
20
|
+
|
|
21
|
+
this.errorCode = errorCode;
|
|
22
|
+
this.errorMessage = errorMessage;
|
|
23
|
+
this.name = "PersistenceError";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Error thrown when trying to access the file system.
|
|
28
|
+
*/
|
|
29
|
+
static createFileSystemError(errorCode: string, errorMessage: string): PersistenceError {
|
|
30
|
+
return new PersistenceError(errorCode, errorMessage);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Error thrown when trying to write, load, or delete data from secret service on linux.
|
|
35
|
+
* Libsecret is used to access secret service.
|
|
36
|
+
*/
|
|
37
|
+
static createLibSecretError(errorMessage: string): PersistenceError {
|
|
38
|
+
return new PersistenceError("GnomeKeyringError", errorMessage);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Error thrown when trying to write, load, or delete data from keychain on macOs.
|
|
43
|
+
*/
|
|
44
|
+
static createKeychainPersistenceError(errorMessage: string): PersistenceError {
|
|
45
|
+
return new PersistenceError("KeychainError", errorMessage);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Error thrown when trying to encrypt or decrypt data using DPAPI on Windows.
|
|
50
|
+
*/
|
|
51
|
+
static createFilePersistenceWithDPAPIError(errorMessage: string): PersistenceError {
|
|
52
|
+
return new PersistenceError("DPAPIEncryptedFileError", errorMessage);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Error thrown when using the cross platform lock.
|
|
57
|
+
*/
|
|
58
|
+
static createCrossPlatformLockError(errorMessage: string): PersistenceError {
|
|
59
|
+
return new PersistenceError("CrossPlatformLockError", errorMessage);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Throw cache persistence error
|
|
64
|
+
*
|
|
65
|
+
* @param errorMessage string
|
|
66
|
+
* @returns PersistenceError
|
|
67
|
+
*/
|
|
68
|
+
static createCachePersistenceError(errorMessage: string): PersistenceError {
|
|
69
|
+
return new PersistenceError("CachePersistenceError", errorMessage);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Throw unsupported error
|
|
74
|
+
*
|
|
75
|
+
* @param errorMessage string
|
|
76
|
+
* @returns PersistenceError
|
|
77
|
+
*/
|
|
78
|
+
static createNotSupportedError(errorMessage: string): PersistenceError {
|
|
79
|
+
return new PersistenceError("NotSupportedError", errorMessage);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Throw persistence not verified error
|
|
84
|
+
*
|
|
85
|
+
* @param errorMessage string
|
|
86
|
+
* @returns PersistenceError
|
|
87
|
+
*/
|
|
88
|
+
static createPersistenceNotVerifiedError(errorMessage: string): PersistenceError {
|
|
89
|
+
return new PersistenceError("PersistenceNotVerifiedError", errorMessage);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Throw persistence creation validation error
|
|
94
|
+
*
|
|
95
|
+
* @param errorMessage string
|
|
96
|
+
* @returns PersistenceError
|
|
97
|
+
*/
|
|
98
|
+
static createPersistenceNotValidatedError(errorMessage: string): PersistenceError {
|
|
99
|
+
return new PersistenceError("PersistenceNotValidatedError", errorMessage);
|
|
100
|
+
}
|
|
101
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export { PersistenceCachePlugin } from "./persistence/PersistenceCachePlugin";
|
|
7
|
-
export { FilePersistence } from "./persistence/FilePersistence";
|
|
8
|
-
export { FilePersistenceWithDataProtection } from "./persistence/FilePersistenceWithDataProtection";
|
|
9
|
-
export { DataProtectionScope } from "./persistence/DataProtectionScope";
|
|
10
|
-
export { KeychainPersistence } from "./persistence/KeychainPersistence";
|
|
11
|
-
export { LibSecretPersistence } from "./persistence/LibSecretPersistence";
|
|
12
|
-
export { IPersistence } from "./persistence/IPersistence";
|
|
13
|
-
export { CrossPlatformLockOptions } from "./lock/CrossPlatformLockOptions";
|
|
14
|
-
export { PersistenceCreator } from "./persistence/PersistenceCreator";
|
|
15
|
-
export { IPersistenceConfiguration } from "./persistence/IPersistenceConfiguration";
|
|
16
|
-
export { Environment } from "./utils/Environment";
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export { PersistenceCachePlugin } from "./persistence/PersistenceCachePlugin";
|
|
7
|
+
export { FilePersistence } from "./persistence/FilePersistence";
|
|
8
|
+
export { FilePersistenceWithDataProtection } from "./persistence/FilePersistenceWithDataProtection";
|
|
9
|
+
export { DataProtectionScope } from "./persistence/DataProtectionScope";
|
|
10
|
+
export { KeychainPersistence } from "./persistence/KeychainPersistence";
|
|
11
|
+
export { LibSecretPersistence } from "./persistence/LibSecretPersistence";
|
|
12
|
+
export { IPersistence } from "./persistence/IPersistence";
|
|
13
|
+
export { CrossPlatformLockOptions } from "./lock/CrossPlatformLockOptions";
|
|
14
|
+
export { PersistenceCreator } from "./persistence/PersistenceCreator";
|
|
15
|
+
export { IPersistenceConfiguration } from "./persistence/IPersistenceConfiguration";
|
|
16
|
+
export { Environment } from "./utils/Environment";
|
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { promises as fs } from "fs";
|
|
7
|
-
import { pid } from "process";
|
|
8
|
-
import { CrossPlatformLockOptions } from "./CrossPlatformLockOptions";
|
|
9
|
-
import { Constants } from "../utils/Constants";
|
|
10
|
-
import { PersistenceError } from "../error/PersistenceError";
|
|
11
|
-
import { Logger } from "@azure/msal-common";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Cross-process lock that works on all platforms.
|
|
15
|
-
*/
|
|
16
|
-
export class CrossPlatformLock {
|
|
17
|
-
|
|
18
|
-
private readonly lockFilePath: string;
|
|
19
|
-
private lockFileHandle: fs.FileHandle;
|
|
20
|
-
private readonly retryNumber: number;
|
|
21
|
-
private readonly retryDelay: number;
|
|
22
|
-
|
|
23
|
-
private logger: Logger;
|
|
24
|
-
|
|
25
|
-
constructor(lockFilePath: string, logger: Logger, lockOptions?: CrossPlatformLockOptions) {
|
|
26
|
-
this.lockFilePath = lockFilePath;
|
|
27
|
-
this.retryNumber = lockOptions ? lockOptions.retryNumber : 500;
|
|
28
|
-
this.retryDelay = lockOptions ? lockOptions.retryDelay : 100;
|
|
29
|
-
this.logger = logger;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Locks cache from read or writes by creating file with same path and name as
|
|
34
|
-
* cache file but with .lockfile extension. If another process has already created
|
|
35
|
-
* the lockfile, will back off and retry based on configuration settings set by CrossPlatformLockOptions
|
|
36
|
-
*/
|
|
37
|
-
public async lock(): Promise<void> {
|
|
38
|
-
for (let tryCount = 0; tryCount < this.retryNumber; tryCount++) {
|
|
39
|
-
try {
|
|
40
|
-
this.logger.info(`Pid ${pid} trying to acquire lock`);
|
|
41
|
-
this.lockFileHandle = await fs.open(this.lockFilePath, "wx+");
|
|
42
|
-
|
|
43
|
-
this.logger.info(`Pid ${pid} acquired lock`);
|
|
44
|
-
await this.lockFileHandle.write(pid.toString());
|
|
45
|
-
return;
|
|
46
|
-
} catch (err) {
|
|
47
|
-
if (err.code === Constants.EEXIST_ERROR || err.code === Constants.EPERM_ERROR) {
|
|
48
|
-
this.logger.info(err);
|
|
49
|
-
await this.sleep(this.retryDelay);
|
|
50
|
-
} else {
|
|
51
|
-
this.logger.error(`${pid} was not able to acquire lock. Ran into error: ${err.message}`);
|
|
52
|
-
throw PersistenceError.createCrossPlatformLockError(err.message);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
this.logger.error(`${pid} was not able to acquire lock. Exceeded amount of retries set in the options`);
|
|
57
|
-
throw PersistenceError.createCrossPlatformLockError(
|
|
58
|
-
"Not able to acquire lock. Exceeded amount of retries set in options");
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* unlocks cache file by deleting .lockfile.
|
|
63
|
-
*/
|
|
64
|
-
public async unlock(): Promise<void> {
|
|
65
|
-
try {
|
|
66
|
-
if(this.lockFileHandle){
|
|
67
|
-
// if we have a file handle to the .lockfile, delete lock file
|
|
68
|
-
await fs.unlink(this.lockFilePath);
|
|
69
|
-
await this.lockFileHandle.close();
|
|
70
|
-
this.logger.info("lockfile deleted");
|
|
71
|
-
} else {
|
|
72
|
-
this.logger.warning("lockfile handle does not exist, so lockfile could not be deleted");
|
|
73
|
-
}
|
|
74
|
-
} catch (err) {
|
|
75
|
-
if (err.code === Constants.ENOENT_ERROR) {
|
|
76
|
-
this.logger.info("Tried to unlock but lockfile does not exist");
|
|
77
|
-
} else {
|
|
78
|
-
this.logger.error(`${pid} was not able to release lock. Ran into error: ${err.message}`);
|
|
79
|
-
throw PersistenceError.createCrossPlatformLockError(err.message);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
private sleep(ms): Promise<void> {
|
|
85
|
-
return new Promise((resolve) => {
|
|
86
|
-
setTimeout(resolve, ms);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { promises as fs } from "fs";
|
|
7
|
+
import { pid } from "process";
|
|
8
|
+
import { CrossPlatformLockOptions } from "./CrossPlatformLockOptions";
|
|
9
|
+
import { Constants } from "../utils/Constants";
|
|
10
|
+
import { PersistenceError } from "../error/PersistenceError";
|
|
11
|
+
import { Logger } from "@azure/msal-common";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Cross-process lock that works on all platforms.
|
|
15
|
+
*/
|
|
16
|
+
export class CrossPlatformLock {
|
|
17
|
+
|
|
18
|
+
private readonly lockFilePath: string;
|
|
19
|
+
private lockFileHandle: fs.FileHandle;
|
|
20
|
+
private readonly retryNumber: number;
|
|
21
|
+
private readonly retryDelay: number;
|
|
22
|
+
|
|
23
|
+
private logger: Logger;
|
|
24
|
+
|
|
25
|
+
constructor(lockFilePath: string, logger: Logger, lockOptions?: CrossPlatformLockOptions) {
|
|
26
|
+
this.lockFilePath = lockFilePath;
|
|
27
|
+
this.retryNumber = lockOptions ? lockOptions.retryNumber : 500;
|
|
28
|
+
this.retryDelay = lockOptions ? lockOptions.retryDelay : 100;
|
|
29
|
+
this.logger = logger;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Locks cache from read or writes by creating file with same path and name as
|
|
34
|
+
* cache file but with .lockfile extension. If another process has already created
|
|
35
|
+
* the lockfile, will back off and retry based on configuration settings set by CrossPlatformLockOptions
|
|
36
|
+
*/
|
|
37
|
+
public async lock(): Promise<void> {
|
|
38
|
+
for (let tryCount = 0; tryCount < this.retryNumber; tryCount++) {
|
|
39
|
+
try {
|
|
40
|
+
this.logger.info(`Pid ${pid} trying to acquire lock`);
|
|
41
|
+
this.lockFileHandle = await fs.open(this.lockFilePath, "wx+");
|
|
42
|
+
|
|
43
|
+
this.logger.info(`Pid ${pid} acquired lock`);
|
|
44
|
+
await this.lockFileHandle.write(pid.toString());
|
|
45
|
+
return;
|
|
46
|
+
} catch (err) {
|
|
47
|
+
if (err.code === Constants.EEXIST_ERROR || err.code === Constants.EPERM_ERROR) {
|
|
48
|
+
this.logger.info(err);
|
|
49
|
+
await this.sleep(this.retryDelay);
|
|
50
|
+
} else {
|
|
51
|
+
this.logger.error(`${pid} was not able to acquire lock. Ran into error: ${err.message}`);
|
|
52
|
+
throw PersistenceError.createCrossPlatformLockError(err.message);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
this.logger.error(`${pid} was not able to acquire lock. Exceeded amount of retries set in the options`);
|
|
57
|
+
throw PersistenceError.createCrossPlatformLockError(
|
|
58
|
+
"Not able to acquire lock. Exceeded amount of retries set in options");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* unlocks cache file by deleting .lockfile.
|
|
63
|
+
*/
|
|
64
|
+
public async unlock(): Promise<void> {
|
|
65
|
+
try {
|
|
66
|
+
if(this.lockFileHandle){
|
|
67
|
+
// if we have a file handle to the .lockfile, delete lock file
|
|
68
|
+
await fs.unlink(this.lockFilePath);
|
|
69
|
+
await this.lockFileHandle.close();
|
|
70
|
+
this.logger.info("lockfile deleted");
|
|
71
|
+
} else {
|
|
72
|
+
this.logger.warning("lockfile handle does not exist, so lockfile could not be deleted");
|
|
73
|
+
}
|
|
74
|
+
} catch (err) {
|
|
75
|
+
if (err.code === Constants.ENOENT_ERROR) {
|
|
76
|
+
this.logger.info("Tried to unlock but lockfile does not exist");
|
|
77
|
+
} else {
|
|
78
|
+
this.logger.error(`${pid} was not able to release lock. Ran into error: ${err.message}`);
|
|
79
|
+
throw PersistenceError.createCrossPlatformLockError(err.message);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private sleep(ms): Promise<void> {
|
|
85
|
+
return new Promise((resolve) => {
|
|
86
|
+
setTimeout(resolve, ms);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Options for CrossPlatform lock.
|
|
8
|
-
*
|
|
9
|
-
* retryNumber: Numbers of times we should try to acquire a lock. Defaults to 500.
|
|
10
|
-
* retryDelay: Time to wait before trying to retry a lock acquisition. Defaults to 100 ms.
|
|
11
|
-
*/
|
|
12
|
-
export type CrossPlatformLockOptions = {
|
|
13
|
-
retryNumber: number;
|
|
14
|
-
retryDelay: number;
|
|
15
|
-
};
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Options for CrossPlatform lock.
|
|
8
|
+
*
|
|
9
|
+
* retryNumber: Numbers of times we should try to acquire a lock. Defaults to 500.
|
|
10
|
+
* retryDelay: Time to wait before trying to retry a lock acquisition. Defaults to 100 ms.
|
|
11
|
+
*/
|
|
12
|
+
export type CrossPlatformLockOptions = {
|
|
13
|
+
retryNumber: number;
|
|
14
|
+
retryDelay: number;
|
|
15
|
+
};
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { PersistenceError } from "../error/PersistenceError";
|
|
7
|
-
import { Constants } from "../utils/Constants";
|
|
8
|
-
import { IPersistence } from "./IPersistence";
|
|
9
|
-
|
|
10
|
-
export abstract class BasePersistence {
|
|
11
|
-
public abstract createForPersistenceValidation(): Promise<IPersistence>;
|
|
12
|
-
|
|
13
|
-
public async verifyPersistence(): Promise<boolean> {
|
|
14
|
-
// We are using a different location for the test to avoid overriding the functional cache
|
|
15
|
-
const persistenceValidator = await this.createForPersistenceValidation();
|
|
16
|
-
|
|
17
|
-
try {
|
|
18
|
-
await persistenceValidator.save(Constants.PERSISTENCE_TEST_DATA);
|
|
19
|
-
|
|
20
|
-
const retrievedDummyData = await persistenceValidator.load();
|
|
21
|
-
|
|
22
|
-
if (!retrievedDummyData) {
|
|
23
|
-
throw PersistenceError.createCachePersistenceError(
|
|
24
|
-
"Persistence check failed. Data was written but it could not be read. " +
|
|
25
|
-
"Possible cause: on Linux, LibSecret is installed but D-Bus isn't running because it cannot be started over SSH."
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (retrievedDummyData !== Constants.PERSISTENCE_TEST_DATA) {
|
|
30
|
-
throw PersistenceError.createCachePersistenceError(
|
|
31
|
-
`Persistence check failed. Data written ${Constants.PERSISTENCE_TEST_DATA} is different from data read ${retrievedDummyData}`
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
await persistenceValidator.delete();
|
|
35
|
-
return true;
|
|
36
|
-
} catch (e) {
|
|
37
|
-
throw PersistenceError.createCachePersistenceError(`Verifing persistence failed with the error: ${e}`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { PersistenceError } from "../error/PersistenceError";
|
|
7
|
+
import { Constants } from "../utils/Constants";
|
|
8
|
+
import { IPersistence } from "./IPersistence";
|
|
9
|
+
|
|
10
|
+
export abstract class BasePersistence {
|
|
11
|
+
public abstract createForPersistenceValidation(): Promise<IPersistence>;
|
|
12
|
+
|
|
13
|
+
public async verifyPersistence(): Promise<boolean> {
|
|
14
|
+
// We are using a different location for the test to avoid overriding the functional cache
|
|
15
|
+
const persistenceValidator = await this.createForPersistenceValidation();
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
await persistenceValidator.save(Constants.PERSISTENCE_TEST_DATA);
|
|
19
|
+
|
|
20
|
+
const retrievedDummyData = await persistenceValidator.load();
|
|
21
|
+
|
|
22
|
+
if (!retrievedDummyData) {
|
|
23
|
+
throw PersistenceError.createCachePersistenceError(
|
|
24
|
+
"Persistence check failed. Data was written but it could not be read. " +
|
|
25
|
+
"Possible cause: on Linux, LibSecret is installed but D-Bus isn't running because it cannot be started over SSH."
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (retrievedDummyData !== Constants.PERSISTENCE_TEST_DATA) {
|
|
30
|
+
throw PersistenceError.createCachePersistenceError(
|
|
31
|
+
`Persistence check failed. Data written ${Constants.PERSISTENCE_TEST_DATA} is different from data read ${retrievedDummyData}`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
await persistenceValidator.delete();
|
|
35
|
+
return true;
|
|
36
|
+
} catch (e) {
|
|
37
|
+
throw PersistenceError.createCachePersistenceError(`Verifing persistence failed with the error: ${e}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Specifies the scope of the data protection - either the current user or the local
|
|
8
|
-
* machine.
|
|
9
|
-
*
|
|
10
|
-
* You do not need a key to protect or unprotect the data.
|
|
11
|
-
* If you set the Scope to CurrentUser, only applications running on your credentials can
|
|
12
|
-
* unprotect the data; however, that means that any application running on your credentials
|
|
13
|
-
* can access the protected data. If you set the Scope to LocalMachine, any full-trust
|
|
14
|
-
* application on the computer can unprotect, access, and modify the data.
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
export enum DataProtectionScope {
|
|
18
|
-
CurrentUser = "CurrentUser",
|
|
19
|
-
LocalMachine = "LocalMachine",
|
|
20
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Specifies the scope of the data protection - either the current user or the local
|
|
8
|
+
* machine.
|
|
9
|
+
*
|
|
10
|
+
* You do not need a key to protect or unprotect the data.
|
|
11
|
+
* If you set the Scope to CurrentUser, only applications running on your credentials can
|
|
12
|
+
* unprotect the data; however, that means that any application running on your credentials
|
|
13
|
+
* can access the protected data. If you set the Scope to LocalMachine, any full-trust
|
|
14
|
+
* application on the computer can unprotect, access, and modify the data.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
export enum DataProtectionScope {
|
|
18
|
+
CurrentUser = "CurrentUser",
|
|
19
|
+
LocalMachine = "LocalMachine",
|
|
20
|
+
}
|