Skip to content

Commit

Permalink
Checks if all the APIs were migrated properly
Browse files Browse the repository at this point in the history
  • Loading branch information
adri9valle committed Jul 29, 2019
1 parent 5e6e4d6 commit e1dad8d
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions server/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,12 @@ export function Initialize(server) {
const apiEntries = (((data || {}).hits || {}).hits || []);
await updateConfigurationFile.migrateFromIndex(apiEntries)
log('initialize:checkWazuhIndex', 'Index .wazuh will be removed and its content will be migrated to config.yml', 'debug');
// Delete the documents stored in the index .wazuh
await wzWrapper.deleteDocumentsInIndex('.wazuh');
// Check if all APIs entries were migrated properly and delete it from the .wazuh index
if (await checkProperlyMigrate()){
await wzWrapper.deleteDocumentsInIndex('.wazuh');
} else {
throw new Error('Cannot migrate all APIs from .wazuh index to the config.yml file properly.');
}
log('initialize:checkWazuhIndex', 'Content of index .wazuh deleted.', 'debug');
} catch (error) {
throw new Error('Error deleting index .wazuh. ' + error);
Expand All @@ -212,6 +216,25 @@ export function Initialize(server) {
}
};

// Checks if all the APIs were migrated
const checkProperlyMigrate = async () => {
let apisIndex = await wzWrapper.getWazuhAPIEntries();
let apisConfig = await updateConfigurationFile.getHosts();
apisIndex = (apisIndex.hits || {}).hits || [];

const apisIndexKeys = apisIndex.map(api => {
return api._id;
});

const apisConfigKeys = apisConfig.map(api => {
return Object.keys(api)[0];
});

apisIndexKeys.map(k => {
if (!apisConfigKeys.includes(k)) throw new Error('Cannot migrate all the APIs entries.');
});
}

const checkWazuhVersionRegistry = async () => {
try {
log(
Expand Down

0 comments on commit e1dad8d

Please sign in to comment.