@salesforce/core 8.8.4 → 8.8.6
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/crypto/keyChain.js
CHANGED
|
@@ -21,35 +21,39 @@ const messages = new messages_1.Messages('@salesforce/core', 'encryption', new M
|
|
|
21
21
|
*/
|
|
22
22
|
const retrieveKeychain = async (platform) => {
|
|
23
23
|
const logger = await logger_1.Logger.child('keyChain');
|
|
24
|
-
logger.debug(`platform: ${platform}`);
|
|
25
24
|
const useGenericUnixKeychainVar = kit_1.env.getBoolean('SF_USE_GENERIC_UNIX_KEYCHAIN');
|
|
26
|
-
const shouldUseGenericUnixKeychain = useGenericUnixKeychainVar && useGenericUnixKeychainVar;
|
|
27
25
|
if (platform.startsWith('win')) {
|
|
26
|
+
logger.debug(`platform: ${platform}. Using generic Windows keychain.`);
|
|
28
27
|
return keyChainImpl_1.keyChainImpl.generic_windows;
|
|
29
28
|
}
|
|
30
29
|
else if (platform.includes('darwin')) {
|
|
31
30
|
// OSX can use the generic keychain. This is useful when running under an
|
|
32
31
|
// automation user.
|
|
33
|
-
if (
|
|
32
|
+
if (useGenericUnixKeychainVar) {
|
|
33
|
+
logger.debug(`platform: ${platform}. Using generic Unix keychain.`);
|
|
34
34
|
return keyChainImpl_1.keyChainImpl.generic_unix;
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
37
|
+
logger.debug(`platform: ${platform}. Using Darwin native keychain.`);
|
|
37
38
|
return keyChainImpl_1.keyChainImpl.darwin;
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
else if (platform.includes('linux')) {
|
|
41
42
|
// Use the generic keychain if specified
|
|
42
|
-
if (
|
|
43
|
+
if (useGenericUnixKeychainVar) {
|
|
44
|
+
logger.debug(`platform: ${platform}. Using generic Unix keychain.`);
|
|
43
45
|
return keyChainImpl_1.keyChainImpl.generic_unix;
|
|
44
46
|
}
|
|
45
47
|
else {
|
|
46
48
|
// otherwise try and use the builtin keychain
|
|
47
49
|
try {
|
|
50
|
+
logger.debug(`platform: ${platform}. Using Linux keychain.`);
|
|
48
51
|
await keyChainImpl_1.keyChainImpl.linux.validateProgram();
|
|
49
52
|
return keyChainImpl_1.keyChainImpl.linux;
|
|
50
53
|
}
|
|
51
54
|
catch (e) {
|
|
52
55
|
// If the builtin keychain is not available use generic
|
|
56
|
+
logger.debug(`platform: ${platform}. Using generic Unix keychain.`);
|
|
53
57
|
return keyChainImpl_1.keyChainImpl.generic_unix;
|
|
54
58
|
}
|
|
55
59
|
}
|
|
@@ -143,7 +143,7 @@ class AliasAccessor extends kit_1.AsyncOptionalCreatable {
|
|
|
143
143
|
this.aliasStore = fileContentsRawToAliasStore(await (0, promises_1.readFile)(this.fileLocation, 'utf-8'));
|
|
144
144
|
}
|
|
145
145
|
catch (e) {
|
|
146
|
-
if (e instanceof Error && 'code' in e && e.code === 'ENOENT') {
|
|
146
|
+
if (e instanceof Error && 'code' in e && typeof e.code === 'string' && ['ENOENT', 'ENOTDIR'].includes(e.code)) {
|
|
147
147
|
this.aliasStore = new Map();
|
|
148
148
|
await (0, promises_1.mkdir)((0, node_path_1.dirname)(this.fileLocation), { recursive: true });
|
|
149
149
|
await this.saveAliasStoreToFile();
|
|
@@ -39,6 +39,7 @@ const global_1 = require("../../global");
|
|
|
39
39
|
const logger_1 = require("../../logger/logger");
|
|
40
40
|
const messages_1 = require("../../messages");
|
|
41
41
|
const lifecycleEvents_1 = require("../../lifecycleEvents");
|
|
42
|
+
const sfError_1 = require("../../sfError");
|
|
42
43
|
function chunk(array, chunkSize) {
|
|
43
44
|
const final = [];
|
|
44
45
|
for (let i = 0, len = array.length; i < len; i += chunkSize)
|
|
@@ -64,9 +65,11 @@ class BaseOrgAccessor extends kit_1.AsyncOptionalCreatable {
|
|
|
64
65
|
return this.get(username, decrypt);
|
|
65
66
|
}
|
|
66
67
|
catch (err) {
|
|
67
|
-
|
|
68
|
+
const error = sfError_1.SfError.wrap(err);
|
|
69
|
+
if (['JsonParseError', 'GenericKeychainInvalidPermsError'].includes(error.name)) {
|
|
68
70
|
throw err;
|
|
69
71
|
}
|
|
72
|
+
this.logger.debug(`Error when reading auth file for user: ${username} due to: ${error.name}:${error.message}`);
|
|
70
73
|
return null;
|
|
71
74
|
}
|
|
72
75
|
}
|
|
@@ -85,7 +88,13 @@ class BaseOrgAccessor extends kit_1.AsyncOptionalCreatable {
|
|
|
85
88
|
this.configs.set(username, config);
|
|
86
89
|
}
|
|
87
90
|
catch (e) {
|
|
88
|
-
|
|
91
|
+
const error = sfError_1.SfError.wrap(e);
|
|
92
|
+
let warningMsg = `The auth file for ${username} is invalid.`;
|
|
93
|
+
if (error.message) {
|
|
94
|
+
warningMsg += ` Due to: ${error.message}`;
|
|
95
|
+
}
|
|
96
|
+
await lifecycleEvents_1.Lifecycle.getInstance().emitWarning(warningMsg);
|
|
97
|
+
this.logger.debug(`Error when reading auth file for user: ${username} due to: ${error.name}:${error.message}`);
|
|
89
98
|
}
|
|
90
99
|
});
|
|
91
100
|
// eslint-disable-next-line no-await-in-loop
|
|
@@ -222,10 +231,14 @@ class BaseOrgAccessor extends kit_1.AsyncOptionalCreatable {
|
|
|
222
231
|
else {
|
|
223
232
|
const contents = this.contents.get(username) ?? {};
|
|
224
233
|
await this.read(username, false, false);
|
|
225
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
226
234
|
const readConfig = this.configs.get(username);
|
|
227
|
-
readConfig
|
|
228
|
-
|
|
235
|
+
if (readConfig) {
|
|
236
|
+
readConfig.setContentsFromObject(contents);
|
|
237
|
+
return (await readConfig.write());
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
this.logger.debug(`Failed to write auth file for ${username}. readConfig not found.`);
|
|
241
|
+
}
|
|
229
242
|
}
|
|
230
243
|
}
|
|
231
244
|
async init() {
|