Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/wazuh/wazuh-kibana-app in…
Browse files Browse the repository at this point in the history
…to enhancement/6959-extract-common-services-frontend-state
  • Loading branch information
Desvelao committed Jan 7, 2025
2 parents d132185 + 09dd139 commit ce72e83
Show file tree
Hide file tree
Showing 43 changed files with 1,336 additions and 3,963 deletions.
15 changes: 0 additions & 15 deletions .github/workflows/dev-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ jobs:
matrix:
plugins:
[
{
name: 'Main',
path: 'wazuh/plugins/main',
container_path: 'wazuh',
},
{
name: 'Wazuh Check Updates',
path: 'wazuh/plugins/wazuh-check-updates',
Expand All @@ -64,16 +59,6 @@ jobs:
path: 'wazuh/plugins/wazuh-core',
container_path: 'wazuh-core',
},
{
name: 'Wazuh Engine',
path: 'wazuh/plugins/wazuh-engine',
container_path: 'wazuh-engine',
},
{
name: 'Wazuh Fleet',
path: 'wazuh/plugins/wazuh-fleet',
container_path: 'wazuh-fleet',
},
]

steps:
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ jobs:
echo "Listing branches"
git branch -a
echo "Getting diff files ignoring deleted and getting the changed or renamed files"
CHANGED_FILES=$(git diff --name-status --diff-filter d ${REMOTE_NAME}/${GITHUB_BASE_REF}..${REMOTE_NAME}/${GITHUB_HEAD_REF} | awk '{print $NF}' | grep -E '.*\.[jt]sx?$')
CHANGED_FILES=$(git diff --name-status --diff-filter d ${REMOTE_NAME}/${GITHUB_BASE_REF}..${REMOTE_NAME}/${GITHUB_HEAD_REF} | awk '{print $NF}' | grep -E '.*\.[jt]sx?$' || echo "false")
if [ $CHANGED_FILES = "false" ]; then
echo "No changed files found with the extension .js, .jsx, .ts or .tsx"
exit 0
fi
echo "Changed files:"
echo "${CHANGED_FILES}"
git checkout $GITHUB_HEAD_REF
Expand Down
21 changes: 0 additions & 21 deletions .github/workflows/manual-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ jobs:
echo "revision=$(jq -r '.revision' $(pwd)/wazuh/plugins/main/package.json)" >> $GITHUB_ENV
echo "versionPlatform=$(jq -r '.pluginPlatform.version' $(pwd)/wazuh/plugins/main/package.json)" >> $GITHUB_ENV
- name: Step 03 - Download the main plugin's artifact
uses: actions/download-artifact@v4
with:
name: wazuh-dashboard-plugins_wazuh_${{ env.version }}-${{ env.revision }}_${{ env.githubReference }}.zip
path: ${{ env.currentDir }}/wazuh/scripts/test-packages/plugins/wazuh-dashboard-plugins_wazuh_${{ env.version }}-${{ env.revision }}_${{ env.githubReference }}.zip
overwrite: true

- name: Step 04 - Download the core plugin's artifact
uses: actions/download-artifact@v4
with:
Expand All @@ -74,20 +67,6 @@ jobs:
path: ${{ env.currentDir }}/wazuh/scripts/test-packages/plugins/wazuh-dashboard-plugins_wazuh-check-updates_${{ env.version }}-${{ env.revision }}_${{ env.githubReference }}.zip
overwrite: true

- name: Step 06 - Download the engine plugin's artifact
uses: actions/download-artifact@v4
with:
name: wazuh-dashboard-plugins_wazuh-engine_${{ env.version }}-${{ env.revision }}_${{ env.githubReference }}.zip
path: ${{ env.currentDir }}/wazuh/scripts/test-packages/plugins/wazuh-dashboard-plugins_wazuh-engine_${{ env.version }}-${{ env.revision }}_${{ env.githubReference }}.zip
overwrite: true

- name: Step 07 - Download the fleet plugin's artifact
uses: actions/download-artifact@v4
with:
name: wazuh-dashboard-plugins_wazuh-fleet_${{ env.version }}-${{ env.revision }}_${{ env.githubReference }}.zip
path: ${{ env.currentDir }}/wazuh/scripts/test-packages/plugins/wazuh-dashboard-plugins_wazuh-fleet${{ env.version }}-${{ env.revision }}_${{ env.githubReference }}.zip
overwrite: true

- name: Step 06 - Build the Docker image
run: |
echo "current=${{ env.currentDir }}"
Expand Down
24 changes: 15 additions & 9 deletions docker/osd-dev/config/2.x/osd/opensearch_dashboards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ opensearch.ssl.verificationMode: certificate
# opensearch.requestHeadersWhitelist: ["securitytenant","Authorization"]
#
# osd 2.0
opensearch.requestHeadersAllowlist: ["securitytenant", "Authorization"]
opensearch.requestHeadersAllowlist: ['securitytenant', 'Authorization']
#
opensearch_security.multitenancy.enabled: false
opensearch_security.readonly_mode.roles: ["kibana_read_only"]
opensearch_security.readonly_mode.roles: ['kibana_read_only']
server.ssl.enabled: true
server.ssl.key: "/home/node/kbn/certs/osd.key"
server.ssl.certificate: "/home/node/kbn/certs/osd.pem"
opensearch.ssl.certificateAuthorities: ["/home/node/kbn/certs/ca.pem"]
uiSettings.overrides.defaultRoute: /app/wz-home
opensearch.username: "kibanaserver"
opensearch.password: "kibanaserver"
server.ssl.key: '/home/node/kbn/certs/osd.key'
server.ssl.certificate: '/home/node/kbn/certs/osd.pem'
opensearch.ssl.certificateAuthorities: ['/home/node/kbn/certs/ca.pem']
uiSettings.overrides.defaultRoute: /app/home
opensearch.username: 'kibanaserver'
opensearch.password: 'kibanaserver'
opensearchDashboards.branding:
useExpandedHeader: false

wazuh_core.hosts:
manager:
url: 'https://wazuh.manager'
port: 55000
username: wazuh-wui
password: MyS3cr37P450r.*-
run_as: false
18 changes: 9 additions & 9 deletions docker/osd-dev/config/2.x/osd/opensearch_dashboards_saml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ opensearch.ssl.verificationMode: certificate
# opensearch.requestHeadersWhitelist: ["securitytenant","Authorization"]
#
# osd 2.0
opensearch.requestHeadersAllowlist: ["securitytenant", "Authorization"]
opensearch.requestHeadersAllowlist: ['securitytenant', 'Authorization']
#
opensearch_security.multitenancy.enabled: false
opensearch_security.readonly_mode.roles: ["kibana_read_only"]
opensearch_security.readonly_mode.roles: ['kibana_read_only']
server.ssl.enabled: true
server.ssl.key: "/home/node/kbn/certs/osd.key"
server.ssl.certificate: "/home/node/kbn/certs/osd.pem"
opensearch.ssl.certificateAuthorities: ["/home/node/kbn/certs/ca.pem"]
uiSettings.overrides.defaultRoute: /app/wazuh
opensearch.username: "kibanaserver"
opensearch.password: "kibanaserver"
server.ssl.key: '/home/node/kbn/certs/osd.key'
server.ssl.certificate: '/home/node/kbn/certs/osd.pem'
opensearch.ssl.certificateAuthorities: ['/home/node/kbn/certs/ca.pem']
uiSettings.overrides.defaultRoute: /app/home
opensearch.username: 'kibanaserver'
opensearch.password: 'kibanaserver'

opensearch_security.auth.type: "saml"
opensearch_security.auth.type: 'saml'
server.xsrf.allowlist:
[
/_plugins/_security/saml/acs,
Expand Down
File renamed without changes.
76 changes: 33 additions & 43 deletions plugins/main/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {
Plugin,
PluginInitializerContext,
} from 'opensearch_dashboards/public';
import { Cookies } from 'react-cookie';
import { euiPaletteColorBlind } from '@elastic/eui';
import { createHashHistory } from 'history';
import {
setDataPlugin,
setHttp,
Expand All @@ -27,61 +30,49 @@ import {
setWazuhEnginePlugin,
setWazuhFleetPlugin,
} from './kibana-services';
import { validate as validateNodeCronInterval } from 'node-cron';
import {
AppPluginStartDependencies,
WazuhSetup,
WazuhSetupPlugins,
WazuhStart,
WazuhStartPlugins,
} from './types';
import { Cookies } from 'react-cookie';
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 store from './redux/store';
import { updateAppConfig } from './redux/actions/appConfigActions';
import {
initializeInterceptor,
unregisterInterceptor,
} from './services/request-handler';
import { Applications, Categories } from './utils/applications';
import { euiPaletteColorBlind } from '@elastic/eui';
import NavigationService from './react-services/navigation-service';
import { createHashHistory } from 'history';
import { reportingDefinitions } from './react-services/reporting/reporting-definitions';

export class WazuhPlugin
implements
Plugin<WazuhSetup, WazuhStart, WazuhSetupPlugins, WazuhStartPlugins>
{
constructor(private readonly initializerContext: PluginInitializerContext) {}

private hideTelemetryBanner?: () => void;

public async setup(
core: CoreSetup,
plugins: WazuhSetupPlugins,
): Promise<WazuhSetup> {
// 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);
}

// Redefine the mapKeys method to change the properties sent to euiPaletteColorBlind.
// This is a workaround until the issue reported in Opensearch Dashboards is fixed.
// https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5422
// This should be reomved when the issue is fixed. Probably in OSD 2.12.0
plugins.charts.colors.mappedColors.mapKeys = function (
keys: Array<string | number>,
keys: (string | number)[],
) {
const configMapping = this.getConfigColorMapping();
const configColors = _.values(configMapping);
const oldColors = _.values(this._oldMap);

let alreadyUsedColors: string[] = [];
const keysToMap: Array<string | number> = [];
const keysToMap: (string | number)[] = [];

_.each(keys, key => {
// If this key is mapped in the config, it's unnecessary to have it mapped here
if (configMapping[key as any]) {
Expand All @@ -90,7 +81,9 @@ export class WazuhPlugin
}

// If this key is mapped to a color used by the config color mapping, we need to remap it
if (_.includes(configColors, this._mapping[key])) keysToMap.push(key);
if (_.includes(configColors, this._mapping[key])) {
keysToMap.push(key);
}

// if key exist in oldMap, move it to mapping
if (this._oldMap[key]) {
Expand All @@ -99,13 +92,16 @@ export class WazuhPlugin
}

// If this key isn't mapped, we need to map it
if (this.get(key) == null) keysToMap.push(key);
if (this.get(key) === null) {
keysToMap.push(key);
}
});

alreadyUsedColors.push(...Object.values(this._mapping));
alreadyUsedColors = alreadyUsedColors.map(color =>
color.toLocaleLowerCase(),
);

// Choose colors from euiPaletteColorBlind and filter out any already assigned to keys
const colorPalette = euiPaletteColorBlind({
rotations: Math.ceil(
Expand All @@ -120,57 +116,46 @@ export class WazuhPlugin
};

// Register the applications
Applications.forEach(app => {
for (const app of Applications) {
const { category, id, title, redirectTo, order } = app;

core.application.register({
id,
title,
order,
mount: async (params: AppMountParameters) => {
try {
/* Workaround: Redefine the validation functions of cron.statistics.interval setting.
There is an optimization error of the frontend side source code due to some modules can
not be loaded
*/
const setting = plugins.wazuhCore.configuration._settings.get(
'cron.statistics.interval',
);
!setting.validateUIForm &&
(setting.validateUIForm = function (value) {
return this.validate(value);
});
!setting.validate &&
(setting.validate = function (value: string) {
return validateNodeCronInterval(value)
? undefined
: 'Interval is not valid.';
});
setWzCurrentAppID(id);
// Set the dynamic redirection
setWzMainParams(redirectTo());
initializeInterceptor(core);

// 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());
if (this.hideTelemetryBanner) {
await this.hideTelemetryBanner();
}

setScopedHistory(params.history);
// This allows you to add the selectors to the navbar
setHeaderActionMenuMounter(params.setHeaderActionMenu);
NavigationService.getInstance(createHashHistory());

// Load application bundle
const { renderApp } = await import('./application');

setErrorOrchestrator(ErrorOrchestratorService);
setHttp(core.http);
setCookies(new Cookies());

if (!AppState.checkCookies()) {
NavigationService.getInstance().reload();
}

params.element.classList.add('dscAppWrapper', 'wz-app');

const unmount = await renderApp(params);

return () => {
unmount();
unregisterInterceptor();
Expand All @@ -183,9 +168,11 @@ export class WazuhPlugin
({ id: categoryID }) => categoryID === category,
),
});
});
}

return {};
}

public start(
core: CoreStart,
plugins: AppPluginStartDependencies,
Expand All @@ -194,11 +181,13 @@ export class WazuhPlugin
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();
}

setCore(core);
setPlugins(plugins);
setHttp(core.http);
Expand All @@ -215,6 +204,7 @@ export class WazuhPlugin
setWazuhCorePlugin(plugins.wazuhCore);
setWazuhEnginePlugin(plugins.wazuhEngine);
setWazuhFleetPlugin(plugins.wazuhFleet);

return {};
}
}
Loading

0 comments on commit ce72e83

Please sign in to comment.