-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create new plugin wazuh-endpoints (#6142)
* Create new plugin wazuh-endpoints * Delete import * Add github action to run plugin test * Remove github action to run plugin test
- Loading branch information
1 parent
e391616
commit 4357c94
Showing
20 changed files
with
466 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"prefix": "wazuhEndpoints", | ||
"paths": { | ||
"wazuhEndpoints": "." | ||
}, | ||
"translations": ["translations/en-US.json"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
Oops, something went wrong.