rework custom configuration

This commit is contained in:
Girish Ramakrishnan
2019-05-10 15:53:34 -07:00
parent 800e25a7a7
commit a54be69c96
8 changed files with 50 additions and 58 deletions
+21 -31
View File
@@ -8,20 +8,22 @@ let debug = require('debug')('box:features'),
exports = module.exports = {
uiSpec: uiSpec,
supportEmail: supportEmail,
alertsEmail: alertsEmail,
sendAlertsToCloudronAdmins: sendAlertsToCloudronAdmins
spec: spec
};
const DEFAULT = {
features: {
configureBackup: true,
dynamicDns: true,
subscription: true,
remoteSupport: true
const DEFAULT_SPEC = {
backups: {
configurable: true
},
domains: {
dynamicDns: true
},
subscription: {
configurable: true
},
support: {
email: 'support@cloudron.io'
email: 'support@cloudron.io',
remoteSupport: true
},
alerts: {
email: '',
@@ -29,34 +31,22 @@ const DEFAULT = {
}
};
const gCustom = (function () {
const gSpec = (function () {
try {
if (!safe.fs.existsSync(paths.CUSTOM_FILE)) return DEFAULT;
if (!safe.fs.existsSync(paths.CUSTOM_FILE)) return DEFAULT_SPEC;
const c = yaml.safeLoad(safe.fs.readFileSync(paths.CUSTOM_FILE, 'utf8'));
return lodash.merge({}, DEFAULT, c);
return lodash.merge({}, DEFAULT_SPEC, c);
} catch (e) {
debug(`Error loading features file from ${paths.CUSTOM_FILE} : ${e.message}`);
return DEFAULT;
return DEFAULT_SPEC;
}
})();
// flags sent to the UI. this is separate because we have values that are secret to the backend
function uiSpec() {
return {
dynamicDns: gCustom.features.dynamicDns,
remoteSupport: gCustom.features.remoteSupport,
subscription: gCustom.features.subscription,
configureBackup: gCustom.features.configureBackup
};
return gSpec;
}
function supportEmail() {
return gCustom.support.email;
}
function alertsEmail() {
return gCustom.alerts.email;
}
function sendAlertsToCloudronAdmins() {
return gCustom.alerts.notifyCloudronAdmins;
}
function spec() {
return gSpec;
}