Skip to content

Commit

Permalink
Check for duplicated API keys
Browse files Browse the repository at this point in the history
  • Loading branch information
adri9valle committed Jul 29, 2019
1 parent a6f7929 commit 99563d9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
17 changes: 16 additions & 1 deletion public/controllers/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ export class SettingsController {
for (const key in this.showEditForm) this.showEditForm[key] = false;
this.$scope.$emit('updateAPI', {});
this.errorHandler.info('The API was removed successfully', 'Settings');
//this.apiTableProps.apiEntries = this.apiTableProps.apiEntries;
this.$scope.$applyAsync();
} catch (error) {
this.errorHandler.handle('Could not remove the API', 'Settings');
Expand Down Expand Up @@ -262,10 +261,26 @@ export class SettingsController {
}
}

checkNotDuplicatedApis(apis) {
try {
const keys = apis.map(api => { return Object.keys(api)[0] });
const cleanKeys = [...new Set(keys)];
if (keys.length !== cleanKeys.length){
this.duplicatedApisKeys = true;
this.errMsg = 'Please check the config.yml file, there were found duplicated APIs keys.'
}
return
} catch (error) {
console.error('Error checking duplicated APIs keys');
throw error;
}
}

// Get settings function
async getSettings() {
try {
const data = await this.genericReq.request('GET', '/api/apis');
this.checkNotDuplicatedApis(data.data);
let result = [];
for (const entry of data.data) {
const id = Object.keys(entry)[0];
Expand Down
14 changes: 12 additions & 2 deletions public/templates/settings/settings-api.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,23 @@
</span>
</div>
<!-- End headline -->
<div layout="row" layout-padding ng-if="ctrl.apiTableProps.apiEntries.length">
<div layout="row" layout-padding ng-if="ctrl.apiTableProps.apiEntries.length && !ctrl.duplicatedApisKeys">
<react-component name="ApiTable" props="ctrl.apiTableProps" />
</div>
<div ng-ig="ctrl.duplicatedApisKeys">
<div flex class="euiCallOut euiCallOut--warning md-margin-h">
<div class="euiCallOutHeader">
<span class="euiCallOutHeader__title">
<react-component name="EuiIcon" props="{type:'help'}" />
{{ctrl.errMsg}}
</span>
</div>
</div>
</div>

<!-- Add API section-->
<div layout="row" layout-padding
ng-if="!currentAPI || (ctrl.addManagerContainer && !ctrl.isEditing) || !ctrl.apiTableProps.apiEntries.length">
ng-if="(!currentAPI || (ctrl.addManagerContainer && !ctrl.isEditing) || !ctrl.apiTableProps.apiEntries.length) && !ctrl.duplicatedApisKeys">
<react-component flex name="AddApi" props="ctrl.addApiProps" />
<!-- End add API form -->
</div>
Expand Down
3 changes: 0 additions & 3 deletions server/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@ export function Initialize(server) {
log('initialize:checkWazuhIndex', 'Checking if .wazuh index exists.', 'debug');

const result = await wzWrapper.checkIfIndexExists('.wazuh');

//const shardConfiguration = BuildBody(configurationFile, 'wazuh');

if (result) {
try {
const data = await wzWrapper.getWazuhAPIEntries();
Expand Down

0 comments on commit 99563d9

Please sign in to comment.