Skip to content

Commit b8562d9

Browse files
authored
Revert "Add centralized request service" (#4829)
Revert "Add centralized request service (#4758)" This reverts commit 34c3fae.
1 parent 34c3fae commit b8562d9

File tree

8 files changed

+45
-202
lines changed

8 files changed

+45
-202
lines changed

CHANGELOG.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ All notable changes to the Wazuh app project will be documented in this file.
1414
- Added validation to the plugin settings in the form of `Settings/Configuration` and the endpoint to update the plugin configuration [#4503](https://github.com/wazuh/wazuh-kibana-app/pull/4503)[#4785](https://github.com/wazuh/wazuh-kibana-app/pull/4785)
1515
- Added new plugin settings to customize the header and footer on the PDF reports [#4505](https://github.com/wazuh/wazuh-kibana-app/pull/4505)[#4798](https://github.com/wazuh/wazuh-kibana-app/pull/4798)[#4805](https://github.com/wazuh/wazuh-kibana-app/pull/4805)
1616
- Add a new plugin setting to enable or disable the customization [#4507](https://github.com/wazuh/wazuh-kibana-app/pull/4507)
17-
- Added a centralized service to handle the requestrs [#4758](https://github.com/wazuh/wazuh-kibana-app/pull/4758)
1817

1918
### Changed
2019

@@ -49,11 +48,10 @@ commands of Start the agent in the deploy new agent section [#4458](https://gith
4948
- Fixed nested field rendering in security alerts table details [#4428](https://github.com/wazuh/wazuh-kibana-app/pull/4428)
5049
- Fixed a bug where the Wazuh logo was used instead of the custom one [#4539](https://github.com/wazuh/wazuh-kibana-app/pull/4539)
5150
- Fixed rendering problems of the `Agent Overview` section in low resolutions [#4516](https://github.com/wazuh/wazuh-kibana-app/pull/4516)
52-
- Fixed issue when logging out from Wazuh when SAML is enabled [#4664](https://github.com/wazuh/wazuh-kibana-app/pull/4664)
51+
- Fixed issue when logging out from Wazuh when SAML is enabled [#4595](https://github.com/wazuh/wazuh-kibana-app/issues/4595)
5352
- Fixed server errors with code 500 when the Wazuh API is not reachable / up. [#4710](https://github.com/wazuh/wazuh-kibana-app/pull/4710) [#4728](https://github.com/wazuh/wazuh-kibana-app/pull/4728)
5453
- Fixed pagination to SCA table [#4653](https://github.com/wazuh/wazuh-kibana-app/issues/4653)
5554
- Fixed a bug that caused the flyouts to close when clicking inside them [#4638](https://github.com/wazuh/wazuh-kibana-app/pull/4638)
56-
- Fixed a bug that caused the main Office 365 dashboard to display an incorrect Max rule level [#4508](https://github.com/wazuh/wazuh-kibana-app/pull/4508)
5755

5856
## Wazuh v4.3.9 - OpenSearch Dashboards 1.2.0 - Revision 4310
5957

public/plugin.ts

-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { getThemeAssetURL, getAssetURL } from './utils/assets';
3131
import { WzRequest } from './react-services/wz-request';
3232
import store from './redux/store';
3333
import { updateAppConfig } from './redux/actions/appConfigActions';
34-
import { initializeInterceptor } from './services/request-handler';
3534

3635
const SIDEBAR_LOGO = 'customization.logo.sidebar';
3736
const innerAngularName = 'app/wazuh';
@@ -165,7 +164,6 @@ export class WazuhPlugin implements Plugin<WazuhSetup, WazuhStart, WazuhSetupPlu
165164
setSavedObjects(core.savedObjects);
166165
setOverlays(core.overlays);
167166
setErrorOrchestrator(ErrorOrchestratorService);
168-
initializeInterceptor();
169167
return {};
170168
}
171169
}

public/react-services/generic-request.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
* Find more information about this on the LICENSE file.
1111
*/
1212

13+
import axios from 'axios';
1314
import { AppState } from './app-state';
1415
import { WazuhConfig } from './wazuh-config';
1516
import { ApiCheck } from './wz-api-check';
1617
import { WzMisc } from '../factories/misc';
1718
import { OdfeUtils } from '../utils';
1819
import { getHttp, getDataPlugin } from '../kibana-services';
1920
import { PLUGIN_PLATFORM_REQUEST_HEADERS } from '../../common/constants';
20-
import { request } from '../services/request-handler';
2121

2222
export class GenericRequest {
2323
static async request(method, path, payload = null, returnError = false) {
@@ -33,9 +33,9 @@ export class GenericRequest {
3333
};
3434
const tmpUrl = getHttp().basePath.prepend(path);
3535

36-
try {
36+
try{
3737
requestHeaders.pattern = (await getDataPlugin().indexPatterns.get(AppState.getCurrentPattern())).title;
38-
} catch (error) { };
38+
}catch(error){};
3939

4040
try {
4141
requestHeaders.id = JSON.parse(AppState.getCurrentAPI()).id;
@@ -48,36 +48,40 @@ export class GenericRequest {
4848
if (method === 'GET') {
4949
options = {
5050
method: method,
51-
path: path,
51+
headers: requestHeaders,
52+
url: tmpUrl,
5253
timeout: timeout || 20000
5354
};
5455
}
5556
if (method === 'PUT') {
5657
options = {
5758
method: method,
59+
headers: requestHeaders,
5860
data: payload,
59-
path: path,
61+
url: tmpUrl,
6062
timeout: timeout || 20000
6163
};
6264
}
6365
if (method === 'POST') {
6466
options = {
6567
method: method,
68+
headers: requestHeaders,
6669
data: payload,
67-
path: path,
70+
url: tmpUrl,
6871
timeout: timeout || 20000
6972
};
7073
}
7174
if (method === 'DELETE') {
7275
options = {
7376
method: method,
77+
headers: requestHeaders,
7478
data: payload,
75-
path: path,
79+
url: tmpUrl,
7680
timeout: timeout || 20000
7781
};
7882
}
7983

80-
Object.assign(data, await request(options));
84+
Object.assign(data, await axios(options));
8185
if (!data) {
8286
throw new Error(
8387
`Error doing a request to ${tmpUrl}, method: ${method}.`
@@ -96,9 +100,9 @@ export class GenericRequest {
96100
const wzMisc = new WzMisc();
97101
wzMisc.setApiIsDown(true);
98102

99-
if (!window.location.hash.includes('#/settings') &&
100-
!window.location.hash.includes('#/health-check') &&
101-
!window.location.hash.includes('#/blank-screen')) {
103+
if (!window.location.hash.includes('#/settings') &&
104+
!window.location.hash.includes('#/health-check') &&
105+
!window.location.hash.includes('#/blank-screen')) {
102106
window.location.href = getHttp().basePath.prepend('/app/wazuh#/health-check');
103107
}
104108
}

public/react-services/wz-api-check.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
* Find more information about this on the LICENSE file.
1111
*/
1212
import { WazuhConfig } from './wazuh-config';
13+
import axios from 'axios';
1314
import { AppState } from './app-state';
1415
import { WzMisc } from '../factories/misc';
1516
import { getHttp } from '../kibana-services';
16-
import { request } from '../services/request-handler';
17+
import { PLUGIN_PLATFORM_REQUEST_HEADERS } from '../../common/constants';
1718

1819
export class ApiCheck {
1920
static async checkStored(data, idChanged = false) {
@@ -29,7 +30,8 @@ export class ApiCheck {
2930
const url = getHttp().basePath.prepend('/api/check-stored-api');
3031
const options = {
3132
method: 'POST',
32-
path: '/api/check-stored-api',
33+
headers: { ...PLUGIN_PLATFORM_REQUEST_HEADERS, 'content-type': 'application/json' },
34+
url: url,
3335
data: payload,
3436
timeout: timeout || 20000
3537
};
@@ -38,7 +40,7 @@ export class ApiCheck {
3840
AppState.setPatternSelector(configuration['ip.selector']);
3941
}
4042

41-
const response = await request(options);
43+
const response = await axios(options);
4244

4345
if (response.error) {
4446
return Promise.reject(response);
@@ -63,20 +65,21 @@ export class ApiCheck {
6365
* Check the status of an API entry
6466
* @param {String} apiObject
6567
*/
66-
static async checkApi(apiEntry, forceRefresh = false) {
68+
static async checkApi(apiEntry, forceRefresh=false) {
6769
try {
6870
const wazuhConfig = new WazuhConfig();
6971
const { timeout } = wazuhConfig.getConfig();
7072
const url = getHttp().basePath.prepend('/api/check-api');
7173

7274
const options = {
7375
method: 'POST',
74-
path: '/api/check-api',
75-
data: { ...apiEntry, forceRefresh },
76+
headers: { ...PLUGIN_PLATFORM_REQUEST_HEADERS, 'content-type': 'application/json' },
77+
url: url,
78+
data: {...apiEntry, forceRefresh},
7679
timeout: timeout || 20000
7780
};
7881

79-
const response = await request(options);
82+
const response = await axios(options);
8083

8184
if (response.error) {
8285
return Promise.reject(response);

public/react-services/wz-request.ts

+18-14
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*
1010
* Find more information about this on the LICENSE file.
1111
*/
12+
import axios from 'axios';
1213
import { AppState } from './app-state';
1314
import { ApiCheck } from './wz-api-check';
1415
import { WzAuthentication } from './wz-authentication';
@@ -17,7 +18,7 @@ import { WazuhConfig } from './wazuh-config';
1718
import { OdfeUtils } from '../utils';
1819
import IApiResponse from './interfaces/api-response.interface';
1920
import { getHttp } from '../kibana-services';
20-
import { request } from '../services/request-handler';
21+
import { PLUGIN_PLATFORM_REQUEST_HEADERS } from '../../common/constants';
2122
export class WzRequest {
2223
static wazuhConfig: any;
2324

@@ -31,13 +32,15 @@ export class WzRequest {
3132
method,
3233
path,
3334
payload: any = null,
34-
extraOptions: { shouldRetry?: boolean, checkCurrentApiIsUp?: boolean } = {
35-
shouldRetry: true,
36-
checkCurrentApiIsUp: true
35+
extraOptions: { shouldRetry?: boolean, checkCurrentApiIsUp?: boolean, overwriteHeaders?: any } = {
36+
shouldRetry: true,
37+
checkCurrentApiIsUp: true,
38+
overwriteHeaders: {}
3739
}
3840
) {
39-
const shouldRetry = typeof extraOptions.shouldRetry === 'boolean' ? extraOptions.shouldRetry : true;
41+
const shouldRetry = typeof extraOptions.shouldRetry === 'boolean' ? extraOptions.shouldRetry : true;
4042
const checkCurrentApiIsUp = typeof extraOptions.checkCurrentApiIsUp === 'boolean' ? extraOptions.checkCurrentApiIsUp : true;
43+
const overwriteHeaders = typeof extraOptions.overwriteHeaders === 'object' ? extraOptions.overwriteHeaders : {};
4144
try {
4245
if (!method || !path) {
4346
throw new Error('Missing parameters');
@@ -49,12 +52,13 @@ export class WzRequest {
4952
const url = getHttp().basePath.prepend(path);
5053
const options = {
5154
method: method,
52-
path: path,
55+
headers: { ...PLUGIN_PLATFORM_REQUEST_HEADERS, 'content-type': 'application/json', ...overwriteHeaders },
56+
url: url,
5357
data: payload,
5458
timeout: timeout,
5559
};
5660

57-
const data = await request(options);
61+
const data = await axios(options);
5862

5963
if (data['error']) {
6064
throw new Error(data['error']);
@@ -64,7 +68,7 @@ export class WzRequest {
6468
} catch (error) {
6569
OdfeUtils.checkOdfeSessionExpired(error);
6670
//if the requests fails, we need to check if the API is down
67-
if (checkCurrentApiIsUp) {
71+
if(checkCurrentApiIsUp){
6872
const currentApi = JSON.parse(AppState.getCurrentAPI() || '{}');
6973
if (currentApi && currentApi.id) {
7074
try {
@@ -98,7 +102,7 @@ export class WzRequest {
98102
}
99103
return errorMessage
100104
? Promise.reject(this.returnErrorInstance(error, errorMessage))
101-
: Promise.reject(this.returnErrorInstance(error, 'Server did not respond'));
105+
: Promise.reject(this.returnErrorInstance(error,'Server did not respond'));
102106
}
103107
}
104108

@@ -109,9 +113,9 @@ export class WzRequest {
109113
* @param {Object} body Request body
110114
*/
111115
static async apiReq(
112-
method,
113-
path,
114-
body,
116+
method,
117+
path,
118+
body,
115119
options: { checkCurrentApiIsUp?: boolean } = { checkCurrentApiIsUp: true }
116120
): Promise<IApiResponse<any>> {
117121
try {
@@ -168,8 +172,8 @@ export class WzRequest {
168172
* @param message
169173
* @returns error
170174
*/
171-
static returnErrorInstance(error, message) {
172-
if (!error || typeof error === 'string') {
175+
static returnErrorInstance(error, message){
176+
if(!error || typeof error === 'string'){
173177
return new Error(message || error);
174178
}
175179
error.message = message

public/services/request-handler.js

-89
This file was deleted.

0 commit comments

Comments
 (0)