diff --git a/src/apps.js b/src/apps.js index ca1fb1aba..c7194949f 100644 --- a/src/apps.js +++ b/src/apps.js @@ -710,6 +710,8 @@ function install(data, user, auditSource, callback) { robotsTxt = data.robotsTxt || null, enableBackup = 'enableBackup' in data ? data.enableBackup : true, enableAutomaticUpdate = 'enableAutomaticUpdate' in data ? data.enableAutomaticUpdate : true, + backupId = data.backupId || null, + backupFormat = data.backupFormat || 'tgz', alternateDomains = data.alternateDomains || [], env = data.env || {}, mailboxName = data.mailboxName || '', @@ -743,6 +745,9 @@ function install(data, user, auditSource, callback) { error = validateRobotsTxt(robotsTxt); if (error) return callback(error); + error = validateBackupFormat(backupFormat); + if (error) return callback(error); + error = validateLabel(label); if (error) return callback(error); @@ -798,7 +803,7 @@ function install(data, user, auditSource, callback) { label: label, tags: tags, runState: exports.RSTATE_RUNNING, - installationState: exports.ISTATE_PENDING_INSTALL + installationState: backupId ? exports.ISTATE_PENDING_RESTORE : exports.ISTATE_PENDING_INSTALL }; appdb.add(appId, appStoreId, manifest, location, domain, translatePortBindings(portBindings, manifest), data, function (error) { @@ -815,13 +820,14 @@ function install(data, user, auditSource, callback) { if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, 'Error setting cert: ' + error.message)); } + const restoreConfig = backupId ? { backupId: backupId, backupFormat: backupFormat } : null; const task = { - args: { restoreConfig: null, overwriteDns }, + args: { restoreConfig, overwriteDns }, values: { }, - requiredState: exports.ISTATE_PENDING_INSTALL + requiredState: data.installationState }; - addTask(appId, exports.ISTATE_PENDING_INSTALL, task, function (error, result) { + addTask(appId, data.installationState, task, function (error, result) { if (error) return callback(error); const newApp = _.extend({}, data, { appStoreId, manifest, location, domain, portBindings }); diff --git a/src/routes/apps.js b/src/routes/apps.js index 2f28c554d..ce4407a9d 100644 --- a/src/routes/apps.js +++ b/src/routes/apps.js @@ -121,6 +121,9 @@ function installApp(req, res, next) { if (('portBindings' in data) && typeof data.portBindings !== 'object') return next(new HttpError(400, 'portBindings must be an object')); if ('icon' in data && typeof data.icon !== 'string') return next(new HttpError(400, 'icon is not a string')); + if (data.backupId && typeof data.backupId !== 'string') return next(new HttpError(400, 'backupId must be string or null')); + if (data.backupFormat && typeof data.backupFormat !== 'string') return next(new HttpError(400, 'backupFormat must be string or null')); + if ('label' in data && typeof data.label !== 'string') return next(new HttpError(400, 'label must be a string')); // falsy values in cert and key unset the cert