mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 22:43:30 +03:00
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
This commit is contained in:
parent
ed56239523
commit
74c15c7b02
@ -6,23 +6,7 @@ const events = require('../../lib/common/events');
|
||||
const models = require('../../models');
|
||||
const SettingsCache = require('../../../shared/settings-cache');
|
||||
const SettingsBREADService = require('./settings-bread-service');
|
||||
|
||||
// The string returned when a setting is set as write-only
|
||||
const obfuscatedSetting = '••••••••';
|
||||
|
||||
// The function used to decide whether a setting is write-only
|
||||
function isSecretSetting(setting) {
|
||||
return /secret/.test(setting.key);
|
||||
}
|
||||
|
||||
// The function that obfuscates a write-only setting
|
||||
// NOTE: move this method into SettingsBREADService once once refactoring is finished
|
||||
function hideValueIfSecret(setting) {
|
||||
if (setting.value && isSecretSetting(setting)) {
|
||||
return {...setting, value: obfuscatedSetting};
|
||||
}
|
||||
return setting;
|
||||
}
|
||||
const {obfuscatedSetting, isSecretSetting, hideValueIfSecret} = require('./settings-utils');
|
||||
|
||||
/**
|
||||
* @returns {SettingsBREADService} instance of the PostsService
|
||||
|
@ -1,28 +1,13 @@
|
||||
const _ = require('lodash');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
const {NotFoundError, NoPermissionError, BadRequestError} = require('@tryghost/errors');
|
||||
const {obfuscatedSetting, isSecretSetting, hideValueIfSecret} = require('./settings-utils');
|
||||
|
||||
const messages = {
|
||||
problemFindingSetting: 'Problem finding setting: {key}',
|
||||
accessCoreSettingFromExtReq: 'Attempted to access core setting from external request'
|
||||
};
|
||||
|
||||
// The string returned when a setting is set as write-only
|
||||
const obfuscatedSetting = '••••••••';
|
||||
|
||||
// The function used to decide whether a setting is write-only
|
||||
function isSecretSetting(setting) {
|
||||
return /secret/.test(setting.key);
|
||||
}
|
||||
|
||||
// The function that obfuscates a write-only setting
|
||||
function hideValueIfSecret(setting) {
|
||||
if (setting.value && isSecretSetting(setting)) {
|
||||
return {...setting, value: obfuscatedSetting};
|
||||
}
|
||||
return setting;
|
||||
}
|
||||
|
||||
class SettingsBREADService {
|
||||
/**
|
||||
*
|
||||
|
32
core/server/services/settings/settings-utils.js
Normal file
32
core/server/services/settings/settings-utils.js
Normal file
@ -0,0 +1,32 @@
|
||||
// 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
|
||||
};
|
Loading…
Reference in New Issue
Block a user