SEARCH-539 & SEARCH-206

- Removed the version
This commit is contained in:
Keerthi Niranjan 2017-12-19 15:06:37 +05:30
parent f67fb1db2e
commit 867fe40d72
2 changed files with 17 additions and 20 deletions

View File

@ -16,14 +16,12 @@ class Crypto {
* Constructor * Constructor
* @param userId * @param userId
* @param key * @param key
* @param version
*/ */
constructor(userId, key, version) { constructor(userId, key) {
this.indexDataFolder = `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH}_${userId}`; this.indexDataFolder = `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH}_${userId}_${searchConfig.INDEX_VERSION}`;
this.permanentIndexName = `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${userId}`; 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.version = version;
this.encryptedIndex = `${DUMP_PATH}/${this.permanentIndexName}`; this.encryptedIndex = `${DUMP_PATH}/${this.permanentIndexName}`;
this.dataFolder = searchConfig.FOLDERS_CONSTANTS.INDEX_PATH; this.dataFolder = searchConfig.FOLDERS_CONSTANTS.INDEX_PATH;
} }
@ -33,17 +31,17 @@ class Crypto {
* encrypting it * encrypting it
* @returns {Promise} * @returns {Promise}
*/ */
encryption(key, version) { encryption(key) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!fs.existsSync(`${this.indexDataFolder}_${version}`)){ if (!fs.existsSync(this.indexDataFolder)){
log.send(logLevels.ERROR, 'Crypto: User index folder not found'); log.send(logLevels.ERROR, 'Crypto: User index folder not found');
reject(); reject();
return; return;
} }
lz4.compression(`${searchConfig.FOLDERS_CONSTANTS.INDEX_FOLDER_NAME}/${this.permanentIndexName}_${version}`, lz4.compression(`${searchConfig.FOLDERS_CONSTANTS.INDEX_FOLDER_NAME}/${this.permanentIndexName}`,
`${this.permanentIndexName}_${version}`, (error, response) => { `${this.permanentIndexName}`, (error, response) => {
if (error) { if (error) {
log.send(logLevels.ERROR, 'Crypto: Error while compressing to lz4: ' + error); log.send(logLevels.ERROR, 'Crypto: Error while compressing to lz4: ' + error);
reject(error); reject(error);
@ -53,8 +51,8 @@ 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}_${version}${searchConfig.TAR_LZ4_EXT}`); const input = fs.createReadStream(`${this.dump}/${this.permanentIndexName}${searchConfig.TAR_LZ4_EXT}`);
const outputEncryption = fs.createWriteStream(`${this.encryptedIndex}_${version}.enc`); const outputEncryption = fs.createWriteStream(`${this.encryptedIndex}.enc`);
let config = { let config = {
key: key key: key
}; };
@ -68,7 +66,7 @@ class Crypto {
reject(new Error(err)); reject(new Error(err));
return; return;
} }
fs.unlinkSync(`${this.dump}/${this.permanentIndexName}_${version}${searchConfig.TAR_LZ4_EXT}`); fs.unlinkSync(`${this.dump}/${this.permanentIndexName}${searchConfig.TAR_LZ4_EXT}`);
resolve('Success'); resolve('Success');
}); });
}); });
@ -83,13 +81,13 @@ class Crypto {
decryption() { decryption() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!fs.existsSync(`${this.encryptedIndex}_${this.version}.enc`)){ if (!fs.existsSync(`${this.encryptedIndex}.enc`)){
log.send(logLevels.ERROR, 'Crypto: Encrypted file not found'); log.send(logLevels.ERROR, 'Crypto: Encrypted file not found');
reject(); reject();
return; return;
} }
const input = fs.createReadStream(`${this.encryptedIndex}_${this.version}.enc`); const input = fs.createReadStream(`${this.encryptedIndex}.enc`);
const output = fs.createWriteStream(`${this.dump}/decrypted${searchConfig.TAR_LZ4_EXT}`); const output = fs.createWriteStream(`${this.dump}/decrypted${searchConfig.TAR_LZ4_EXT}`);
let config = { let config = {
key: this.key key: this.key

View File

@ -26,19 +26,18 @@ class Search {
* Constructor for the SymphonySearchEngine library * Constructor for the SymphonySearchEngine library
* @param userId (for the index folder name) * @param userId (for the index folder name)
* @param key * @param key
* @param version
*/ */
constructor(userId, key, version) { constructor(userId, key) {
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.userId}_${version}`; this.indexFolderName = `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH}_${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;
this.messageData = []; this.messageData = [];
this.isRealTimeIndexing = false; this.isRealTimeIndexing = false;
this.crypto = new Crypto(userId, key, version); this.crypto = new Crypto(userId, key);
this.decryptAndInit(); this.decryptAndInit();
this.collector = makeBoundTimedCollector(this.checkIsRealTimeIndexing.bind(this), this.collector = makeBoundTimedCollector(this.checkIsRealTimeIndexing.bind(this),
searchConfig.REAL_TIME_INDEXING_TIME, this.realTimeIndexing.bind(this)); searchConfig.REAL_TIME_INDEXING_TIME, this.realTimeIndexing.bind(this));
@ -235,8 +234,8 @@ class Search {
* Encrypting the index after the merging the index * Encrypting the index after the merging the index
* to the main user index * to the main user index
*/ */
encryptIndex(key, version) { encryptIndex(key) {
return this.crypto.encryption(key, version).then(() => { return this.crypto.encryption(key).then(() => {
return 'Success' return 'Success'
}).catch((e) => { }).catch((e) => {
log.send(logLevels.ERROR, 'Encrypting the index folder failed ->' + e); log.send(logLevels.ERROR, 'Encrypting the index folder failed ->' + e);