Add REST route for platform config

Fixes #566
This commit is contained in:
Girish Ramakrishnan
2018-07-25 13:06:38 -07:00
parent f4d7d4e7f2
commit 0cb03e3789
4 changed files with 63 additions and 24 deletions

View File

@@ -20,7 +20,10 @@ exports = module.exports = {
setTimeZone: setTimeZone,
getAppstoreConfig: getAppstoreConfig,
setAppstoreConfig: setAppstoreConfig
setAppstoreConfig: setAppstoreConfig,
getPlatformConfig: getPlatformConfig,
setPlatformConfig: setPlatformConfig
};
var assert = require('assert'),
@@ -169,6 +172,34 @@ function setBackupConfig(req, res, next) {
});
}
function getPlatformConfig(req, res, next) {
settings.getPlatformConfig(function (error, config) {
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200, config));
});
}
function setPlatformConfig(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
for (let addon of [ 'mysql', 'postgresql', 'mail', 'mongodb' ]) {
if (!(addon in req.body)) continue;
if (typeof req.body[addon] !== 'object') return next(new HttpError(400, 'addon config must be an object'));
if (typeof req.body[addon].memory !== 'number') return next(new HttpError(400, 'memory must be a number'));
if (typeof req.body[addon].memorySwap !== 'number') return next(new HttpError(400, 'memorySwap must be a number'));
}
settings.setPlatformConfig(req.body, function (error) {
if (error && error.reason === SettingsError.BAD_FIELD) return next(new HttpError(400, error.message));
if (error && error.reason === SettingsError.EXTERNAL_ERROR) return next(new HttpError(402, error.message));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200, {}));
});
}
function getAppstoreConfig(req, res, next) {
settings.getAppstoreConfig(function (error, result) {
if (error) return next(new HttpError(500, error));