Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix routes resolvers circular redirections - infinite loop #4079

Merged
merged 4 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Fixed error not working the alerts displayed when changin the selected time in some flyouts [#3947](https://github.com/wazuh/wazuh-kibana-app/pull/3947)
- Fixed the user can not logout when the Kibana server has a basepath configurated [#3957](https://github.com/wazuh/wazuh-kibana-app/pull/3957)
- Fixed fatal cron-job error when Wazuh API is down [#3991](https://github.com/wazuh/wazuh-kibana-app/pull/3991)
- Fixed circular re-directions when API errors are handled [#4079](https://github.com/wazuh/wazuh-kibana-app/pull/4079)
- Fixed agent breadcrumb routing minor error [#4101](https://github.com/wazuh/wazuh-kibana-app/pull/4101)
- Fixed selected text not visible in API Console [#4102](https://github.com/wazuh/wazuh-kibana-app/pull/4102)

Expand Down
11 changes: 9 additions & 2 deletions public/components/health-check/services/check-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const trySetDefault = async (checkLogger: CheckLogger) => {
return Promise.reject('No API available to connect');
}
}
return Promise.reject('No API configuration found');
} catch (error) {
checkLogger.error(`Error connecting to API: ${error}`);
return Promise.reject(`Error connecting to API: ${error}`);
Expand All @@ -50,7 +51,13 @@ const trySetDefault = async (checkLogger: CheckLogger) => {
export const checkApiService = (appInfo: any) => async (checkLogger: CheckLogger) => {
let apiChanged = false;
try {
const currentApi = JSON.parse(AppState.getCurrentAPI() || '{}');
let currentApi = JSON.parse(AppState.getCurrentAPI() || '{}');
if(!currentApi.id){
checkLogger.info(`No current API selected`);
currentApi.id = await trySetDefault(checkLogger);
apiChanged = true;
}

checkLogger.info(`Current API id [${currentApi.id}]`);
checkLogger.info(`Checking current API id [${currentApi.id}]...`);
const data = await ApiCheck.checkStored(currentApi.id).catch(async (err) => {
Expand All @@ -68,7 +75,7 @@ export const checkApiService = (appInfo: any) => async (checkLogger: CheckLogger
const api = ((data || {}).data || {}).data || {};
const name = (api.cluster_info || {}).manager || false;
AppState.setCurrentAPI(JSON.stringify({ name: name, id: api.id }));
checkLogger.info(`Set current API in cookie: id [${api.id}], name [${api.name}]`);
checkLogger.info(`Set current API in cookie: id [${api.id}], name [${name}]`);
getToasts().add({
color: 'warning',
title: 'Selected Wazuh API has been updated',
Expand Down
4 changes: 3 additions & 1 deletion public/react-services/generic-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ export class GenericRequest {
const wzMisc = new WzMisc();
wzMisc.setApiIsDown(true);

if (!window.location.hash.includes('#/settings')) {
if (!window.location.hash.includes('#/settings') &&
!window.location.hash.includes('#/health-check') &&
!window.location.hash.includes('#/blank-screen')) {
window.location.href = getHttp().basePath.prepend('/app/wazuh#/health-check');
}
}
Expand Down
64 changes: 0 additions & 64 deletions public/services/resolves/api-count.js

This file was deleted.

2 changes: 0 additions & 2 deletions public/services/resolves/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { settingsWizard } from './settings-wizard';
import { getSavedSearch } from './get-saved-search';
import { getIp } from './get-ip';
import { getWzConfig } from './get-config';
import { apiCount } from './api-count';

export {
checkTimestamp,
Expand All @@ -24,5 +23,4 @@ export {
getSavedSearch,
getIp,
getWzConfig,
apiCount
};
3 changes: 2 additions & 1 deletion public/services/resolves/settings-wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ export function settingsWizard(
wzMisc.setWizard(true);
if (redirect) {
AppState.setCurrentAPI(redirect);
} else if (!$location.path().includes('/settings')) {
} else if (!$location.path().includes('/settings') &&
!$location.path().includes('/blank-screen')) {
$location.search('_a', null);
$location.search('tab', 'api');
$location.path('/settings');
Expand Down
5 changes: 2 additions & 3 deletions public/services/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
getSavedSearch,
getIp,
getWzConfig,
apiCount
} from './resolves';

// HTML templates
Expand Down Expand Up @@ -125,7 +124,7 @@ app.config(($routeProvider) => {
$routeProvider
.when('/health-check', {
template: healthCheckTemplate,
resolve: { apiCount, wzConfig, ip },
resolve: { wzConfig, ip },
outerAngularWrapperRoute: true
})
.when('/agents/:agent?/:tab?/:tabView?', {
Expand Down Expand Up @@ -175,7 +174,7 @@ app.config(($routeProvider) => {
})
.when('/blank-screen', {
template: blankScreenTemplate,
resolve: { enableWzMenu, wzConfig },
resolve: { enableWzMenu },
outerAngularWrapperRoute: true
})
.when('/', {
Expand Down