-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4aa5ab8
commit fb7ef7f
Showing
19 changed files
with
456 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"prefix": "wazuhSecurityPolicies", | ||
"paths": { | ||
"wazuhSecurityPolicies": "." | ||
}, | ||
"translations": ["translations/ja-JP.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,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> |
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,2 @@ | ||
export const PLUGIN_ID = 'wazuhSecurityPolicies'; | ||
export const PLUGIN_NAME = 'Ruleset'; |
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": "wazuhSecurityPolicies", | ||
"version": "1.0.0", | ||
"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,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" | ||
} | ||
} |
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 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
116
plugins/wazuh-security-policies/public/components/app.tsx
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,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> | ||
); | ||
}; |
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 @@ | ||
/* stylelint-disable no-empty-source */ |
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,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'; |
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,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() {} | ||
} |
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 { 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; | ||
} |
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,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'; |
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,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() {} | ||
} |
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,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(), | ||
}, | ||
}), | ||
); | ||
} |
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 @@ | ||
/* 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 {} |
Oops, something went wrong.