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

View File

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