153 lines
4.7 KiB
JavaScript
153 lines
4.7 KiB
JavaScript
'use strict';
|
|
|
|
// -------------------------------------------
|
|
// This file just describes the interface
|
|
//
|
|
// New backends can start from here
|
|
// -------------------------------------------
|
|
|
|
// Implementation note:
|
|
// retry logic for upload() comes from the syncer since it is stream based
|
|
// for the other API calls we leave it to the backend to retry. this allows
|
|
// them to tune the concurrency based on failures/rate limits accordingly
|
|
exports = module.exports = {
|
|
getBackupPath,
|
|
checkPreconditions,
|
|
|
|
upload,
|
|
|
|
exists,
|
|
|
|
download,
|
|
downloadDir,
|
|
copy,
|
|
|
|
listDir,
|
|
|
|
remove,
|
|
removeDir,
|
|
|
|
testConfig,
|
|
removePrivateFields,
|
|
injectPrivateFields
|
|
};
|
|
|
|
var assert = require('assert'),
|
|
BoxError = require('../boxerror.js'),
|
|
DataLayout = require('../datalayout.js'),
|
|
EventEmitter = require('events');
|
|
|
|
function removePrivateFields(apiConfig) {
|
|
// in-place removal of tokens and api keys with constants.SECRET_PLACEHOLDER
|
|
return apiConfig;
|
|
}
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
function injectPrivateFields(newConfig, currentConfig) {
|
|
// in-place injection of tokens and api keys which came in with constants.SECRET_PLACEHOLDER
|
|
}
|
|
|
|
function getBackupPath(apiConfig) {
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
|
|
|
// Result: path at the backup storage
|
|
return '/';
|
|
}
|
|
|
|
function checkPreconditions(apiConfig, dataLayout, callback) {
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
|
assert(dataLayout instanceof DataLayout, 'dataLayout must be a DataLayout');
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
callback(null);
|
|
}
|
|
|
|
function upload(apiConfig, backupFilePath, sourceStream, callback) {
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
|
assert.strictEqual(typeof backupFilePath, 'string');
|
|
assert.strictEqual(typeof sourceStream, 'object');
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
// Result: none
|
|
// sourceStream errors are handled upstream
|
|
|
|
callback(new BoxError(BoxError.NOT_IMPLEMENTED, 'upload is not implemented'));
|
|
}
|
|
|
|
function exists(apiConfig, backupFilePath, callback) {
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
|
assert.strictEqual(typeof backupFilePath, 'string');
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
callback(new BoxError(BoxError.NOT_IMPLEMENTED, 'exists is not implemented'));
|
|
}
|
|
|
|
function download(apiConfig, backupFilePath, callback) {
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
|
assert.strictEqual(typeof backupFilePath, 'string');
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
// Result: download stream
|
|
callback(new BoxError(BoxError.NOT_IMPLEMENTED, 'download is not implemented'));
|
|
}
|
|
|
|
function downloadDir(apiConfig, backupFilePath, destDir) {
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
|
assert.strictEqual(typeof backupFilePath, 'string');
|
|
assert.strictEqual(typeof destDir, 'string');
|
|
|
|
var events = new EventEmitter();
|
|
process.nextTick(function () { events.emit('done', null); });
|
|
return events;
|
|
}
|
|
|
|
function copy(apiConfig, oldFilePath, newFilePath) {
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
|
assert.strictEqual(typeof oldFilePath, 'string');
|
|
assert.strictEqual(typeof newFilePath, 'string');
|
|
|
|
var events = new EventEmitter();
|
|
process.nextTick(function () { events.emit('done', null); });
|
|
return events;
|
|
}
|
|
|
|
function listDir(apiConfig, dir, batchSize, iteratorCallback, callback) {
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
|
assert.strictEqual(typeof dir, 'string');
|
|
assert.strictEqual(typeof batchSize, 'number');
|
|
assert.strictEqual(typeof iteratorCallback, 'function');
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
callback(new BoxError(BoxError.NOT_IMPLEMENTED, 'listDir is not implemented'));
|
|
}
|
|
|
|
function remove(apiConfig, filename, callback) {
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
|
assert.strictEqual(typeof filename, 'string');
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
// Result: none
|
|
|
|
callback(new BoxError(BoxError.NOT_IMPLEMENTED, 'remove is not implemented'));
|
|
}
|
|
|
|
function removeDir(apiConfig, pathPrefix) {
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
|
assert.strictEqual(typeof pathPrefix, 'string');
|
|
|
|
// Result: none
|
|
var events = new EventEmitter();
|
|
process.nextTick(function () { events.emit('done', new BoxError(BoxError.NOT_IMPLEMENTED, 'removeDir is not implemented')); });
|
|
return events;
|
|
}
|
|
|
|
function testConfig(apiConfig, callback) {
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
// Result: none - first callback argument error if config does not pass the test
|
|
|
|
callback(new BoxError(BoxError.NOT_IMPLEMENTED, 'testConfig is not implemented'));
|
|
}
|
|
|