Skip to content

Commit

Permalink
Initialize Wazuh plugin with custom logos (#4539)
Browse files Browse the repository at this point in the history
* Create get-logos endpoint and initialize custom logos

* Update endpoint name

* Add Changelog

Co-authored-by: Alex Ruiz Becerra <alejandro.ruiz.becerra@wazuh.com>
(cherry picked from commit b9f7cf3)
  • Loading branch information
asteriscos authored and AlexRuiz7 committed Sep 20, 2022
1 parent b3fa8bd commit f6ef54a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 8 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ All notable changes to the Wazuh app project will be documented in this file.
### Changed

- Changed the HTTP verb from `GET` to `POST` in the requests to login to the Wazuh API [#4103](https://github.com/wazuh/wazuh-kibana-app/pull/4103)
- Improve alerts summary performance [#4376](https://github.com/wazuh/wazuh-kibana-app/pull/4376)
- Endpoint `/agents/summary/status` response was adapted. [#3874](https://github.com/wazuh/wazuh-kibana-app/pull/3874)
- Made Agents Overview loading icons independent [#4363](https://github.com/wazuh/wazuh-kibana-app/pull/4363)
- Improved alerts summary performance [#4376](https://github.com/wazuh/wazuh-kibana-app/pull/4376)
- The endpoint `/agents/summary/status` response was adapted. [#3874](https://github.com/wazuh/wazuh-kibana-app/pull/3874)
- Made Agents Overview icons load independently [#4363](https://github.com/wazuh/wazuh-kibana-app/pull/4363)

### Fixed

- Fixed nested fields filtering in dashboards tables and KPIs [#4425](https://github.com/wazuh/wazuh-kibana-app/pull/4425)
- Fixed nested field rendering in security alerts table details [#4428](https://github.com/wazuh/wazuh-kibana-app/pull/4428)
- Improved Agents Overview performance [#4363](https://github.com/wazuh/wazuh-kibana-app/pull/4363)
- Fixed a bug where the Wazuh logo was used instead of the custom one [#4539](https://github.com/wazuh/wazuh-kibana-app/pull/4539)

## Wazuh v4.3.8 - Kibana 7.10.2, 7.16.x, 7.17.x - Revision 4309

Expand Down
33 changes: 28 additions & 5 deletions public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,47 @@ 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';
import store from './redux/store';
import { updateAppConfig } from './redux/actions/appConfigActions';

const SIDEBAR_LOGO = 'customization.logo.sidebar';
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 {
public async setup(core: CoreSetup, plugins: WazuhSetupPlugins): WazuhSetup {
const UI_THEME = core.uiSettings.get('theme:darkMode') ? 'dark' : 'light';

// Get custom logos configuration to start up the app with the correct logos
let logosInitialState={};
try{
logosInitialState = await core.http.get(`/api/logos`);
}
catch(error){
console.error('plugin.ts: Error getting logos configuration', error);
}

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

// Update redux app state logos with the custom logos
if (logosInitialState?.logos) {
store.dispatch(updateAppConfig(logosInitialState.logos));
}
// hide the telemetry banner.
// Set the flag in the telemetry saved object as the notice was seen and dismissed
this.hideTelemetryBanner && await this.hideTelemetryBanner();
Expand All @@ -67,7 +90,7 @@ export class WazuhPlugin implements Plugin<WazuhSetup, WazuhStart, WazuhSetupPlu
'GET',
`/api/check-wazuh`,
)

params.element.classList.add('dscAppWrapper', 'wz-app');
const unmount = await renderApp(innerAngularName, params.element);
//Update if user has Wazuh disabled
Expand All @@ -81,7 +104,7 @@ export class WazuhPlugin implements Plugin<WazuhSetup, WazuhStart, WazuhSetupPlu
id: 'wazuh',
label: 'Wazuh',
order: 0,
euiIconType: core.http.basePath.prepend(response.data.logoSidebar ? getAssetURL(response.data.logoSidebar) : getThemeAssetURL('icon.svg', UI_THEME)),
euiIconType: core.http.basePath.prepend(logosInitialState?.logos?.[SIDEBAR_LOGO] ? getAssetURL(logosInitialState?.logos?.[SIDEBAR_LOGO]) : getThemeAssetURL('icon.svg', UI_THEME)),
}}
})
return () => {
Expand All @@ -95,7 +118,7 @@ export class WazuhPlugin implements Plugin<WazuhSetup, WazuhStart, WazuhSetupPlu
id: 'wazuh',
label: 'Wazuh',
order: 0,
euiIconType: core.http.basePath.prepend(getThemeAssetURL('icon.svg', UI_THEME)),
euiIconType: core.http.basePath.prepend(logosInitialState?.logos?.[SIDEBAR_LOGO] ? getAssetURL(logosInitialState?.logos?.[SIDEBAR_LOGO]) : getThemeAssetURL('icon.svg', UI_THEME)),
},
updater$: this.stateUpdater
});
Expand Down
29 changes: 29 additions & 0 deletions server/controllers/wazuh-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1073,4 +1073,33 @@ export class WazuhApiCtrl {
}

}

/**
* Gets custom logos configuration (path)
* @param context
* @param request
* @param response
*/
async getAppLogos(context: RequestHandlerContext, request: KibanaRequest, response: KibanaResponseFactory) {
try {
const configuration = getConfiguration();
const SIDEBAR_LOGO = 'customization.logo.sidebar';
const APP_LOGO = 'customization.logo.app';
const HEALTHCHECK_LOGO = 'customization.logo.healthcheck';

return response.ok({
body: {
logos: {
[SIDEBAR_LOGO]: configuration[SIDEBAR_LOGO],
[APP_LOGO]: configuration[APP_LOGO],
[HEALTHCHECK_LOGO]: configuration[HEALTHCHECK_LOGO],
}
}
});
} catch (error) {
log('wazuh-api:isWazuhDisabled', error.message || error);
return ErrorResponse(error.message || error, 3035, 500, response);
}

}
}
9 changes: 9 additions & 0 deletions server/routes/wazuh-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,13 @@ export function WazuhApiRoutes(router: IRouter) {
},
async (context, request, response) => ctrl.isWazuhDisabled(context, request, response)
);

// Return app logos configuration
router.get({
path: '/api/logos',
validate: false,
options: { authRequired: false }
},
async (context, request, response) => ctrl.getAppLogos(context, request, response)
);
}

0 comments on commit f6ef54a

Please sign in to comment.