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

TypeError resolved #4362

Merged
merged 7 commits into from
Aug 5, 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 @@ -7,6 +7,7 @@ All notable changes to the Wazuh app project will be documented in this file.
### Fixed

- Fixed path in logo customization section [#4352](https://github.com/wazuh/wazuh-kibana-app/pull/4352)
- Fixed a TypeError in Firefox. Change the Get request that was made with a Kibana core.http.get(/api/check-wazuh) resource to the WzRequest.genericReq resource and it no longer fails, also add a test capture to public/plugin.ts that wraps the request and in case of failure, the error is detected when the browser does not work with the V8 engine. [#4362](https://github.com/wazuh/wazuh-kibana-app/pull/4362)
- Fixed an error of an undefined username hash related to reporting when using Kibana with X-Pack and security was disabled [#4358](https://github.com/wazuh/wazuh-kibana-app/pull/4358)

## Wazuh v4.3.6 - Kibana 7.10.2, 7.16.x, 7.17.x - Revision 4307
Expand Down
102 changes: 48 additions & 54 deletions public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,70 +28,68 @@ import { AppState } from './react-services/app-state';
import { setErrorOrchestrator } from './react-services/common-services';
import { ErrorOrchestratorService } from './react-services/error-orchestrator/error-orchestrator.service';
import { getThemeAssetURL, getAssetURL } from './utils/assets';

import { WzRequest } from './react-services/wz-request';
const innerAngularName = 'app/wazuh';

export class WazuhPlugin implements Plugin<WazuhSetup, WazuhStart, WazuhSetupPlugins, WazuhStartPlugins> {
constructor(private readonly initializerContext: PluginInitializerContext) {}
public initializeInnerAngular?: () => void;
private innerAngularInitialized: boolean = false;
private stateUpdater = new BehaviorSubject<AppUpdater>(() => ({}));
private hideTelemetryBanner?: () => void;

public setup(core: CoreSetup, plugins: WazuhSetupPlugins): WazuhSetup {
const UI_THEME = core.uiSettings.get('theme:darkMode') ? 'dark' : 'light';

core.application.register({
id: `wazuh`,
title: 'Wazuh',
icon: core.http.basePath.prepend(getThemeAssetURL('icon.svg', UI_THEME)),
mount: async (params: AppMountParameters) => {
if (!this.initializeInnerAngular) {
throw Error('Wazuh plugin method initializeInnerAngular is undefined');
}

// hide the telemetry banner.
// Set the flag in the telemetry saved object as the notice was seen and dismissed
this.hideTelemetryBanner && await this.hideTelemetryBanner();

setScopedHistory(params.history);
// Load application bundle
const { renderApp } = await import('./application');
// Get start services as specified in kibana.json
const [coreStart, depsStart] = await core.getStartServices();
setErrorOrchestrator(ErrorOrchestratorService);
setHttp(core.http);
setCookies(new Cookies());
if(!AppState.checkCookies() || params.history.parentHistory.action === 'PUSH') {
window.location.reload();
}

await this.initializeInnerAngular();

//Check is user has Wazuh disabled
const response = await core.http.get(`/api/check-wazuh`);

params.element.classList.add('dscAppWrapper', 'wz-app');
const unmount = await renderApp(innerAngularName, params.element);

//Update if user has Wazuh disabled
this.stateUpdater.next(() => {
if (response.isWazuhDisabled) {
unmount();
try {
if (!this.initializeInnerAngular) {
throw Error('Wazuh plugin method initializeInnerAngular is undefined');
}

return {
status: response.isWazuhDisabled,
category: {
id: 'wazuh',
label: 'Wazuh',
order: 0,
euiIconType: core.http.basePath.prepend(response.logoSidebar ? getAssetURL(response.logoSidebar) : getThemeAssetURL('icon.svg', UI_THEME)),
}}
})
return () => {
unmount();
};
// hide the telemetry banner.
// Set the flag in the telemetry saved object as the notice was seen and dismissed
this.hideTelemetryBanner && await this.hideTelemetryBanner();
setScopedHistory(params.history);
// Load application bundle
const { renderApp } = await import('./application');
// Get start services as specified in kibana.json
const [coreStart, depsStart] = await core.getStartServices();
setErrorOrchestrator(ErrorOrchestratorService);
setHttp(core.http);
setCookies(new Cookies());
if(!AppState.checkCookies() || params.history.parentHistory.action === 'PUSH') {
window.location.reload();
}
await this.initializeInnerAngular();
//Check is user has Wazuh disabled
const response = await WzRequest.genericReq(
'GET',
`/api/check-wazuh`,
)

params.element.classList.add('dscAppWrapper', 'wz-app');
const unmount = await renderApp(innerAngularName, params.element);
//Update if user has Wazuh disabled
this.stateUpdater.next(() => {
if (response.data.isWazuhDisabled) {
unmount();
}
return {
status: response.data.isWazuhDisabled,
category: {
id: 'wazuh',
label: 'Wazuh',
order: 0,
euiIconType: core.http.basePath.prepend(response.data.logoSidebar ? getAssetURL(response.data.logoSidebar) : getThemeAssetURL('icon.svg', UI_THEME)),
}}
})
return () => {
unmount();
};
}catch(error){
console.debug(error);
}
},
category: {
id: 'wazuh',
Expand All @@ -103,13 +101,11 @@ export class WazuhPlugin implements Plugin<WazuhSetup, WazuhStart, WazuhSetupPlu
});
return {};
}

public start(core: CoreStart, plugins: AppPluginStartDependencies): WazuhStart {
// hide security alert
if(plugins.securityOss) {
plugins.securityOss.insecureCluster.hideAlert(true);
};

if(plugins?.telemetry?.telemetryNotifications?.setOptedInNoticeSeen) {
// assign to a method to hide the telemetry banner used when the app is mounted
this.hideTelemetryBanner = () => plugins.telemetry.telemetryNotifications.setOptedInNoticeSeen();
Expand All @@ -133,8 +129,6 @@ export class WazuhPlugin implements Plugin<WazuhSetup, WazuhStart, WazuhSetupPlu
setAngularModule(module);
this.innerAngularInitialized = true;
};


setCore(core);
setPlugins(plugins);
setHttp(core.http);
Expand All @@ -149,4 +143,4 @@ export class WazuhPlugin implements Plugin<WazuhSetup, WazuhStart, WazuhSetupPlu
setErrorOrchestrator(ErrorOrchestratorService);
return {};
}
}
}