Ghost/core/server/services/settings/settings-utils.js
Naz 74c15c7b02 Refactored secret settings util functions
refs https://github.com/TryGhost/Team/issues/694
refs https://linear.app/tryghost/issue/CORE-13

- The index file in services/settings was containning logic and started throwing an additional lint warning due to module length.
- The extracted secret settings utils were used in multiple places and were a good candidate to live in it's own small module
2021-09-21 23:05:57 +12:00

33 lines
893 B
JavaScript

// The string returned when a setting is set as write-only
const obfuscatedSetting = '••••••••';
/**
* @description // The function used to decide whether a setting is write-only
* @param {Object} setting setting record
* @param {String} setting.key
* @returns {Boolean}
*/
function isSecretSetting(setting) {
return /secret/.test(setting.key);
}
/**
* @description The function that obfuscates a write-only setting
* @param {Object} setting setting record
* @param {String} setting.value
* @param {String} setting.key
* @returns {Object} settings record with obfuscated value if it's a secret
*/
function hideValueIfSecret(setting) {
if (setting.value && isSecretSetting(setting)) {
return {...setting, value: obfuscatedSetting};
}
return setting;
}
module.exports = {
obfuscatedSetting,
isSecretSetting,
hideValueIfSecret
};