mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 10:53:34 +03:00
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
|
||
|
};
|