merge settingsdb into settings code

This commit is contained in:
Girish Ramakrishnan
2021-08-19 13:24:38 -07:00
parent 4cd5137292
commit 411cc7daa1
25 changed files with 332 additions and 578 deletions
+56 -70
View File
@@ -18,44 +18,40 @@ const assert = require('assert'),
safe = require('safetydance'),
settings = require('../settings.js');
function getAutoupdatePattern(req, res, next) {
settings.getAutoupdatePattern(function (error, pattern) {
if (error) return next(BoxError.toHttpError(error));
async function getAutoupdatePattern(req, res, next) {
const [error, pattern] = await safe(settings.getAutoupdatePattern());
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, { pattern: pattern }));
});
next(new HttpSuccess(200, { pattern }));
}
function setAutoupdatePattern(req, res, next) {
async function setAutoupdatePattern(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (typeof req.body.pattern !== 'string') return next(new HttpError(400, 'pattern is required'));
settings.setAutoupdatePattern(req.body.pattern, function (error) {
if (error) return next(BoxError.toHttpError(error));
const [error] = await safe(settings.setAutoupdatePattern(req.body.pattern));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, {}));
});
next(new HttpSuccess(200, {}));
}
function getTimeZone(req, res, next) {
settings.getTimeZone(function (error, tz) {
if (error) return next(BoxError.toHttpError(error));
async function getTimeZone(req, res, next) {
const [error, timeZone] = await safe(settings.getTimeZone());
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, { timeZone: tz }));
});
next(new HttpSuccess(200, { timeZone }));
}
function setTimeZone(req, res, next) {
async function setTimeZone(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (typeof req.body.timeZone !== 'string') return next(new HttpError(400, 'timeZone is required'));
settings.setTimeZone(req.body.timeZone, function (error) {
if (error) return next(BoxError.toHttpError(error));
const [error] = await safe(settings.setTimeZone(req.body.timeZone));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, {}));
});
next(new HttpSuccess(200, {}));
}
async function getSupportConfig(req, res, next) {
@@ -65,15 +61,14 @@ async function getSupportConfig(req, res, next) {
next(new HttpSuccess(200, supportConfig));
}
function getBackupConfig(req, res, next) {
settings.getBackupConfig(function (error, backupConfig) {
if (error) return next(BoxError.toHttpError(error));
async function getBackupConfig(req, res, next) {
const [error, backupConfig] = await safe(settings.getBackupConfig());
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, backups.removePrivateFields(backupConfig)));
});
next(new HttpSuccess(200, backups.removePrivateFields(backupConfig)));
}
function setBackupConfig(req, res, next) {
async function setBackupConfig(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (typeof req.body.provider !== 'string') return next(new HttpError(400, 'provider is required'));
@@ -111,22 +106,20 @@ function setBackupConfig(req, res, next) {
// testing the backup using put/del takes a bit of time at times
req.clearTimeout();
settings.setBackupConfig(req.body, function (error) {
if (error) return next(BoxError.toHttpError(error));
const [error] = await safe(settings.setBackupConfig(req.body));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, {}));
});
next(new HttpSuccess(200, {}));
}
function getExternalLdapConfig(req, res, next) {
settings.getExternalLdapConfig(function (error, config) {
if (error) return next(BoxError.toHttpError(error));
async function getExternalLdapConfig(req, res, next) {
const [error, config] = await safe(settings.getExternalLdapConfig());
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, externalLdap.removePrivateFields(config)));
});
next(new HttpSuccess(200, externalLdap.removePrivateFields(config)));
}
function setExternalLdapConfig(req, res, next) {
async function setExternalLdapConfig(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (!req.body.provider || typeof req.body.provider !== 'string') return next(new HttpError(400, 'provider must be a string'));
@@ -138,31 +131,28 @@ function setExternalLdapConfig(req, res, next) {
if ('bindDn' in req.body && typeof req.body.bindDn !== 'string') return next(new HttpError(400, 'bindDn must be a non empty string'));
if ('bindPassword' in req.body && typeof req.body.bindPassword !== 'string') return next(new HttpError(400, 'bindPassword must be a string'));
settings.setExternalLdapConfig(req.body, function (error) {
if (error) return next(BoxError.toHttpError(error));
const [error] = await safe(settings.setExternalLdapConfig(req.body));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, {}));
});
next(new HttpSuccess(200, {}));
}
function getDynamicDnsConfig(req, res, next) {
settings.getDynamicDnsConfig(function (error, enabled) {
if (error) return next(BoxError.toHttpError(error));
async function getDynamicDnsConfig(req, res, next) {
const [error, enabled] = await safe(settings.getDynamicDnsConfig());
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, { enabled: enabled }));
});
next(new HttpSuccess(200, { enabled }));
}
function setDynamicDnsConfig(req, res, next) {
async function setDynamicDnsConfig(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (typeof req.body.enabled !== 'boolean') return next(new HttpError(400, 'enabled boolean is required'));
settings.setDynamicDnsConfig(req.body.enabled, function (error) {
if (error) return next(BoxError.toHttpError(error));
const [error] = await safe(settings.setDynamicDnsConfig(req.body.enabled));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, {}));
});
next(new HttpSuccess(200, {}));
}
async function getUnstableAppsConfig(req, res, next) {
@@ -183,15 +173,14 @@ async function setUnstableAppsConfig(req, res, next) {
next(new HttpSuccess(200, {}));
}
function getRegistryConfig(req, res, next) {
settings.getRegistryConfig(function (error, registryConfig) {
if (error) return next(BoxError.toHttpError(error));
async function getRegistryConfig(req, res, next) {
const [error, registryConfig] = await safe(settings.getRegistryConfig());
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, docker.removePrivateFields(registryConfig)));
});
next(new HttpSuccess(200, docker.removePrivateFields(registryConfig)));
}
function setRegistryConfig(req, res, next) {
async function setRegistryConfig(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (!req.body.provider || typeof req.body.provider !== 'string') return next(new HttpError(400, 'provider is required'));
@@ -202,11 +191,10 @@ function setRegistryConfig(req, res, next) {
if ('password' in req.body && typeof req.body.password !== 'string') return next(new HttpError(400, 'password is required'));
}
settings.setRegistryConfig(req.body, function (error) {
if (error) return next(BoxError.toHttpError(error));
const [error] = await safe(settings.setRegistryConfig(req.body));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200));
});
next(new HttpSuccess(200));
}
async function getDirectoryConfig(req, res, next) {
@@ -228,24 +216,22 @@ async function setDirectoryConfig(req, res, next) {
next(new HttpSuccess(200, {}));
}
function getSysinfoConfig(req, res, next) {
settings.getSysinfoConfig(function (error, sysinfoConfig) {
if (error) return next(BoxError.toHttpError(error));
async function getSysinfoConfig(req, res, next) {
const [error, sysinfoConfig] = await safe(settings.getSysinfoConfig());
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, sysinfoConfig));
});
next(new HttpSuccess(200, sysinfoConfig));
}
function setSysinfoConfig(req, res, next) {
async function setSysinfoConfig(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (!req.body.provider || typeof req.body.provider !== 'string') return next(new HttpError(400, 'provider is required'));
settings.setSysinfoConfig(req.body, function (error) {
if (error) return next(BoxError.toHttpError(error));
const [error] = await safe(settings.setSysinfoConfig(req.body));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, {}));
});
next(new HttpSuccess(200, {}));
}
async function getLanguage(req, res, next) {