Skip to content

Commit 44589e7

Browse files
felipegonzalezmvyenienserrano
authored andcommitted
Enhance Wazuh integration by adding version, revision, and stage on wz dashboard (#1327)
* Enhance Wazuh integration by adding version, revision, and stage metadata. Update related interfaces and mocks to support new properties across the application. * Add production flag handling in VERSION.json and update related interfaces This commit introduces a new step in the build workflow to set the production flag in VERSION.json based on the deployment stage. Additionally, it updates various interfaces and mocks across the application to include the new property, ensuring consistent handling of this metadata throughout the codebase. * Refactor Wazuh build metadata handling and update related interfaces This commit removes the production flag handling from the build workflow and integrates it directly into the package.json during the build process. It also introduces a new WazuhBuildInfo interface to encapsulate version, revision, stage, and production status, updating various components and mocks across the application to utilize this new structure for consistent metadata management. * Update health check mock and enhance injected metadata in tests This commit replaces the hardcoded health check configuration in the injected metadata service mock with a reference to the centralized healthCheckConfig. Additionally, it updates the PluginsService tests to include the new 'getWazuhBuildInfo' method in the injected metadata mock, ensuring consistency across the application. * fix prettier * tmp change on workflow * restore file
1 parent 23d8eb8 commit 44589e7

21 files changed

Lines changed: 163 additions & 22 deletions

File tree

dev-tools/build-packages/deb/deb-builder.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ log "Extracting base tar.gz..."
6060
tar -zxf "${out_dir}/wazuh-dashboard-$version-$revision-linux-$architecture.tar.gz"
6161
log "Preparing the package..."
6262
jq '.wazuh.revision="'${revision}'"' package.json > pkgtmp.json && mv pkgtmp.json package.json
63+
if [ "${is_production}" = "yes" ]; then
64+
jq '.wazuh.isProduction = true' package.json > pkgtmp.json && mv pkgtmp.json package.json
65+
else
66+
jq '.wazuh.isProduction = false' package.json > pkgtmp.json && mv pkgtmp.json package.json
67+
fi
6368
mkdir -p etc/services
6469
cp "${config_path}"/* etc/services
6570
jq '.version="'${version}'"' VERSION.json > VERSION.tmp && mv VERSION.tmp VERSION.json

dev-tools/build-packages/rpm/rpm-builder.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ log "Extracting base tar.gz..."
5858
tar -zxf "${out_dir}/wazuh-dashboard-$version-$revision-linux-$architecture.tar.gz"
5959
log "Preparing the package..."
6060
jq '.wazuh.revision="'${revision}'"' package.json > pkgtmp.json && mv pkgtmp.json package.json
61+
if [ "${is_production}" = "yes" ]; then
62+
jq '.wazuh.isProduction = true' package.json > pkgtmp.json && mv pkgtmp.json package.json
63+
else
64+
jq '.wazuh.isProduction = false' package.json > pkgtmp.json && mv pkgtmp.json package.json
65+
fi
6166
mkdir -p etc/services
6267
cp "${config_path}"/* etc/services
6368
jq '.version="'${version}'"' VERSION.json > VERSION.tmp && mv VERSION.tmp VERSION.json

packages/osd-config/src/env.test.mocks.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ export const mockPackage = {
4444
raw: {},
4545
};
4646

47+
export const mockVersionFile = {
48+
raw: { stage: '' },
49+
};
50+
4751
jest.doMock('load-json-file', () => ({
48-
sync: () => mockPackage.raw,
52+
sync: (filePath: string) => {
53+
if (filePath.endsWith('VERSION.json')) {
54+
return mockVersionFile.raw;
55+
}
56+
return mockPackage.raw;
57+
},
4958
}));

packages/osd-config/src/env.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,25 @@ export interface RawPackageInfo {
6969
};
7070
wazuh: {
7171
version: string;
72+
revision?: string;
73+
isProduction?: boolean;
7274
};
7375
}
7476

77+
/** @internal */
78+
interface RawWazuhVersionFile {
79+
version?: string;
80+
stage?: string;
81+
}
82+
83+
function loadWazuhVersionFile(repoRoot: string): RawWazuhVersionFile {
84+
try {
85+
return loadJsonFile.sync(join(repoRoot, 'VERSION.json')) as RawWazuhVersionFile;
86+
} catch {
87+
return {};
88+
}
89+
}
90+
7591
export class Env {
7692
/**
7793
* @internal
@@ -154,6 +170,7 @@ export class Env {
154170
const isOpenSearchDashboardsDistributable = Boolean(
155171
pkg.build && pkg.build.distributable === true
156172
);
173+
const wazuhVersionFile = loadWazuhVersionFile(this.homeDir);
157174
this.packageInfo = Object.freeze({
158175
branch: pkg.branch,
159176
buildNum: isOpenSearchDashboardsDistributable ? pkg.build.number : Number.MAX_SAFE_INTEGER,
@@ -163,6 +180,9 @@ export class Env {
163180
version: pkg.version,
164181
dist: isOpenSearchDashboardsDistributable,
165182
wazuhVersion: pkg.wazuh.version,
183+
wazuhRevision: pkg.wazuh.revision ?? '01',
184+
wazuhStage: wazuhVersionFile.stage ?? '',
185+
wazuhIsProduction: pkg.wazuh.isProduction ?? false,
166186
});
167187
}
168188
}

packages/osd-config/src/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export interface PackageInfo {
3838
buildSha: string;
3939
dist: boolean;
4040
wazuhVersion: string;
41+
wazuhRevision: string;
42+
wazuhStage: string;
43+
wazuhIsProduction: boolean;
4144
}
4245

4346
/**

src/core/public/chrome/chrome_service.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ export class ChromeService {
406406
homeHref={application.getUrlForApp('wz-home')}
407407
isVisible$={this.isVisible$}
408408
headerVariant$={this.headerVariant$}
409-
opensearchDashboardsVersion={injectedMetadata.getWazuhVersion()}
409+
opensearchDashboardsVersion={injectedMetadata.getWazuhBuildInfo().version}
410410
navLinks$={navLinks.getNavLinks$()}
411411
recentlyAccessed$={recentlyAccessed.get$()}
412412
navControlsLeft$={navControls.getLeft$()}

src/core/public/core_system.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,11 @@ export class CoreSystem {
304304
docLinks,
305305
http,
306306
i18n,
307-
injectedMetadata: pick(injectedMetadata, ['getInjectedVar', 'getBranding']),
307+
injectedMetadata: pick(injectedMetadata, [
308+
'getInjectedVar',
309+
'getBranding',
310+
'getWazuhBuildInfo',
311+
]),
308312
notifications,
309313
overlays,
310314
savedObjects,

src/core/public/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,11 @@ import { KeyboardShortcutSetup, KeyboardShortcutStart } from './keyboard_shortcu
106106
import { ChatServiceSetup, ChatServiceStart } from './chat';
107107
import type { TelemetryServiceSetup, TelemetryServiceStart } from './telemetry';
108108
import { HealthCheckServiceSetup, HealthCheckServiceStart } from './healthcheck';
109+
import type { WazuhBuildInfo } from '../types/wazuh_build_info';
109110

110111
export type { Logos } from '../common';
111112
export { PackageInfo, EnvironmentMode } from '../server/types';
113+
export type { WazuhBuildInfo } from '../types/wazuh_build_info';
112114
/** @interal */
113115
export { CoreContext, CoreSystem } from './core_system';
114116
export {
@@ -288,6 +290,8 @@ export interface CoreSetup<TPluginsStart extends object = object, TStart = unkno
288290
injectedMetadata: {
289291
getInjectedVar: (name: string, defaultValue?: any) => unknown;
290292
getBranding: () => Branding;
293+
// Wazuh
294+
getWazuhBuildInfo: () => WazuhBuildInfo;
291295
};
292296
/** {@link StartServicesAccessor} */
293297
getStartServices: StartServicesAccessor<TPluginsStart, TStart>;
@@ -355,6 +359,8 @@ export interface CoreStart {
355359
injectedMetadata: {
356360
getInjectedVar: (name: string, defaultValue?: any) => unknown;
357361
getBranding: () => Branding;
362+
// Wazuh
363+
getWazuhBuildInfo: () => WazuhBuildInfo;
358364
};
359365
/** {@link WorkspacesStart} */
360366
workspaces: WorkspacesStart;

src/core/public/injected_metadata/injected_metadata_service.mock.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,17 @@
2929
*/
3030

3131
import type { PublicMethodsOf } from '@osd/utility-types';
32+
import { healthCheckConfig } from 'src/core/server/healthcheck/healthcheck/health_check.mock';
33+
import { WazuhBuildInfo } from '../../types/wazuh_build_info';
3234
import { InjectedMetadataService, InjectedMetadataSetup } from './injected_metadata_service';
3335

36+
export const mockWazuhBuildInfo: WazuhBuildInfo = {
37+
version: '4.x.x',
38+
revision: '01',
39+
stage: '',
40+
isProduction: false,
41+
};
42+
3443
const createSetupContractMock = () => {
3544
const setupContract: jest.Mocked<InjectedMetadataSetup> = {
3645
getBasePath: jest.fn(),
@@ -48,7 +57,7 @@ const createSetupContractMock = () => {
4857
getSurvey: jest.fn(),
4958
getEnableIconSideNav: jest.fn(),
5059
getKeyboardShortcuts: jest.fn(),
51-
getWazuhVersion: jest.fn(),
60+
getWazuhBuildInfo: jest.fn(),
5261
getWazuhDocVersion: jest.fn(),
5362
// Wazuh
5463
getHealthCheck: jest.fn(),
@@ -70,18 +79,27 @@ const createSetupContractMock = () => {
7079
setupContract.getPlugins.mockReturnValue([]);
7180
setupContract.getEnableIconSideNav.mockReturnValue(true);
7281
setupContract.getKeyboardShortcuts.mockReturnValue({ enabled: true });
73-
setupContract.getWazuhVersion.mockReturnValue('4.x.x');
82+
setupContract.getWazuhBuildInfo.mockReturnValue(mockWazuhBuildInfo);
7483
setupContract.getWazuhDocVersion.mockReturnValue('4.x');
84+
setupContract.getHealthCheck.mockReturnValue(healthCheckConfig);
7585
return setupContract;
7686
};
7787

78-
const createStartContractMock = createSetupContractMock;
79-
8088
type InjectedMetadataServiceContract = PublicMethodsOf<InjectedMetadataService>;
81-
const createMock = (): jest.Mocked<InjectedMetadataServiceContract> => ({
82-
setup: jest.fn().mockReturnValue(createSetupContractMock()),
83-
start: jest.fn().mockReturnValue(createStartContractMock()),
84-
});
89+
90+
const createStartContractMock = () => createSetupContractMock();
91+
92+
const createMock = () => {
93+
const mocked: jest.Mocked<InjectedMetadataServiceContract> = {
94+
setup: jest.fn(),
95+
start: jest.fn(),
96+
};
97+
98+
mocked.setup.mockReturnValue(createSetupContractMock());
99+
mocked.start.mockReturnValue(createStartContractMock());
100+
101+
return mocked;
102+
};
85103

86104
export const injectedMetadataServiceMock = {
87105
create: createMock,

src/core/public/injected_metadata/injected_metadata_service.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
UserProvidedValues,
4040
} from '../../server/types';
4141
import { AppCategory, Branding } from '../';
42+
import { WazuhBuildInfo } from '../../types/wazuh_build_info';
4243

4344
export interface InjectedPluginMetadata {
4445
id: PluginName;
@@ -54,7 +55,7 @@ export interface InjectedMetadataParams {
5455
version: string;
5556
buildNumber: number;
5657
branch: string;
57-
wazuhVersion: string;
58+
wazuhBuildInfo: WazuhBuildInfo;
5859
basePath: string;
5960
serverBasePath: string;
6061
category?: AppCategory;
@@ -171,13 +172,13 @@ export class InjectedMetadataService {
171172
},
172173

173174
// Wazuh
174-
getWazuhVersion: () => {
175-
return this.state.wazuhVersion;
175+
getWazuhBuildInfo: () => {
176+
return this.state.wazuhBuildInfo;
176177
},
177178

178179
// Wazuh
179180
getWazuhDocVersion: () => {
180-
return this.state.wazuhVersion?.split('.').slice(0, 2).join('.') || 'current';
181+
return this.state.wazuhBuildInfo.version?.split('.').slice(0, 2).join('.') || 'current';
181182
},
182183

183184
// Wazuh
@@ -224,7 +225,7 @@ export interface InjectedMetadataSetup {
224225
enabled: boolean;
225226
};
226227
// Wazuh
227-
getWazuhVersion: () => string;
228+
getWazuhBuildInfo: () => WazuhBuildInfo;
228229
getWazuhDocVersion: () => string;
229230
getHealthCheck: () => HealthCheckConfig;
230231
}

0 commit comments

Comments
 (0)