import: cleanup app import logic

This commit is contained in:
Girish Ramakrishnan
2022-10-02 10:08:50 +02:00
parent 9f788c2c57
commit 4aab03bb07
2 changed files with 13 additions and 15 deletions

View File

@@ -2174,20 +2174,18 @@ async function importApp(app, data, auditSource) {
const appId = app.id;
// all fields are optional
data.remotePath = data.remotePath || null;
data.backupFormat = data.backupFormat || null;
data.backupConfig = data.backupConfig || null;
const { remotePath, backupFormat, backupConfig } = data;
let error = backupFormat ? validateBackupFormat(backupFormat) : null;
let error = checkAppState(app, exports.ISTATE_PENDING_IMPORT);
if (error) throw error;
error = checkAppState(app, exports.ISTATE_PENDING_IMPORT);
if (error) throw error;
let restoreConfig;
// TODO: make this smarter to do a read-only test and check if the file exists in the storage backend
if (backupConfig) {
if (data.remotePath) { // if not provided, we import in-place
error = validateBackupFormat(backupFormat);
if (error) throw error;
// TODO: make this smarter to do a read-only test and check if the file exists in the storage backend
if (mounts.isManagedProvider(backupConfig.provider)) {
error = mounts.validateMountOptions(backupConfig.provider, backupConfig.mountOptions);
if (error) throw error;
@@ -2203,18 +2201,18 @@ async function importApp(app, data, auditSource) {
}
error = await backups.testProviderConfig(backupConfig);
if (error) throw error;
}
if (backupConfig) {
if ('password' in backupConfig) {
backupConfig.encryption = backups.generateEncryptionKeysSync(backupConfig.password);
delete backupConfig.password;
} else {
backupConfig.encryption = null;
}
}
const restoreConfig = { remotePath, backupFormat, backupConfig };
restoreConfig = { remotePath, backupFormat, backupConfig };
} else {
restoreConfig = { remotePath: null };
}
const task = {
args: {