@salesforce/core
Version:
Core libraries to interact with SFDX projects, orgs, and APIs.
43 lines • 1.57 kB
JavaScript
;
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.KeychainConfig = void 0;
const path_1 = require("path");
const fs_1 = require("../util/fs");
const configFile_1 = require("./configFile");
/**
* Represent a key chain config backed by a json file.
*/
// istanbul ignore next - getPassword/setPassword is always mocked out
class KeychainConfig extends configFile_1.ConfigFile {
static getFileName() {
return 'key.json';
}
/**
* Gets default options for the KeychainConfig
*/
static getDefaultOptions() {
return configFile_1.ConfigFile.getDefaultOptions(true, KeychainConfig.getFileName());
}
/**
* Write the config file with new contents. If no new contents are passed in
* it will write this.contents that was set from read(). Returns the written contents.
*
* @param newContents the new contents of the file
*/
async write(newContents) {
if (newContents != null) {
this.setContents(newContents);
}
await fs_1.fs.mkdirp(path_1.dirname(this.getPath()));
await fs_1.fs.writeFile(this.getPath(), JSON.stringify(this.getContents(), null, 4), { mode: '600' });
return this.getContents();
}
}
exports.KeychainConfig = KeychainConfig;
//# sourceMappingURL=keychainConfig.js.map