mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
SEARCH-569
- Review comments fix
This commit is contained in:
parent
761875559c
commit
181fa7b767
@ -20,10 +20,11 @@ class Crypto {
|
|||||||
constructor(userId, key) {
|
constructor(userId, key) {
|
||||||
this.indexDataFolder = `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH}_${userId}_${searchConfig.INDEX_VERSION}`;
|
this.indexDataFolder = `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH}_${userId}_${searchConfig.INDEX_VERSION}`;
|
||||||
this.permanentIndexName = `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${userId}_${searchConfig.INDEX_VERSION}`;
|
this.permanentIndexName = `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${userId}_${searchConfig.INDEX_VERSION}`;
|
||||||
this.dump = DUMP_PATH;
|
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.encryptedIndex = `${DUMP_PATH}/${this.permanentIndexName}.enc`;
|
this.encryptedIndex = `${DUMP_PATH}/${this.permanentIndexName}.enc`;
|
||||||
this.dataFolder = searchConfig.FOLDERS_CONSTANTS.INDEX_PATH;
|
this.dataFolder = searchConfig.FOLDERS_CONSTANTS.INDEX_PATH;
|
||||||
|
this.lz4Temp = `${DUMP_PATH}/${this.permanentIndexName}${searchConfig.TAR_LZ4_EXT}`;
|
||||||
|
this.decryptedTemp = `${DUMP_PATH}/decrypted${searchConfig.TAR_LZ4_EXT}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,7 +52,7 @@ class Crypto {
|
|||||||
if (response && response.stderr) {
|
if (response && response.stderr) {
|
||||||
log.send(logLevels.WARN, 'Crypto: Child process stderr while compression, ' + response.stderr);
|
log.send(logLevels.WARN, 'Crypto: Child process stderr while compression, ' + response.stderr);
|
||||||
}
|
}
|
||||||
const input = fs.createReadStream(`${this.dump}/${this.permanentIndexName}${searchConfig.TAR_LZ4_EXT}`);
|
const input = fs.createReadStream(this.lz4Temp);
|
||||||
const outputEncryption = fs.createWriteStream(this.encryptedIndex);
|
const outputEncryption = fs.createWriteStream(this.encryptedIndex);
|
||||||
let config = {
|
let config = {
|
||||||
key: key
|
key: key
|
||||||
@ -60,9 +61,9 @@ class Crypto {
|
|||||||
try {
|
try {
|
||||||
encrypt = crypto.encrypt(config);
|
encrypt = crypto.encrypt(config);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.send(logLevels.ERROR, 'Error decrypting : ' + e);
|
log.send(logLevels.ERROR, 'Error encrypting : ' + e);
|
||||||
if (fs.existsSync(`${this.dump}/${this.permanentIndexName}${searchConfig.TAR_LZ4_EXT}`)) {
|
if (fs.existsSync(this.lz4Temp)) {
|
||||||
fs.unlinkSync(`${this.dump}/${this.permanentIndexName}${searchConfig.TAR_LZ4_EXT}`);
|
fs.unlinkSync(this.lz4Temp);
|
||||||
}
|
}
|
||||||
reject();
|
reject();
|
||||||
return;
|
return;
|
||||||
@ -73,14 +74,14 @@ class Crypto {
|
|||||||
encryptionProcess.on('finish', (err) => {
|
encryptionProcess.on('finish', (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
log.send(logLevels.ERROR, 'Crypto: Error while encrypting the compressed file: ' + err);
|
log.send(logLevels.ERROR, 'Crypto: Error while encrypting the compressed file: ' + err);
|
||||||
if (fs.existsSync(`${this.dump}/${this.permanentIndexName}${searchConfig.TAR_LZ4_EXT}`)) {
|
if (fs.existsSync(this.lz4Temp)) {
|
||||||
fs.unlinkSync(`${this.dump}/${this.permanentIndexName}${searchConfig.TAR_LZ4_EXT}`);
|
fs.unlinkSync(this.lz4Temp);
|
||||||
}
|
}
|
||||||
reject(new Error(err));
|
reject(new Error(err));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (fs.existsSync(`${this.dump}/${this.permanentIndexName}${searchConfig.TAR_LZ4_EXT}`)) {
|
if (fs.existsSync(this.lz4Temp)) {
|
||||||
fs.unlinkSync(`${this.dump}/${this.permanentIndexName}${searchConfig.TAR_LZ4_EXT}`);
|
fs.unlinkSync(this.lz4Temp);
|
||||||
}
|
}
|
||||||
resolve('Success');
|
resolve('Success');
|
||||||
});
|
});
|
||||||
@ -103,7 +104,7 @@ class Crypto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const input = fs.createReadStream(this.encryptedIndex);
|
const input = fs.createReadStream(this.encryptedIndex);
|
||||||
const output = fs.createWriteStream(`${this.dump}/decrypted${searchConfig.TAR_LZ4_EXT}`);
|
const output = fs.createWriteStream(this.decryptedTemp);
|
||||||
let config = {
|
let config = {
|
||||||
key: this.key
|
key: this.key
|
||||||
};
|
};
|
||||||
@ -112,8 +113,8 @@ class Crypto {
|
|||||||
decrypt = crypto.decrypt(config);
|
decrypt = crypto.decrypt(config);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.send(logLevels.ERROR, 'Error decrypting : ' + e);
|
log.send(logLevels.ERROR, 'Error decrypting : ' + e);
|
||||||
if (fs.existsSync(`${this.dump}/decrypted${searchConfig.TAR_LZ4_EXT}`)) {
|
if (fs.existsSync(this.decryptedTemp)) {
|
||||||
fs.unlinkSync(`${this.dump}/decrypted${searchConfig.TAR_LZ4_EXT}`);
|
fs.unlinkSync(this.decryptedTemp);
|
||||||
}
|
}
|
||||||
reject();
|
reject();
|
||||||
return;
|
return;
|
||||||
@ -123,13 +124,13 @@ class Crypto {
|
|||||||
|
|
||||||
decryptionProcess.on('finish', () => {
|
decryptionProcess.on('finish', () => {
|
||||||
|
|
||||||
if (!fs.existsSync(`${this.dump}/decrypted${searchConfig.TAR_LZ4_EXT}`)){
|
if (!fs.existsSync(this.decryptedTemp)){
|
||||||
log.send(logLevels.ERROR, 'decrypted.tar.lz4 file not found');
|
log.send(logLevels.ERROR, 'decrypted.tar.lz4 file not found');
|
||||||
reject();
|
reject();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lz4.deCompression(`${this.dump}/decrypted${searchConfig.TAR_LZ4_EXT}`,(error, response) => {
|
lz4.deCompression(this.decryptedTemp,(error, response) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
log.send(logLevels.ERROR, 'Crypto: Error while deCompression, ' + error);
|
log.send(logLevels.ERROR, 'Crypto: Error while deCompression, ' + error);
|
||||||
// no return, need to unlink if error
|
// no return, need to unlink if error
|
||||||
@ -138,7 +139,7 @@ class Crypto {
|
|||||||
if (response && response.stderr) {
|
if (response && response.stderr) {
|
||||||
log.send(logLevels.WARN, 'Crypto: Child process stderr while deCompression, ' + response.stderr);
|
log.send(logLevels.WARN, 'Crypto: Child process stderr while deCompression, ' + response.stderr);
|
||||||
}
|
}
|
||||||
fs.unlink(`${this.dump}/decrypted${searchConfig.TAR_LZ4_EXT}`, () => {
|
fs.unlink(this.decryptedTemp, () => {
|
||||||
resolve('success');
|
resolve('success');
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user