Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 2 additions & 2 deletions .github/workflows/5_builderpackage_dashboard_plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ jobs:

- name: Bootstrap with Plugins
env:
GIT_REF: ${{ env.PLUGIN_REF }}
GIT_REF: main
run: yarn osd bootstrap --single-version=loose || yarn osd bootstrap --single-version=loose

- name: Build Plugin
working-directory: plugins/${{ inputs.name }}
env:
GIT_REF: ${{ env.PLUGIN_REF }}
GIT_REF: main
run: |
set -o pipefail
OPENSEARCH_DASHBOARDS_VERSION=${{ inputs.version_opensearch }} yarn build 2>&1 | tee build.log
Expand Down
5 changes: 5 additions & 0 deletions dev-tools/build-packages/deb/deb-builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ log "Extracting base tar.gz..."
tar -zxf "${out_dir}/wazuh-dashboard-$version-$revision-linux-$architecture.tar.gz"
log "Preparing the package..."
jq '.wazuh.revision="'${revision}'"' package.json > pkgtmp.json && mv pkgtmp.json package.json
if [ "${is_production}" = "yes" ]; then
jq '.wazuh.isProduction = true' package.json > pkgtmp.json && mv pkgtmp.json package.json
else
jq '.wazuh.isProduction = false' package.json > pkgtmp.json && mv pkgtmp.json package.json
fi
mkdir -p etc/services
cp "${config_path}"/* etc/services
jq '.version="'${version}'"' VERSION.json > VERSION.tmp && mv VERSION.tmp VERSION.json
Expand Down
5 changes: 5 additions & 0 deletions dev-tools/build-packages/rpm/rpm-builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ log "Extracting base tar.gz..."
tar -zxf "${out_dir}/wazuh-dashboard-$version-$revision-linux-$architecture.tar.gz"
log "Preparing the package..."
jq '.wazuh.revision="'${revision}'"' package.json > pkgtmp.json && mv pkgtmp.json package.json
if [ "${is_production}" = "yes" ]; then
jq '.wazuh.isProduction = true' package.json > pkgtmp.json && mv pkgtmp.json package.json
else
jq '.wazuh.isProduction = false' package.json > pkgtmp.json && mv pkgtmp.json package.json
fi
mkdir -p etc/services
cp "${config_path}"/* etc/services
jq '.version="'${version}'"' VERSION.json > VERSION.tmp && mv VERSION.tmp VERSION.json
Expand Down
11 changes: 10 additions & 1 deletion packages/osd-config/src/env.test.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ export const mockPackage = {
raw: {},
};

export const mockVersionFile = {
raw: { stage: '' },
};

jest.doMock('load-json-file', () => ({
sync: () => mockPackage.raw,
sync: (filePath: string) => {
if (filePath.endsWith('VERSION.json')) {
return mockVersionFile.raw;
}
return mockPackage.raw;
},
}));
20 changes: 20 additions & 0 deletions packages/osd-config/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,25 @@ export interface RawPackageInfo {
};
wazuh: {
version: string;
revision?: string;
isProduction?: boolean;
};
}

/** @internal */
interface RawWazuhVersionFile {
version?: string;
stage?: string;
}

function loadWazuhVersionFile(repoRoot: string): RawWazuhVersionFile {
try {
return loadJsonFile.sync(join(repoRoot, 'VERSION.json')) as RawWazuhVersionFile;
} catch {
return {};
}
}

export class Env {
/**
* @internal
Expand Down Expand Up @@ -154,6 +170,7 @@ export class Env {
const isOpenSearchDashboardsDistributable = Boolean(
pkg.build && pkg.build.distributable === true
);
const wazuhVersionFile = loadWazuhVersionFile(this.homeDir);
this.packageInfo = Object.freeze({
branch: pkg.branch,
buildNum: isOpenSearchDashboardsDistributable ? pkg.build.number : Number.MAX_SAFE_INTEGER,
Expand All @@ -163,6 +180,9 @@ export class Env {
version: pkg.version,
dist: isOpenSearchDashboardsDistributable,
wazuhVersion: pkg.wazuh.version,
wazuhRevision: pkg.wazuh.revision ?? '01',
wazuhStage: wazuhVersionFile.stage ?? '',
wazuhIsProduction: pkg.wazuh.isProduction ?? false,
});
}
}
3 changes: 3 additions & 0 deletions packages/osd-config/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export interface PackageInfo {
buildSha: string;
dist: boolean;
wazuhVersion: string;
wazuhRevision: string;
wazuhStage: string;
wazuhIsProduction: boolean;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/chrome/chrome_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export class ChromeService {
homeHref={application.getUrlForApp('wz-home')}
isVisible$={this.isVisible$}
headerVariant$={this.headerVariant$}
opensearchDashboardsVersion={injectedMetadata.getWazuhVersion()}
opensearchDashboardsVersion={injectedMetadata.getWazuhBuildInfo().version}
navLinks$={navLinks.getNavLinks$()}
recentlyAccessed$={recentlyAccessed.get$()}
navControlsLeft$={navControls.getLeft$()}
Expand Down
6 changes: 5 additions & 1 deletion src/core/public/core_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,11 @@ export class CoreSystem {
docLinks,
http,
i18n,
injectedMetadata: pick(injectedMetadata, ['getInjectedVar', 'getBranding']),
injectedMetadata: pick(injectedMetadata, [
'getInjectedVar',
'getBranding',
'getWazuhBuildInfo',
]),
notifications,
overlays,
savedObjects,
Expand Down
6 changes: 6 additions & 0 deletions src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ import { KeyboardShortcutSetup, KeyboardShortcutStart } from './keyboard_shortcu
import { ChatServiceSetup, ChatServiceStart } from './chat';
import type { TelemetryServiceSetup, TelemetryServiceStart } from './telemetry';
import { HealthCheckServiceSetup, HealthCheckServiceStart } from './healthcheck';
import type { WazuhBuildInfo } from '../types/wazuh_build_info';

export type { Logos } from '../common';
export { PackageInfo, EnvironmentMode } from '../server/types';
export type { WazuhBuildInfo } from '../types/wazuh_build_info';
/** @interal */
export { CoreContext, CoreSystem } from './core_system';
export {
Expand Down Expand Up @@ -288,6 +290,8 @@ export interface CoreSetup<TPluginsStart extends object = object, TStart = unkno
injectedMetadata: {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
getBranding: () => Branding;
// Wazuh
getWazuhBuildInfo: () => WazuhBuildInfo;
};
/** {@link StartServicesAccessor} */
getStartServices: StartServicesAccessor<TPluginsStart, TStart>;
Expand Down Expand Up @@ -355,6 +359,8 @@ export interface CoreStart {
injectedMetadata: {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
getBranding: () => Branding;
// Wazuh
getWazuhBuildInfo: () => WazuhBuildInfo;
};
/** {@link WorkspacesStart} */
workspaces: WorkspacesStart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,17 @@
*/

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

export const mockWazuhBuildInfo: WazuhBuildInfo = {
version: '4.x.x',
revision: '01',
stage: '',
isProduction: false,
};

const createSetupContractMock = () => {
const setupContract: jest.Mocked<InjectedMetadataSetup> = {
getBasePath: jest.fn(),
Expand All @@ -47,7 +56,7 @@ const createSetupContractMock = () => {
getBranding: jest.fn(),
getSurvey: jest.fn(),
getKeyboardShortcuts: jest.fn(),
getWazuhVersion: jest.fn(),
getWazuhBuildInfo: jest.fn(),
getWazuhDocVersion: jest.fn(),
// Wazuh
getHealthCheck: jest.fn(),
Expand All @@ -68,18 +77,27 @@ const createSetupContractMock = () => {
} as any);
setupContract.getPlugins.mockReturnValue([]);
setupContract.getKeyboardShortcuts.mockReturnValue({ enabled: true });
setupContract.getWazuhVersion.mockReturnValue('4.x.x');
setupContract.getWazuhBuildInfo.mockReturnValue(mockWazuhBuildInfo);
setupContract.getWazuhDocVersion.mockReturnValue('4.x');
setupContract.getHealthCheck.mockReturnValue(healthCheckConfig);
return setupContract;
};

const createStartContractMock = createSetupContractMock;

type InjectedMetadataServiceContract = PublicMethodsOf<InjectedMetadataService>;
const createMock = (): jest.Mocked<InjectedMetadataServiceContract> => ({
setup: jest.fn().mockReturnValue(createSetupContractMock()),
start: jest.fn().mockReturnValue(createStartContractMock()),
});

const createStartContractMock = () => createSetupContractMock();

const createMock = () => {
const mocked: jest.Mocked<InjectedMetadataServiceContract> = {
setup: jest.fn(),
start: jest.fn(),
};

mocked.setup.mockReturnValue(createSetupContractMock());
mocked.start.mockReturnValue(createStartContractMock());

return mocked;
};

export const injectedMetadataServiceMock = {
create: createMock,
Expand Down
11 changes: 6 additions & 5 deletions src/core/public/injected_metadata/injected_metadata_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
UserProvidedValues,
} from '../../server/types';
import { AppCategory, Branding } from '../';
import { WazuhBuildInfo } from '../../types/wazuh_build_info';

export interface InjectedPluginMetadata {
id: PluginName;
Expand All @@ -54,7 +55,7 @@ export interface InjectedMetadataParams {
version: string;
buildNumber: number;
branch: string;
wazuhVersion: string;
wazuhBuildInfo: WazuhBuildInfo;
basePath: string;
serverBasePath: string;
category?: AppCategory;
Expand Down Expand Up @@ -166,13 +167,13 @@ export class InjectedMetadataService {
},

// Wazuh
getWazuhVersion: () => {
return this.state.wazuhVersion;
getWazuhBuildInfo: () => {
return this.state.wazuhBuildInfo;
},

// Wazuh
getWazuhDocVersion: () => {
return this.state.wazuhVersion?.split('.').slice(0, 2).join('.') || 'current';
return this.state.wazuhBuildInfo.version?.split('.').slice(0, 2).join('.') || 'current';
},

// Wazuh
Expand Down Expand Up @@ -218,7 +219,7 @@ export interface InjectedMetadataSetup {
enabled: boolean;
};
// Wazuh
getWazuhVersion: () => string;
getWazuhBuildInfo: () => WazuhBuildInfo;
getWazuhDocVersion: () => string;
getHealthCheck: () => HealthCheckConfig;
}
Expand Down
13 changes: 12 additions & 1 deletion src/core/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ export { docLinksServiceMock } from './doc_links/doc_links_service.mock';
export { fatalErrorsServiceMock } from './fatal_errors/fatal_errors_service.mock';
export { httpServiceMock } from './http/http_service.mock';
export { i18nServiceMock } from './i18n/i18n_service.mock';
export { injectedMetadataServiceMock } from './injected_metadata/injected_metadata_service.mock';
export {
injectedMetadataServiceMock,
mockWazuhBuildInfo,
} from './injected_metadata/injected_metadata_service.mock';
export { notificationServiceMock } from './notifications/notifications_service.mock';
export { overlayServiceMock } from './overlays/overlay_service.mock';
export { savedObjectsServiceMock } from './saved_objects/saved_objects_service.mock';
Expand Down Expand Up @@ -93,6 +96,7 @@ function createCoreSetupMock({
injectedMetadata: {
getInjectedVar: injectedMetadataServiceMock.createSetupContract().getInjectedVar,
getBranding: injectedMetadataServiceMock.createSetupContract().getBranding,
getWazuhBuildInfo: injectedMetadataServiceMock.createSetupContract().getWazuhBuildInfo,
},
workspaces: workspacesServiceMock.createSetupContract(),
keyboardShortcut: keyboardShortcutServiceMock.createSetup(),
Expand All @@ -117,6 +121,7 @@ function createCoreStartMock({ basePath = '' } = {}) {
injectedMetadata: {
getInjectedVar: injectedMetadataServiceMock.createStartContract().getInjectedVar,
getBranding: injectedMetadataServiceMock.createStartContract().getBranding,
getWazuhBuildInfo: injectedMetadataServiceMock.createStartContract().getWazuhBuildInfo,
},
fatalErrors: fatalErrorsServiceMock.createStartContract(),
workspaces: workspacesServiceMock.createStartContract(),
Expand Down Expand Up @@ -144,6 +149,9 @@ function pluginInitializerContextMock() {
buildSha: 'buildSha',
dist: false,
wazuhVersion: 'wazuhVersion',
wazuhRevision: '01',
wazuhStage: '',
wazuhIsProduction: false,
},
},
config: {
Expand All @@ -170,6 +178,9 @@ function createCoreContext(): CoreContext {
buildSha: 'buildSha',
dist: false,
wazuhVersion: 'wazuhVersion',
wazuhRevision: '01',
wazuhStage: '',
wazuhIsProduction: false,
},
},
};
Expand Down
2 changes: 2 additions & 0 deletions src/core/public/plugins/plugin_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export function createPluginSetupContext<
injectedMetadata: {
getInjectedVar: deps.injectedMetadata.getInjectedVar,
getBranding: deps.injectedMetadata.getBranding,
getWazuhBuildInfo: deps.injectedMetadata.getWazuhBuildInfo,
},
getStartServices: () => plugin.startDependencies,
workspaces: deps.workspaces,
Expand Down Expand Up @@ -179,6 +180,7 @@ export function createPluginStartContext<
injectedMetadata: {
getInjectedVar: deps.injectedMetadata.getInjectedVar,
getBranding: deps.injectedMetadata.getBranding,
getWazuhBuildInfo: deps.injectedMetadata.getWazuhBuildInfo,
},
fatalErrors: deps.fatalErrors,
workspaces: deps.workspaces,
Expand Down
14 changes: 12 additions & 2 deletions src/core/public/plugins/plugins_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ describe('PluginsService', () => {
...mockSetupDeps,
application: expect.any(Object),
getStartServices: expect.any(Function),
injectedMetadata: pick(mockSetupDeps.injectedMetadata, 'getInjectedVar', 'getBranding'),
injectedMetadata: pick(
mockSetupDeps.injectedMetadata,
'getInjectedVar',
'getBranding',
'getWazuhBuildInfo'
),
};
mockStartDeps = {
application: applicationServiceMock.createInternalStartContract(),
Expand All @@ -148,7 +153,12 @@ describe('PluginsService', () => {
...mockStartDeps,
application: expect.any(Object),
chrome: omit(mockStartDeps.chrome, 'getComponent'),
injectedMetadata: pick(mockStartDeps.injectedMetadata, 'getInjectedVar', 'getBranding'),
injectedMetadata: pick(
mockStartDeps.injectedMetadata,
'getInjectedVar',
'getBranding',
'getWazuhBuildInfo'
),
telemetry: expect.any(Object),
};

Expand Down
3 changes: 3 additions & 0 deletions src/core/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ function pluginInitializerContextMock<T>(config: T = {} as T) {
buildSha: 'buildSha',
dist: false,
wazuhVersion: 'wazuhVersion',
wazuhRevision: '01',
wazuhStage: '',
wazuhIsProduction: false,
},
instanceUuid: 'instance-uuid',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ const packageInfo = {
version: '7.0.0-alpha1',
dist: false,
wazuhVersion: '4.0.0',
wazuhRevision: '01',
wazuhStage: '',
wazuhIsProduction: false,
};

afterEach(() => {
Expand Down
9 changes: 9 additions & 0 deletions src/core/server/rendering/rendering_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,17 @@ const INJECTED_METADATA = {
dist: expect.any(Boolean),
version: expect.any(String),
wazuhVersion: expect.any(String),
wazuhRevision: expect.any(String),
wazuhStage: expect.any(String),
wazuhIsProduction: expect.any(Boolean),
},
},
wazuhBuildInfo: {
version: expect.any(String),
revision: expect.any(String),
stage: expect.any(String),
isProduction: expect.any(Boolean),
},
};

const { createOpenSearchDashboardsRequest, createRawRequest } = httpServerMock;
Expand Down
Loading
Loading