Skip to content

Commit

Permalink
Create new plugin wazuh-endpoints (#6142)
Browse files Browse the repository at this point in the history
* Create new plugin wazuh-endpoints

* Delete import

* Add github action to run plugin test

* Remove github action to run plugin test
  • Loading branch information
lucianogorza committed Nov 24, 2023
1 parent e391616 commit 4357c94
Show file tree
Hide file tree
Showing 20 changed files with 466 additions and 2 deletions.
1 change: 1 addition & 0 deletions docker/osd-dev/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ services:
- '${SRC}/main:/home/node/kbn/plugins/wazuh'
- '${SRC}/wazuh-core:/home/node/kbn/plugins/wazuh-core'
- '${SRC}/wazuh-check-updates:/home/node/kbn/plugins/wazuh-check-updates'
- '${SRC}/wazuh-endpoints:/home/node/kbn/plugins/wazuh-endpoints'
- wd_certs:/home/node/kbn/certs/
- ${WAZUH_DASHBOARD_CONF}:/home/node/kbn/config/opensearch_dashboards.yml
- ./config/${OSD_MAJOR}/osd/wazuh.yml:/home/node/kbn/data/wazuh/config/wazuh.yml
Expand Down
10 changes: 8 additions & 2 deletions plugins/main/opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@
"opensearchDashboardsReact",
"opensearchDashboardsUtils",
"opensearchDashboardsLegacy",
"wazuhCheckUpdates"
"wazuhCheckUpdates",
"wazuhEndpoints"
],
"optionalPlugins": [
"security",
"securityDashboards",
"searchguard",
"telemetry"
],
"optionalPlugins": ["security", "securityDashboards", "searchguard", "telemetry"],
"server": true,
"ui": true
}
2 changes: 2 additions & 0 deletions plugins/main/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SecurityOssPluginStart } from '../../../src/plugins/security_oss/public
import { SavedObjectsStart } from '../../../src/plugins/saved_objects/public';
import { TelemetryPluginStart, TelemetryPluginSetup } from '../../../src/plugins/telemetry/public';
import { WazuhCheckUpdatesPluginStart } from '../../wazuh-check-updates/public';
import { WazuhEndpointsPluginStart } from '../../wazuh-endpoints/public';
import { DashboardStart } from '../../../src/plugins/dashboard/public';

export interface AppPluginStartDependencies {
Expand All @@ -24,6 +25,7 @@ export interface AppPluginStartDependencies {
savedObjects: SavedObjectsStart;
telemetry: TelemetryPluginStart;
wazuhCheckUpdates: WazuhCheckUpdatesPluginStart;
wazuhEndpoints: WazuhEndpointsPluginStart;
dashboard: DashboardStart;
}
export interface AppDependencies {
Expand Down
7 changes: 7 additions & 0 deletions plugins/wazuh-endpoints/.i18nrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"prefix": "wazuhEndpoints",
"paths": {
"wazuhEndpoints": "."
},
"translations": ["translations/en-US.json"]
}
4 changes: 4 additions & 0 deletions plugins/wazuh-endpoints/common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const PLUGIN_ID = 'wazuhEndpoints';
export const PLUGIN_NAME = 'wazuh_endpoints';

export enum routes {}
Empty file.
9 changes: 9 additions & 0 deletions plugins/wazuh-endpoints/opensearch_dashboards.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "wazuhEndpoints",
"version": "4.9.0-00",
"opensearchDashboardsVersion": "opensearchDashboards",
"server": true,
"ui": true,
"requiredPlugins": ["navigation"],
"optionalPlugins": []
}
20 changes: 20 additions & 0 deletions plugins/wazuh-endpoints/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "wazuh-endpoints",
"version": "4.9.0",
"revision": "00",
"pluginPlatform": {
"version": "2.10.0"
},
"description": "Wazuh Endpoints",
"private": true,
"scripts": {
"build": "yarn plugin-helpers build --opensearch-dashboards-version=$OPENSEARCH_DASHBOARDS_VERSION",
"plugin-helpers": "node ../../scripts/plugin_helpers",
"osd": "node ../../scripts/osd",
"test:ui:runner": "node ../../scripts/functional_test_runner.js",
"test:server": "plugin-helpers test:server",
"test:browser": "plugin-helpers test:browser",
"test:jest": "node scripts/jest --runInBand",
"test:jest:runner": "node scripts/runner test"
}
}
8 changes: 8 additions & 0 deletions plugins/wazuh-endpoints/public/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { WazuhEndpointsPlugin } from './plugin';

// This exports static code and TypeScript types,
// as well as, OpenSearch Dashboards Platform `plugin()` initializer.
export function plugin() {
return new WazuhEndpointsPlugin();
}
export { WazuhEndpointsPluginSetup, WazuhEndpointsPluginStart } from './types';
23 changes: 23 additions & 0 deletions plugins/wazuh-endpoints/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { CoreSetup, CoreStart, Plugin } from 'opensearch-dashboards/public';
import {
AppPluginStartDependencies,
WazuhEndpointsPluginSetup,
WazuhEndpointsPluginStart,
} from './types';

export class WazuhEndpointsPlugin
implements Plugin<WazuhEndpointsPluginSetup, WazuhEndpointsPluginStart>
{
public setup(core: CoreSetup): WazuhEndpointsPluginSetup {
return {};
}

public start(
core: CoreStart,
plugins: AppPluginStartDependencies,
): WazuhEndpointsPluginStart {
return {};
}

public stop() {}
}
5 changes: 5 additions & 0 deletions plugins/wazuh-endpoints/public/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface WazuhEndpointsPluginSetup {}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface WazuhEndpointsPluginStart {}

export interface AppPluginStartDependencies {}
19 changes: 19 additions & 0 deletions plugins/wazuh-endpoints/scripts/jest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// # Run Jest tests
//
// All args will be forwarded directly to Jest, e.g. to watch tests run:
//
// node scripts/jest --watch
//
// or to build code coverage:
//
// node scripts/jest --coverage
//
// See all cli options in https://facebook.github.io/jest/docs/cli.html

const path = require('path');
process.argv.push('--config', path.resolve(__dirname, '../test/jest/config.js'));

require('../../../src/setup_node_env');
const jest = require('../../../node_modules/jest');

jest.run(process.argv.slice(2));
17 changes: 17 additions & 0 deletions plugins/wazuh-endpoints/scripts/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

/* eslint-disable @typescript-eslint/no-var-requires */

const fs = require('fs');

/**
* Reads the package.json file.
* @returns {Object} JSON object.
*/
function loadPackageJson() {
const packageJson = fs.readFileSync('./package.json');
return JSON.parse(packageJson);
}

module.exports = {
loadPackageJson
};
148 changes: 148 additions & 0 deletions plugins/wazuh-endpoints/scripts/runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/* eslint-disable array-element-newline */
/* eslint-disable @typescript-eslint/no-var-requires */

/**
Runs yarn commands using a Docker container.
Intended to test and build locally.
Uses development images. Must be executed from the root folder of the project.
See /docker/runner/docker-compose.yml for available environment variables.
# Usage:
# -------------
# - node scripts/runner <command> [<command_args>]
# - yarn test:jest:runner [<jest_args>]
# - yarn build:runner
*/

const childProcess = require('child_process');
const { loadPackageJson } = require('./manifest');

const COMPOSE_DIR = '../../docker/runner';

function getProjectInfo() {
const manifest = loadPackageJson();

return {
app: 'osd',
version: manifest['pluginPlatform']['version'],
repo: process.cwd(),
};
}

function getBuildArgs({ app, version }) {
return `--opensearch-dashboards-version=${version}`;
}

/**
* Transforms the Jest CLI options from process.argv back to a string.
* If no options are provided, default ones are generated.
* @returns {String} Space separated string with all Jest CLI options provided.
*/
function getJestArgs() {
// Take args only after `test` word
const index = process.argv.indexOf('test');
const args = process.argv.slice(index + 1);
// Remove duplicates using set
return Array.from(new Set([...args, '--runInBand'])).join(' ');
}

/**
* Generates the execution parameters if they are not set.
* @returns {Object} Default environment variables.
*/
const buildEnvVars = ({ app, version, repo, cmd, args }) => {
return {
APP: app,
VERSION: version,
REPO: repo,
CMD: cmd,
ARGS: args,
};
};

/**
* Captures the SIGINT signal (Ctrl + C) to stop the container and exit.
*/
function setupAbortController() {
process.on('SIGINT', () => {
childProcess.spawnSync('docker', [
'compose',
'--project-directory',
COMPOSE_DIR,
'stop',
]);
process.exit();
});
}

/**
* Start the container.
*/
function startRunner() {
const runner = childProcess.spawn('docker', [
'compose',
'--project-directory',
COMPOSE_DIR,
'up',
]);

runner.stdout.on('data', data => {
console.log(`${data}`);
});

runner.stderr.on('data', data => {
console.error(`${data}`);
});
}

/**
* Main function
*/
function main() {
if (process.argv.length < 2) {
process.stderr.write('Required parameters not provided');
process.exit(-1);
}

const projectInfo = getProjectInfo();
let envVars = {};

switch (process.argv[2]) {
case 'build':
envVars = buildEnvVars({
...projectInfo,
cmd: 'plugin-helpers build',
args: getBuildArgs({ ...projectInfo }),
});
break;

case 'test':
envVars = buildEnvVars({
...projectInfo,
cmd: 'test:jest',
args: getJestArgs(),
});
break;

default:
// usage();
console.error('Unsupported or invalid yarn command.');
process.exit(-1);
}

// Check the required environment variables are set
for (const [key, value] of Object.entries(envVars)) {
if (!process.env[key]) {
process.env[key] = value;
}
console.log(`${key}: ${process.env[key]}`);
}

setupAbortController();
startRunner();
}

main();
11 changes: 11 additions & 0 deletions plugins/wazuh-endpoints/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { PluginInitializerContext } from '../../../src/core/server';
import { WazuhEndpointsPlugin } from './plugin';

// This exports static code and TypeScript types,
// as well as, OpenSearch Dashboards Platform `plugin()` initializer.

export function plugin(initializerContext: PluginInitializerContext) {
return new WazuhEndpointsPlugin(initializerContext);
}

export { WazuhEndpointsPluginSetup, WazuhEndpointsPluginStart } from './types';
37 changes: 37 additions & 0 deletions plugins/wazuh-endpoints/server/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
PluginInitializerContext,
CoreSetup,
CoreStart,
Plugin,
Logger,
} from 'opensearch-dashboards/server';

import {
PluginSetup,
WazuhEndpointsPluginSetup,
WazuhEndpointsPluginStart,
AppPluginStartDependencies,
} from './types';

export class WazuhEndpointsPlugin
implements Plugin<WazuhEndpointsPluginSetup, WazuhEndpointsPluginStart> {
private readonly logger: Logger;

constructor(initializerContext: PluginInitializerContext) {
this.logger = initializerContext.logger.get();
}

public async setup(core: CoreSetup, plugins: PluginSetup) {
this.logger.debug('wazuh_endpoints: Setup');

return {};
}

public start(core: CoreStart, plugins: AppPluginStartDependencies): WazuhEndpointsPluginStart {
this.logger.debug('wazuh_endpoints: Started');

return {};
}

public stop() {}
}
10 changes: 10 additions & 0 deletions plugins/wazuh-endpoints/server/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface AppPluginStartDependencies {}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface WazuhEndpointsPluginSetup {}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface WazuhEndpointsPluginStart {}

export type PluginSetup = {};

export interface AppPluginStartDependencies {}
Loading

0 comments on commit 4357c94

Please sign in to comment.