diff --git a/src/installer.js b/src/installer.js index f2a2bffe1..3d0665aeb 100644 --- a/src/installer.js +++ b/src/installer.js @@ -12,8 +12,6 @@ exports = module.exports = { InstallerError: InstallerError, provision: provision, - restore: restore, - update: update, retire: retire }; @@ -33,14 +31,6 @@ util.inherits(InstallerError, Error); InstallerError.INTERNAL_ERROR = 1; InstallerError.ALREADY_PROVISIONED = 2; -function update(args, callback) { - provision(args, callback); -} - -function restore(args, callback) { - provision(args, callback); -} - function spawn(tag, cmd, args, callback) { assert.strictEqual(typeof tag, 'string'); assert.strictEqual(typeof cmd, 'string'); diff --git a/src/server.js b/src/server.js index f232ab02d..71106a65f 100755 --- a/src/server.js +++ b/src/server.js @@ -51,26 +51,6 @@ function checkData(data) { } } -function restore(req, res, next) { - assert.strictEqual(typeof req.body, 'object'); - - if (typeof req.body.sourceTarballUrl !== 'string') return next(new HttpError(400, 'No sourceTarballUrl provided')); - - if (!req.body.data || typeof req.body.data !== 'object') return next(new HttpError(400, 'No data provided')); - - checkData(req.body.data); - - debug('restore: received from appstore %j', req.body); - - installer.restore(req.body, function (error) { - if (error) console.error(error); - }); - - announce.stop(function () { }); - - next(new HttpSuccess(202, { })); -} - function provision(req, res, next) { assert.strictEqual(typeof req.body, 'object'); @@ -82,33 +62,11 @@ function provision(req, res, next) { debug('provision: received from appstore %j', req.body); - installer.provision(req.body, function (error) { - if (error) console.error(error); - }); - announce.stop(function () { }); next(new HttpSuccess(202, { })); } -function update(req, res, next) { - assert.strictEqual(typeof req.body, 'object'); - - if (typeof req.body.sourceTarballUrl !== 'string') return next(new HttpError(400, 'No sourceTarballUrl provided')); - - if (!req.body.data || typeof req.body.data !== 'object') return next(new HttpError(400, 'No data provided')); - - checkData(req.body.data); - - debug('update: started'); - - installer.update(req.body, function (error) { - if (error) console.error(error); - }); - - next(new HttpSuccess(202, { })); -} - function retire(req, res, next) { assert.strictEqual(typeof req.body, 'object'); @@ -183,7 +141,7 @@ function startUpdateServer(callback) { .use(router) .use(lastMile()); - router.post('/api/v1/installer/update', update); + router.post('/api/v1/installer/update', provision); gHttpServer = http.createServer(app); gHttpServer.on('error', console.error); @@ -207,11 +165,11 @@ function startProvisionServer(callback) { .use(lastMile()); router.post('/api/v1/installer/provision', provision); - router.post('/api/v1/installer/restore', restore); + router.post('/api/v1/installer/restore', provision); router.post('/api/v1/installer/retire', retire); router.get ('/api/v1/installer/logs', logs); router.post('/api/v1/installer/backup', backup); - router.post('/api/v1/installer/update', update); + router.post('/api/v1/installer/update', provision); var caPath = path.join(__dirname, process.env.NODE_ENV === 'test' ? '../../keys/installer_ca' : 'certs'); var certPath = path.join(__dirname, process.env.NODE_ENV === 'test' ? '../../keys/installer' : 'certs'); @@ -265,13 +223,15 @@ function start(callback) { return; } - var apiServerOrigin = JSON.parse(result.body.user_data).apiServerOrigin; + var userData = JSON.parse(result.body.user_data); + var apiServerOrigin = userData.apiServerOrigin; debug('Using apiServerOrigin from metadata: %s', apiServerOrigin); async.series([ announce.start.bind(null, apiServerOrigin), startUpdateServer, - startProvisionServer + startProvisionServer, + installer.provision.bind(null, userData) ], callback); }); }