Add route to restore box from backup

Part of #439
This commit is contained in:
Girish Ramakrishnan
2017-11-22 11:16:44 -08:00
parent 0f191324fa
commit ac94a0b7f2
5 changed files with 90 additions and 4 deletions

View File

@@ -6,6 +6,7 @@ exports = module.exports = {
setupTokenAuth: setupTokenAuth,
providerTokenAuth: providerTokenAuth,
getStatus: getStatus,
restore: restore,
reboot: reboot,
migrate: migrate,
getProgress: getProgress,
@@ -78,6 +79,31 @@ function activate(req, res, next) {
});
}
function restore(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (!req.body.backupConfig || typeof req.body.backupConfig !== 'object') return next(new HttpError(400, 'backupConfig is required'));
var backupConfig = req.body.backupConfig;
if (typeof backupConfig.provider !== 'string') return next(new HttpError(400, 'provider is required'));
if ('key' in backupConfig && typeof backupConfig.key !== 'string') return next(new HttpError(400, 'key must be a string'));
if (typeof backupConfig.format !== 'string') return next(new HttpError(400, 'format must be a string'));
if ('acceptSelfSignedCerts' in backupConfig && typeof backupConfig.acceptSelfSignedCerts !== 'boolean') return next(new HttpError(400, 'format must be a boolean'));
if (typeof req.body.backupId !== 'string') return next(new HttpError(400, 'backupId must be a string or null'));
if (typeof req.body.version !== 'string') return next(new HttpError(400, 'version must be a string'));
cloudron.restore(backupConfig, req.body.backupId, req.body.version, function (error) {
if (error && error.reason === CloudronError.ALREADY_SETUP) return next(new HttpError(409, error.message));
if (error && error.reason === CloudronError.BAD_FIELD) return next(new HttpError(400, error.message));
if (error && error.reason === CloudronError.BAD_STATE) return next(new HttpError(409, error.message));
if (error && error.reason === CloudronError.EXTERNAL_ERROR) return next(new HttpError(402, error.message));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200));
});
}
function dnsSetup(req, res, next) {
assert.strictEqual(typeof req.body, 'object');