diff --git a/src/backups.js b/src/backups.js index 509275f41..19637bbb7 100644 --- a/src/backups.js +++ b/src/backups.js @@ -8,8 +8,6 @@ exports = module.exports = { getPaged: getPaged, getByAppIdPaged: getByAppIdPaged, - getDownloadStream: getDownloadStream, - getRestoreConfig: getRestoreConfig, ensureBackup: ensureBackup, @@ -417,23 +415,6 @@ function restoreApp(app, addonsToRestore, backupId, callback) { }); } -function getDownloadStream(backupId, callback) { - assert.strictEqual(typeof backupId, 'string'); - assert.strictEqual(typeof callback, 'function'); - - settings.getBackupConfig(function (error, backupConfig) { - if (error) return callback(new BackupsError(BackupsError.INTERNAL_ERROR, error)); - - api(backupConfig.provider).getDownloadStream(backupConfig, backupId, function (error, result) { - if (error) return callback(error); - - debug('getDownloadStream: %s', backupId); - - callback(null, result); - }); - }); -} - function removeBackup(backupId, appBackupIds, callback) { assert.strictEqual(typeof backupId, 'string'); assert(util.isArray(appBackupIds)); diff --git a/src/routes/backups.js b/src/routes/backups.js index d01c235de..d22f77c96 100644 --- a/src/routes/backups.js +++ b/src/routes/backups.js @@ -2,12 +2,10 @@ exports = module.exports = { get: get, - create: create, - download: download + create: create }; -var assert = require('assert'), - backups = require('../backups.js'), +var backups = require('../backups.js'), BackupsError = require('../backups.js').BackupsError, HttpError = require('connect-lastmile').HttpError, HttpSuccess = require('connect-lastmile').HttpSuccess; @@ -42,14 +40,3 @@ function create(req, res, next) { next(new HttpSuccess(202, {})); }); } - -function download(req, res, next) { - assert.strictEqual(typeof req.params.backupId, 'string'); - - backups.getDownloadStream(req.params.backupId, function (error, result) { - if (error && error.reason === BackupsError.NOT_FOUND) return next(new HttpError(404, error.message)); - if (error) return next(new HttpError(500, error)); - - result.pipe(res); - }); -} diff --git a/src/server.js b/src/server.js index fabcae907..6205fe7e3 100644 --- a/src/server.js +++ b/src/server.js @@ -218,7 +218,6 @@ function initializeExpressSync() { // backup routes router.get ('/api/v1/backups', settingsScope, routes.user.requireAdmin, routes.backups.get); router.post('/api/v1/backups', settingsScope, routes.user.requireAdmin, routes.backups.create); - router.get ('/api/v1/backups/:backupId/download', appsScope, routes.user.requireAdmin, routes.backups.download); // disable server socket "idle" timeout. we use the timeout middleware to handle timeouts on a route level // we rely on nginx for timeouts on the TCP level (see client_header_timeout) diff --git a/src/storage/caas.js b/src/storage/caas.js index 9ff034159..1565848a4 100644 --- a/src/storage/caas.js +++ b/src/storage/caas.js @@ -6,8 +6,6 @@ exports = module.exports = { copyBackup: copyBackup, removeBackup: removeBackup, - getDownloadStream: getDownloadStream, - backupDone: backupDone, testConfig: testConfig, @@ -17,7 +15,6 @@ var assert = require('assert'), AWS = require('aws-sdk'), BackupsError = require('../backups.js').BackupsError, config = require('../config.js'), - crypto = require('crypto'), debug = require('debug')('box:storage/caas'), once = require('once'), PassThrough = require('stream').PassThrough, @@ -184,54 +181,6 @@ function removeBackup(apiConfig, backupId, appBackupIds, callback) { }); } -function getDownloadStream(apiConfig, backupId, callback) { - assert.strictEqual(typeof apiConfig, 'object'); - assert.strictEqual(typeof backupId, 'string'); - assert.strictEqual(typeof callback, 'function'); - - callback = once(callback); - - var backupFilePath = getBackupFilePath(apiConfig, backupId); - - debug('[%s] getDownloadStream: %s %s', backupId, backupId, backupFilePath); - - getBackupCredentials(apiConfig, function (error, credentials) { - if (error) return callback(error); - - var params = { - Bucket: apiConfig.bucket, - Key: backupFilePath - }; - - var s3 = new AWS.S3(credentials); - - s3.headObject(params, function (error) { - // TODO ENOENT for the mock, fix upstream! - if (error && (error.code === 'NotFound' || error.code === 'ENOENT')) return callback(new BackupsError(BackupsError.NOT_FOUND)); - if (error) return callback(new BackupsError(BackupsError.EXTERNAL_ERROR, error)); - - var s3get = s3.getObject(params).createReadStream(); - var decrypt = crypto.createDecipher('aes-256-cbc', apiConfig.key || ''); - - s3get.on('error', function (error) { - if (error.code === 'NoSuchKey') return callback(new BackupsError(BackupsError.NOT_FOUND)); - - console.error('[%s] getDownloadStream: s3 stream error.', backupId, error); - callback(new BackupsError(BackupsError.EXTERNAL_ERROR, error)); - }); - - decrypt.on('error', function (error) { - console.error('[%s] getDownloadStream: decipher stream error.', error); - callback(new BackupsError(BackupsError.INTERNAL_ERROR, error)); - }); - - s3get.pipe(decrypt); - - callback(null, decrypt); - }); - }); -} - function testConfig(apiConfig, callback) { assert.strictEqual(typeof apiConfig, 'object'); assert.strictEqual(typeof callback, 'function'); diff --git a/src/storage/filesystem.js b/src/storage/filesystem.js index a5f1470de..ddb075075 100644 --- a/src/storage/filesystem.js +++ b/src/storage/filesystem.js @@ -6,8 +6,6 @@ exports = module.exports = { copyBackup: copyBackup, removeBackup: removeBackup, - getDownloadStream: getDownloadStream, - backupDone: backupDone, testConfig: testConfig @@ -154,21 +152,6 @@ function removeBackup(apiConfig, backupId, appBackupIds, callback) { }, callback); } -function getDownloadStream(apiConfig, backupId, callback) { - assert.strictEqual(typeof apiConfig, 'object'); - assert.strictEqual(typeof backupId, 'string'); - assert.strictEqual(typeof callback, 'function'); - - var backupFilePath = getBackupFilePath(apiConfig, backupId); - - debug('[%s] getDownloadStream: %s %s', backupId, backupId, backupFilePath); - - if (!fs.existsSync(backupFilePath)) return callback(new BackupsError(BackupsError.NOT_FOUND, 'backup file does not exist')); - - var stream = fs.createReadStream(backupFilePath); - callback(null, stream); -} - function testConfig(apiConfig, callback) { assert.strictEqual(typeof apiConfig, 'object'); assert.strictEqual(typeof callback, 'function'); diff --git a/src/storage/interface.js b/src/storage/interface.js index 95f8da141..49b4695ae 100644 --- a/src/storage/interface.js +++ b/src/storage/interface.js @@ -12,8 +12,6 @@ exports = module.exports = { copyBackup: copyBackup, removeBackup: removeBackup, - getDownloadStream: getDownloadStream, - backupDone: backupDone, testConfig: testConfig @@ -65,16 +63,6 @@ function removeBackup(apiConfig, backupId, appBackupIds, callback) { callback(new Error('not implemented')); } -function getDownloadStream(apiConfig, backupId, callback) { - assert.strictEqual(typeof apiConfig, 'object'); - assert.strictEqual(typeof backupId, 'string'); - assert.strictEqual(typeof callback, 'function'); - - // Result: ReadStream to a tar.gz (not encrypted) - - callback(new Error('not implemented')); -} - function testConfig(apiConfig, callback) { assert.strictEqual(typeof apiConfig, 'object'); assert.strictEqual(typeof callback, 'function'); diff --git a/src/storage/s3.js b/src/storage/s3.js index 2da0c03b8..7238752e7 100644 --- a/src/storage/s3.js +++ b/src/storage/s3.js @@ -6,8 +6,6 @@ exports = module.exports = { copyBackup: copyBackup, removeBackup: removeBackup, - getDownloadStream: getDownloadStream, - backupDone: backupDone, testConfig: testConfig, @@ -20,7 +18,6 @@ exports = module.exports = { var assert = require('assert'), AWS = require('aws-sdk'), BackupsError = require('../backups.js').BackupsError, - crypto = require('crypto'), debug = require('debug')('box:storage/s3'), once = require('once'), PassThrough = require('stream').PassThrough, @@ -192,54 +189,6 @@ function removeBackup(apiConfig, backupId, appBackupIds, callback) { }); } -function getDownloadStream(apiConfig, backupId, callback) { - assert.strictEqual(typeof apiConfig, 'object'); - assert.strictEqual(typeof backupId, 'string'); - assert.strictEqual(typeof callback, 'function'); - - callback = once(callback); - - var backupFilePath = getBackupFilePath(apiConfig, backupId); - - debug('[%s] getDownloadStream: %s %s', backupId, backupId, backupFilePath); - - getBackupCredentials(apiConfig, function (error, credentials) { - if (error) return callback(error); - - var params = { - Bucket: apiConfig.bucket, - Key: backupFilePath - }; - - var s3 = new AWS.S3(credentials); - - s3.headObject(params, function (error) { - // TODO ENOENT for the mock, fix upstream! - if (error && (error.code === 'NotFound' || error.code === 'ENOENT')) return callback(new BackupsError(BackupsError.NOT_FOUND)); - if (error) return callback(new BackupsError(BackupsError.EXTERNAL_ERROR, error.message)); - - var s3get = s3.getObject(params).createReadStream(); - var decrypt = crypto.createDecipher('aes-256-cbc', apiConfig.key || ''); - - s3get.on('error', function (error) { - if (error.code === 'NoSuchKey') return callback(new BackupsError(BackupsError.NOT_FOUND)); - - console.error('[%s] getDownloadStream: s3 stream error.', backupId, error); - callback(new BackupsError(BackupsError.EXTERNAL_ERROR, error.message)); - }); - - decrypt.on('error', function (error) { - console.error('[%s] getDownloadStream: decipher stream error.', error); - callback(new BackupsError(BackupsError.INTERNAL_ERROR, error.message)); - }); - - s3get.pipe(decrypt); - - callback(null, decrypt); - }); - }); -} - function testConfig(apiConfig, callback) { assert.strictEqual(typeof apiConfig, 'object'); assert.strictEqual(typeof callback, 'function'); diff --git a/src/test/storage-test.js b/src/test/storage-test.js index 1128724c8..9e1193716 100644 --- a/src/test/storage-test.js +++ b/src/test/storage-test.js @@ -213,22 +213,6 @@ describe('Storage', function () { }); }); - it('cannot get backup download stream from deleted backup', function (done) { - filesystem.getDownloadStream(gBackupConfig, gBackupId_1, function (error) { - expect(error).to.be.an('object'); - expect(error.reason).to.equal(BackupsError.NOT_FOUND); - done(); - }); - }); - - it('can get backup download stream', function (done) { - filesystem.getDownloadStream(gBackupConfig, gBackupId_2, function (error, result) { - expect(error).to.be(null); - expect(result).to.be.a(stream.Readable); - done(); - }); - }); - it('can remove backup copy', function (done) { filesystem.removeBackup(gBackupConfig, gBackupId_2, [], done); }); @@ -349,22 +333,6 @@ describe('Storage', function () { }); }); - it('cannot get backup download stream from deleted backup', function (done) { - s3.getDownloadStream(gBackupConfig, gBackupId_1, function (error) { - expect(error).to.be.an('object'); - expect(error.reason).to.equal(BackupsError.NOT_FOUND); - done(); - }); - }); - - it('can get backup download stream', function (done) { - s3.getDownloadStream(gBackupConfig, gBackupId_2, function (error, result) { - expect(error).to.be(null); - expect(result).to.be.a(stream.Readable); - done(); - }); - }); - it('can remove backup copy', function (done) { s3.removeBackup(gBackupConfig, gBackupId_2, [], done); });