SEARCH-440

- Review comments push
This commit is contained in:
Keerthi Niranjan 2017-11-28 16:14:13 +05:30
parent 3e898eca46
commit f500a3b5ce
2 changed files with 10 additions and 12 deletions

View File

@ -13,9 +13,8 @@ const DUMP_PATH = isDevEnv ? path.join(__dirname, '..', '..') : searchConfig.FOL
class Crypto {
constructor(userId, key) {
this.indexDataFolder = searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH +
'_' + userId + '_' + searchConfig.INDEX_VERSION;
this.permanentIndexName = searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME + '_' + 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.dump = DUMP_PATH;
this.key = key;
this.encryptedIndex = `${DUMP_PATH}/${this.permanentIndexName}.enc`;
@ -31,7 +30,7 @@ class Crypto {
return new Promise((resolve, reject) => {
if (!fs.existsSync(this.indexDataFolder)){
log.send(logLevels.ERROR, 'user index folder not found');
log.send(logLevels.ERROR, 'Crypto: User index folder not found');
reject();
return;
}
@ -39,13 +38,13 @@ class Crypto {
lz4.compression(`${searchConfig.FOLDERS_CONSTANTS.INDEX_FOLDER_NAME}/${this.permanentIndexName}`,
`${this.permanentIndexName}`, (error, response) => {
if (error) {
log.send(logLevels.ERROR, 'lz4 compression error: ' + error);
log.send(logLevels.ERROR, 'Crypto: Error while compressing to lz4: ' + error);
reject(error);
return;
}
if (response && response.stderr) {
log.send(logLevels.WARN, 'compression stderr, ' + 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 outputEncryption = fs.createWriteStream(this.encryptedIndex);
@ -58,7 +57,7 @@ class Crypto {
encryptionProcess.on('finish', (err) => {
if (err) {
log.send(logLevels.ERROR, 'encryption error: ' + err);
log.send(logLevels.ERROR, 'Crypto: Error while encrypting the compressed file: ' + err);
reject(new Error(err));
return;
}
@ -78,7 +77,7 @@ class Crypto {
return new Promise((resolve, reject) => {
if (!fs.existsSync(this.encryptedIndex)){
log.send(logLevels.ERROR, 'encrypted file not found');
log.send(logLevels.ERROR, 'Crypto: Encrypted file not found');
reject();
return;
}
@ -102,12 +101,12 @@ class Crypto {
lz4.deCompression(`${this.dump}/decrypted${searchConfig.TAR_LZ4_EXT}`,(error, response) => {
if (error) {
log.send(logLevels.ERROR, 'lz4 deCompression error, ' + error);
log.send(logLevels.ERROR, 'Crypto: Error while deCompression, ' + error);
// no return, need to unlink if error
}
if (response && response.stderr) {
log.send(logLevels.WARN, 'deCompression stderr, ' + response.stderr);
log.send(logLevels.WARN, 'Crypto: Child process stderr while deCompression, ' + response.stderr);
}
fs.unlink(`${this.dump}/decrypted${searchConfig.TAR_LZ4_EXT}`, () => {
resolve('success');

View File

@ -31,8 +31,7 @@ class Search {
this.isInitialized = false;
this.userId = userId;
this.key = key;
this.indexFolderName = searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH +
'_' + this.userId + '_' + searchConfig.INDEX_VERSION;
this.indexFolderName = `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH}_${this.userId}_${searchConfig.INDEX_VERSION}`;
this.dataFolder = searchConfig.FOLDERS_CONSTANTS.INDEX_PATH;
this.realTimeIndex = searchConfig.FOLDERS_CONSTANTS.TEMP_REAL_TIME_INDEX;
this.batchIndex = searchConfig.FOLDERS_CONSTANTS.TEMP_BATCH_INDEX_FOLDER;