2016-09-16 12:55:45 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------
|
|
|
|
|
// This file just describes the interface
|
|
|
|
|
//
|
|
|
|
|
// New backends can start from here
|
|
|
|
|
// -------------------------------------------
|
|
|
|
|
|
2018-02-22 12:30:52 -08:00
|
|
|
// 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
|
2016-09-16 12:55:45 +02:00
|
|
|
exports = module.exports = {
|
2017-09-17 18:50:29 -07:00
|
|
|
upload: upload,
|
2018-02-22 12:30:52 -08:00
|
|
|
|
2017-09-17 18:50:29 -07:00
|
|
|
download: download,
|
2017-09-23 14:27:35 -07:00
|
|
|
downloadDir: downloadDir,
|
2017-09-17 18:50:29 -07:00
|
|
|
copy: copy,
|
|
|
|
|
|
2018-07-27 14:29:07 -07:00
|
|
|
listDir: listDir,
|
|
|
|
|
|
2017-09-23 11:09:36 -07:00
|
|
|
remove: remove,
|
2017-09-27 17:34:49 -07:00
|
|
|
removeDir: removeDir,
|
2016-10-11 11:36:25 +02:00
|
|
|
|
2019-02-09 18:08:10 -08:00
|
|
|
testConfig: testConfig,
|
|
|
|
|
removePrivateFields: removePrivateFields,
|
|
|
|
|
injectPrivateFields: injectPrivateFields
|
2016-09-16 12:55:45 +02:00
|
|
|
};
|
|
|
|
|
|
2017-10-04 11:00:30 -07:00
|
|
|
var assert = require('assert'),
|
|
|
|
|
EventEmitter = require('events');
|
2016-09-16 12:55:45 +02:00
|
|
|
|
2019-02-09 18:08:10 -08:00
|
|
|
function removePrivateFields(apiConfig) {
|
|
|
|
|
// in-place removal of tokens and api keys with domains.SECRET_PLACEHOLDER
|
|
|
|
|
return apiConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function injectPrivateFields(newConfig, currentConfig) {
|
|
|
|
|
// in-place injection of tokens and api keys which came in with domains.SECRET_PLACEHOLDER
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-20 09:57:16 -07:00
|
|
|
function upload(apiConfig, backupFilePath, sourceStream, callback) {
|
2016-09-16 12:55:45 +02:00
|
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
2017-09-19 20:40:38 -07:00
|
|
|
assert.strictEqual(typeof backupFilePath, 'string');
|
2017-09-20 09:57:16 -07:00
|
|
|
assert.strictEqual(typeof sourceStream, 'object');
|
2016-09-16 12:55:45 +02:00
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2017-04-11 11:00:55 +02:00
|
|
|
// Result: none
|
2018-02-27 19:16:03 -08:00
|
|
|
// sourceStream errors are handled upstream
|
2016-09-16 12:55:45 +02:00
|
|
|
|
|
|
|
|
callback(new Error('not implemented'));
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-20 09:57:16 -07:00
|
|
|
function download(apiConfig, backupFilePath, callback) {
|
2016-09-16 12:55:45 +02:00
|
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
2017-09-20 09:57:16 -07:00
|
|
|
assert.strictEqual(typeof backupFilePath, 'string');
|
2016-09-16 12:55:45 +02:00
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2017-09-20 09:57:16 -07:00
|
|
|
// Result: download stream
|
2017-04-11 11:00:55 +02:00
|
|
|
callback(new Error('not implemented'));
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 20:23:04 -07:00
|
|
|
function downloadDir(apiConfig, backupFilePath, destDir) {
|
2017-09-23 14:27:35 -07:00
|
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
|
|
|
|
assert.strictEqual(typeof backupFilePath, 'string');
|
|
|
|
|
assert.strictEqual(typeof destDir, 'string');
|
|
|
|
|
|
2017-10-10 20:23:04 -07:00
|
|
|
var events = new EventEmitter();
|
|
|
|
|
process.nextTick(function () { events.emit('done', null); });
|
|
|
|
|
return events;
|
2017-09-23 14:27:35 -07:00
|
|
|
}
|
|
|
|
|
|
2017-10-04 11:00:30 -07:00
|
|
|
function copy(apiConfig, oldFilePath, newFilePath) {
|
2017-04-11 11:00:55 +02:00
|
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
2017-09-19 20:40:38 -07:00
|
|
|
assert.strictEqual(typeof oldFilePath, 'string');
|
|
|
|
|
assert.strictEqual(typeof newFilePath, 'string');
|
2016-09-16 12:55:45 +02:00
|
|
|
|
2017-10-04 11:00:30 -07:00
|
|
|
var events = new EventEmitter();
|
|
|
|
|
process.nextTick(function () { events.emit('done', null); });
|
|
|
|
|
return events;
|
2016-09-16 12:55:45 +02:00
|
|
|
}
|
|
|
|
|
|
2018-07-27 14:29:07 -07:00
|
|
|
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 Error('not implemented'));
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 17:34:49 -07:00
|
|
|
function remove(apiConfig, filename, callback) {
|
|
|
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
|
|
|
|
assert.strictEqual(typeof filename, 'string');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2018-02-22 10:58:56 -08:00
|
|
|
// Result: none
|
2017-09-27 17:34:49 -07:00
|
|
|
|
|
|
|
|
callback(new Error('not implemented'));
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 20:23:04 -07:00
|
|
|
function removeDir(apiConfig, pathPrefix) {
|
2016-09-19 15:03:38 +02:00
|
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
2017-09-23 11:09:36 -07:00
|
|
|
assert.strictEqual(typeof pathPrefix, 'string');
|
2016-09-16 12:55:45 +02:00
|
|
|
|
2018-02-22 10:58:56 -08:00
|
|
|
// Result: none
|
2017-10-10 20:23:04 -07:00
|
|
|
var events = new EventEmitter();
|
|
|
|
|
process.nextTick(function () { events.emit('done', new Error('not implemented')); });
|
|
|
|
|
return events;
|
2016-09-16 12:55:45 +02:00
|
|
|
}
|
2016-10-10 15:04:28 +02:00
|
|
|
|
2016-10-11 11:36:25 +02:00
|
|
|
function testConfig(apiConfig, callback) {
|
|
|
|
|
assert.strictEqual(typeof apiConfig, 'object');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2017-04-18 14:55:22 +02:00
|
|
|
// Result: none - first callback argument error if config does not pass the test
|
2016-10-11 11:36:25 +02:00
|
|
|
|
|
|
|
|
callback(new Error('not implemented'));
|
|
|
|
|
}
|
2017-01-04 16:22:58 -08:00
|
|
|
|