add route for setting/getting dns settings

This commit is contained in:
Girish Ramakrishnan
2015-10-26 00:59:20 -07:00
parent 2db2eb13af
commit f510d4bc10
4 changed files with 79 additions and 5 deletions

View File

@@ -10,7 +10,10 @@ exports = module.exports = {
setCloudronName: setCloudronName,
getCloudronAvatar: getCloudronAvatar,
setCloudronAvatar: setCloudronAvatar
setCloudronAvatar: setCloudronAvatar,
getDnsConfig: getDnsConfig,
setDnsConfig: setDnsConfig
};
var assert = require('assert'),
@@ -83,3 +86,26 @@ function getCloudronAvatar(req, res, next) {
res.status(200).send(avatar);
});
}
function getDnsConfig(req, res, next) {
settings.getDnsConfig(function (error, config) {
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200, config));
});
}
function setDnsConfig(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (req.body.provider !== 'route53') return next(new HttpError(400, 'provider is required'));
if (typeof req.body.accessKeyId !== 'string') return next(new HttpError(400, 'accessKeyId is required'));
if (typeof req.body.secretAccessKey !== 'string') return next(new HttpError(400, 'secretAccessKey is required'));
settings.setDnsConfig(req.body, function (error) {
if (error && error.reason === SettingsError.BAD_FIELD) return next(new HttpError(400, error.message));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200));
});
}