Skip to content

Commit

Permalink
Manage installation/removal of the Wazuh plugin (#28)
Browse files Browse the repository at this point in the history
Co-authored-by: Maximiliano Ibarra <[email protected]>
  • Loading branch information
2 people authored and yenienserrano committed Jun 1, 2023
1 parent 82e86d1 commit 572fe15
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
15 changes: 13 additions & 2 deletions src/cli_plugin/install/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ import { fromRoot } from '../../core/server/utils';

const LATEST_PLUGIN_BASE_URL =
'https://ci.opensearch.org/ci/dbc/distribution-build-opensearch-dashboards';
const LATEST_WAZUH_PLUGIN_BASE_URL = 'https://packages-dev.wazuh.com/pre-release/ui/dashboard';

function generateUrls({ version, plugin }) {
return [plugin, generatePluginUrl(version, plugin)];
function generateUrls({ version, plugin, wazuhVersion }) {
return plugin.includes('wazuh')
? [plugin, generateWazuhPluginUrl(wazuhVersion, plugin)]
: [plugin, generatePluginUrl(version, plugin)];
}

function generatePluginUrl(version, plugin) {
Expand All @@ -48,6 +51,10 @@ function generatePluginUrl(version, plugin) {
return `${LATEST_PLUGIN_BASE_URL}/${version}/latest/${platform}/${arch}/tar/builds/opensearch-dashboards/plugins/${plugin}-${version}.zip`;
}

function generateWazuhPluginUrl(version, plugin) {
return `${LATEST_WAZUH_PLUGIN_BASE_URL}/${plugin}-${version}-1.zip`;
}

export function parseMilliseconds(val) {
let result;

Expand All @@ -69,12 +76,16 @@ export function parse(command, options, osdPackage) {
config: options.config || '',
plugin: command,
version: osdPackage.version,
wazuhVersion: osdPackage.wazuh.version,
pluginDir: fromRoot('plugins'),
};

settings.urls = generateUrls(settings);
settings.workingPath = resolve(settings.pluginDir, '.plugin.installing');
settings.tempArchiveFile = resolve(settings.workingPath, 'archive.part');

// Clean up.
delete settings.wazuhVersion;

return settings;
}
7 changes: 6 additions & 1 deletion src/cli_plugin/install/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ describe('parseMilliseconds function', function () {
describe('parse function', function () {
const command = 'plugin name';
const defaultOptions = { pluginDir: fromRoot('plugins') };
const osdPackage = { version: 1234 };
const osdPackage = {
version: 1234,
wazuh: {
version: 1234,
},
};

afterAll(() => {
Object.defineProperties(process, {
Expand Down
10 changes: 5 additions & 5 deletions src/core/public/injected_metadata/injected_metadata_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ export interface InjectedMetadataParams {
* @internal
*/
export class InjectedMetadataService {
private state = deepFreeze(
this.params.injectedMetadata
) as InjectedMetadataParams['injectedMetadata'];
private state: InjectedMetadataParams['injectedMetadata'];

constructor(private readonly params: InjectedMetadataParams) {}
constructor(params: InjectedMetadataParams) {
this.state = deepFreeze(params.injectedMetadata) as InjectedMetadataParams['injectedMetadata'];
}

public start(): InjectedMetadataStart {
return this.setup();
Expand Down Expand Up @@ -158,7 +158,7 @@ export class InjectedMetadataService {
},

getWazuhDocVersion: () => {
return this.state.wazuhVersion.slice(0, 3) || 'current';
return this.state.wazuhVersion?.split('.').slice(0, 2).join('.') || 'current';
},
};
}
Expand Down

0 comments on commit 572fe15

Please sign in to comment.