mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 18:31:57 +03:00
74c15c7b02
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
33 lines
893 B
JavaScript
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
|
|
};
|