Skip to content

Commit

Permalink
Plugin created
Browse files Browse the repository at this point in the history
  • Loading branch information
yenienserrano committed Jan 14, 2025
1 parent 4aa5ab8 commit fb7ef7f
Show file tree
Hide file tree
Showing 19 changed files with 456 additions and 0 deletions.
1 change: 1 addition & 0 deletions docker/osd-dev/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ services:
- '${SRC}/main:/home/node/kbn/plugins/main'
- '${SRC}/wazuh-core:/home/node/kbn/plugins/wazuh-core'
- '${SRC}/wazuh-check-updates:/home/node/kbn/plugins/wazuh-check-updates'
- '${SRC}/wazuh-security-policies:/home/node/kbn/plugins/wazuh-security-policies'
- '${SRC}/wazuh-engine:/home/node/kbn/plugins/wazuh-engine'
- '${SRC}/wazuh-fleet:/home/node/kbn/plugins/wazuh-fleet'
- wd_certs:/home/node/kbn/certs/
Expand Down
7 changes: 7 additions & 0 deletions plugins/wazuh-security-policies/.i18nrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"prefix": "wazuhSecurityPolicies",
"paths": {
"wazuhSecurityPolicies": "."
},
"translations": ["translations/ja-JP.json"]
}
22 changes: 22 additions & 0 deletions plugins/wazuh-security-policies/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# wazuhSecurityPolicies

A OpenSearch Dashboards plugin

---

## Development

See the [OpenSearch Dashboards contributing
guide](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/CONTRIBUTING.md) for instructions
setting up your development environment.

## Scripts
<dl>
<dt><code>yarn osd bootstrap</code></dt>
<dd>Execute this to install node_modules and setup the dependencies in your plugin and in OpenSearch Dashboards
</dd>

<dt><code>yarn plugin-helpers build</code></dt>
<dd>Execute this to create a distributable version of this plugin that can be installed in OpenSearch Dashboards
</dd>
</dl>
2 changes: 2 additions & 0 deletions plugins/wazuh-security-policies/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const PLUGIN_ID = 'wazuhSecurityPolicies';
export const PLUGIN_NAME = 'Ruleset';
9 changes: 9 additions & 0 deletions plugins/wazuh-security-policies/opensearch_dashboards.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "wazuhSecurityPolicies",
"version": "1.0.0",
"opensearchDashboardsVersion": "opensearchDashboards",
"server": true,
"ui": true,
"requiredPlugins": ["navigation"],
"optionalPlugins": []
}
10 changes: 10 additions & 0 deletions plugins/wazuh-security-policies/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "wazuhSecurityPolicies",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "yarn plugin-helpers build",
"plugin-helpers": "../../scripts/use_node ../../scripts/plugin_helpers",
"osd": "../../scripts/use_node ../../scripts/osd"
}
}
23 changes: 23 additions & 0 deletions plugins/wazuh-security-policies/public/application.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { AppMountParameters, CoreStart } from '../../../src/core/public';
import { AppPluginStartDependencies } from './types';
import { WazuhSecurityPoliciesApp } from './components/app';

export const renderApp = (
{ notifications, http }: CoreStart,
{ navigation }: AppPluginStartDependencies,
{ appBasePath, element }: AppMountParameters,
) => {
ReactDOM.render(
<WazuhSecurityPoliciesApp
basename={appBasePath}
notifications={notifications}
http={http}
navigation={navigation}
/>,
element,
);

return () => ReactDOM.unmountComponentAtNode(element);
};
116 changes: 116 additions & 0 deletions plugins/wazuh-security-policies/public/components/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import React, { useState } from 'react';
import { i18n } from '@osd/i18n';
import { FormattedMessage, I18nProvider } from '@osd/i18n/react';
import { BrowserRouter as Router } from 'react-router-dom';
import {
EuiHorizontalRule,
EuiPage,
EuiPageBody,
EuiPageContent,
EuiPageContentBody,
EuiPageContentHeader,
EuiPageHeader,
EuiTitle,
EuiText,
EuiButton,
} from '@elastic/eui';
import { CoreStart } from '../../../../src/core/public';
import { NavigationPublicPluginStart } from '../../../../src/plugins/navigation/public';
import { PLUGIN_ID, PLUGIN_NAME } from '../../common';

interface WazuhSecurityPoliciesAppDeps {
basename: string;
notifications: CoreStart['notifications'];
http: CoreStart['http'];
navigation: NavigationPublicPluginStart;
}

export const WazuhSecurityPoliciesApp = ({
basename,
notifications,
http,
navigation,
}: WazuhSecurityPoliciesAppDeps) => {
// Use React hooks to manage state.
const [timestamp, setTimestamp] = useState<string | undefined>();

const onClickHandler = () => {
// Use the core http service to make a response to the server API.
http.get('/api/wazuh_security_policies/example').then(res => {
setTimestamp(res.time);
// Use the core notifications service to display a success message.
notifications.toasts.addSuccess(
i18n.translate('wazuhSecurityPolicies.dataUpdated', {
defaultMessage: 'Data updated',
}),
);
});
};

// Render the application DOM.
// Note that `navigation.ui.TopNavMenu` is a stateful component exported on the `navigation` plugin's start contract.
return (
<Router basename={basename}>
<I18nProvider>
<>
<navigation.ui.TopNavMenu
appName={PLUGIN_ID}
showSearchBar={true}
useDefaultBehaviors={true}
/>
<EuiPage restrictWidth='1000px'>
<EuiPageBody component='main'>
<EuiPageHeader>
<EuiTitle size='l'>
<h1>
<FormattedMessage
id='wazuhSecurityPolicies.helloWorldText'
defaultMessage='{name}'
values={{ name: PLUGIN_NAME }}
/>
</h1>
</EuiTitle>
</EuiPageHeader>
<EuiPageContent>
<EuiPageContentHeader>
<EuiTitle>
<h2>
<FormattedMessage
id='wazuhSecurityPolicies.congratulationsTitle'
defaultMessage='Congratulations, you have successfully created a new OpenSearch Dashboards Plugin!'
/>
</h2>
</EuiTitle>
</EuiPageContentHeader>
<EuiPageContentBody>
<EuiText>
<p>
<FormattedMessage
id='wazuhSecurityPolicies.content'
defaultMessage='Look through the generated code and check out the plugin development documentation.'
/>
</p>
<EuiHorizontalRule />
<p>
<FormattedMessage
id='wazuhSecurityPolicies.timestampText'
defaultMessage='Last timestamp: {time}'
values={{ time: timestamp ?? 'Unknown' }}
/>
</p>
<EuiButton type='primary' size='s' onClick={onClickHandler}>
<FormattedMessage
id='wazuhSecurityPolicies.buttonText'
defaultMessage='Get data'
/>
</EuiButton>
</EuiText>
</EuiPageContentBody>
</EuiPageContent>
</EuiPageBody>
</EuiPage>
</>
</I18nProvider>
</Router>
);
};
1 change: 1 addition & 0 deletions plugins/wazuh-security-policies/public/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* stylelint-disable no-empty-source */
13 changes: 13 additions & 0 deletions plugins/wazuh-security-policies/public/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import './index.scss';
import { WazuhSecurityPoliciesPlugin } from './plugin';

// This exports static code and TypeScript types,
// as well as, OpenSearch Dashboards Platform `plugin()` initializer.
export function plugin() {
return new WazuhSecurityPoliciesPlugin();
}

export {
WazuhSecurityPoliciesPluginSetup,
WazuhSecurityPoliciesPluginStart,
} from './types';
64 changes: 64 additions & 0 deletions plugins/wazuh-security-policies/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { i18n } from '@osd/i18n';
import {
AppMountParameters,
CoreSetup,
Plugin,
} from '../../../src/core/public';
import { PLUGIN_NAME } from '../common';
import {
WazuhSecurityPoliciesPluginSetup,
WazuhSecurityPoliciesPluginStart,
AppPluginStartDependencies,
} from './types';

export class WazuhSecurityPoliciesPlugin
implements
Plugin<WazuhSecurityPoliciesPluginSetup, WazuhSecurityPoliciesPluginStart>
{
public setup(core: CoreSetup): WazuhSecurityPoliciesPluginSetup {
// Register an application into the side navigation menu
core.application.register({
id: 'wazuhSecurityPolicies',
title: PLUGIN_NAME,
category: {
id: 'wz-category-security-policies',
label: i18n.translate('wz-app-category-security-policies', {
defaultMessage: 'Security Policies',
}),
order: 200,
euiIconType: 'indexRollupApp',
},
async mount(params: AppMountParameters) {
// Load application bundle
const { renderApp } = await import('./application');
// Get start services as specified in opensearch_dashboards.json
const [coreStart, depsStart] = await core.getStartServices();

// Render the application
return renderApp(
coreStart,
depsStart as AppPluginStartDependencies,
params,
);
},
});

// Return methods that should be available to other plugins
return {
getGreeting() {
return i18n.translate('wazuhSecurityPolicies.greetingText', {
defaultMessage: 'Hello from {name}!',
values: {
name: PLUGIN_NAME,
},
});
},
};
}

public start(): WazuhSecurityPoliciesPluginStart {
return {};
}

public stop() {}
}
11 changes: 11 additions & 0 deletions plugins/wazuh-security-policies/public/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { NavigationPublicPluginStart } from '../../../src/plugins/navigation/public';

export interface WazuhSecurityPoliciesPluginSetup {
getGreeting: () => string;
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/no-empty-object-type
export interface WazuhSecurityPoliciesPluginStart {}

export interface AppPluginStartDependencies {
navigation: NavigationPublicPluginStart;
}
14 changes: 14 additions & 0 deletions plugins/wazuh-security-policies/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { PluginInitializerContext } from '../../../src/core/server';
import { WazuhSecurityPoliciesPlugin } from './plugin';

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

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

export {
WazuhSecurityPoliciesPluginSetup,
WazuhSecurityPoliciesPluginStart,
} from './types';
41 changes: 41 additions & 0 deletions plugins/wazuh-security-policies/server/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {
PluginInitializerContext,
CoreSetup,
Plugin,
Logger,
} from '../../../src/core/server';
import {
WazuhSecurityPoliciesPluginSetup,
WazuhSecurityPoliciesPluginStart,
} from './types';
import { defineRoutes } from './routes';

export class WazuhSecurityPoliciesPlugin
implements
Plugin<WazuhSecurityPoliciesPluginSetup, WazuhSecurityPoliciesPluginStart>
{
private readonly logger: Logger;

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

public setup(core: CoreSetup) {
this.logger.debug('wazuhSecurityPolicies: Setup');

const router = core.http.createRouter();

// Register server side APIs
defineRoutes(router);

return {};
}

public start() {
this.logger.debug('wazuhSecurityPolicies: Started');

return {};
}

public stop() {}
}
16 changes: 16 additions & 0 deletions plugins/wazuh-security-policies/server/routes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { IRouter } from '../../../../src/core/server';

export function defineRoutes(router: IRouter) {
router.get(
{
path: '/api/wazuh_security_policies/example',
validate: false,
},
async (context, request, response) =>
response.ok({
body: {
time: new Date().toISOString(),
},
}),
);
}
5 changes: 5 additions & 0 deletions plugins/wazuh-security-policies/server/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* eslint-disable @typescript-eslint/no-empty-object-type */
// eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/no-empty-object-type
export interface WazuhSecurityPoliciesPluginSetup {}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface WazuhSecurityPoliciesPluginStart {}
Loading

0 comments on commit fb7ef7f

Please sign in to comment.