backuptarget: pseudo target for import and restore
This commit is contained in:
@@ -22,8 +22,6 @@ exports = module.exports = {
|
||||
getSnapshotInfo,
|
||||
setSnapshotInfo,
|
||||
|
||||
validateFormat,
|
||||
|
||||
getRootPath,
|
||||
|
||||
remount,
|
||||
@@ -33,9 +31,12 @@ exports = module.exports = {
|
||||
storageApi,
|
||||
|
||||
getBackupFilePath,
|
||||
|
||||
createPseudo,
|
||||
};
|
||||
|
||||
const assert = require('assert'),
|
||||
backupFormat = require('./backupformat.js'),
|
||||
backups = require('./backups.js'),
|
||||
BoxError = require('./boxerror.js'),
|
||||
constants = require('./constants.js'),
|
||||
@@ -160,14 +161,6 @@ function removePrivateFields(target) {
|
||||
return target;
|
||||
}
|
||||
|
||||
function validateFormat(format) {
|
||||
assert.strictEqual(typeof format, 'string');
|
||||
|
||||
if (format === 'tgz' || format == 'rsync') return null;
|
||||
|
||||
return new BoxError(BoxError.BAD_FIELD, 'Invalid backup format');
|
||||
}
|
||||
|
||||
function validateLabel(label) {
|
||||
assert.strictEqual(typeof label, 'string');
|
||||
|
||||
@@ -492,7 +485,7 @@ async function add(data, auditSource) {
|
||||
encryptionPassword = data.encryptionPassword || null,
|
||||
encryptedFilenames = data.encryptedFilenames || false;
|
||||
|
||||
const formatError = validateFormat(format);
|
||||
const formatError = backupFormat.validateFormat(format);
|
||||
if (formatError) throw formatError;
|
||||
|
||||
const labelError = validateLabel(label);
|
||||
@@ -522,3 +515,27 @@ async function add(data, auditSource) {
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
// creates a backup target object that is not in the database
|
||||
async function createPseudo(data) {
|
||||
assert.strictEqual(typeof data, 'object');
|
||||
|
||||
const { id, provider, config, format } = data; // required
|
||||
const encryptionPassword = data.encryptionPassword || null,
|
||||
encryptedFilenames = data.encryptedFilenames || false;
|
||||
|
||||
const formatError = backupFormat.validateFormat(format);
|
||||
if (formatError) throw formatError;
|
||||
|
||||
let encryption = null;
|
||||
if (encryptionPassword) {
|
||||
const encryptionPasswordError = validateEncryptionPassword(encryptionPassword);
|
||||
if (encryptionPasswordError) throw encryptionPasswordError;
|
||||
encryption = hush.generateEncryptionKeysSync(encryptionPassword);
|
||||
encryption.encryptedFilenames = !!encryptedFilenames;
|
||||
}
|
||||
|
||||
debug('add: validating new storage configuration');
|
||||
const sanitizedConfig = await storageApi({ provider }).verifyConfig({id, provider, config });
|
||||
return { id, format, provider, config: sanitizedConfig, encryption };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user