UNPKG

2.18 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright (c) 2018, salesforce.com, inc.
4 * All rights reserved.
5 * SPDX-License-Identifier: BSD-3-Clause
6 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7 */
8Object.defineProperty(exports, "__esModule", { value: true });
9const kit_1 = require("@salesforce/kit");
10const keyChainImpl_1 = require("./keyChainImpl");
11const logger_1 = require("./logger");
12const sfdxError_1 = require("./sfdxError");
13/**
14 * Gets the os level keychain impl.
15 * @param platform The os platform.
16 * @ignore
17 */
18exports.retrieveKeychain = async (platform) => {
19 const logger = await logger_1.Logger.child('keyChain');
20 logger.debug(`platform: ${platform}`);
21 const useGenericUnixKeychainVar = kit_1.env.getBoolean('SFDX_USE_GENERIC_UNIX_KEYCHAIN');
22 const shouldUseGenericUnixKeychain = !!useGenericUnixKeychainVar && useGenericUnixKeychainVar;
23 if (/^win/.test(platform)) {
24 return keyChainImpl_1.keyChainImpl.generic_windows;
25 }
26 else if (/darwin/.test(platform)) {
27 // OSX can use the generic keychain. This is useful when running under an
28 // automation user.
29 if (shouldUseGenericUnixKeychain) {
30 return keyChainImpl_1.keyChainImpl.generic_unix;
31 }
32 else {
33 return keyChainImpl_1.keyChainImpl.darwin;
34 }
35 }
36 else if (/linux/.test(platform)) {
37 // Use the generic keychain if specified
38 if (shouldUseGenericUnixKeychain) {
39 return keyChainImpl_1.keyChainImpl.generic_unix;
40 }
41 else {
42 // otherwise try and use the builtin keychain
43 try {
44 await keyChainImpl_1.keyChainImpl.linux.validateProgram();
45 return keyChainImpl_1.keyChainImpl.linux;
46 }
47 catch (e) {
48 // If the builtin keychain is not available use generic
49 return keyChainImpl_1.keyChainImpl.generic_unix;
50 }
51 }
52 }
53 else {
54 throw sfdxError_1.SfdxError.create('@salesforce/core', 'encryption', 'UnsupportedOperatingSystemError', [platform]);
55 }
56};
57//# sourceMappingURL=keyChain.js.map
\No newline at end of file