-
Notifications
You must be signed in to change notification settings - Fork 875
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instantiate credential management plugin code structure (#1996)
- Loading branch information
Showing
15 changed files
with
383 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
This comment has been minimized.
Sorry, something went wrong. |
||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/** | ||
* For new files created by OpenSearch Contributors | ||
*/ | ||
const OSD_NEW_HEADER = ` | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
`; | ||
|
||
module.exports = { | ||
root: true, | ||
extends: ['@elastic/eslint-config-kibana', 'plugin:@elastic/eui/recommended'], | ||
rules: { | ||
'@osd/eslint/require-license-header': [ | ||
'error', | ||
{ | ||
licenses: [OSD_NEW_HEADER], | ||
}, | ||
], | ||
}, | ||
}; |
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": "credentialManagement", | ||
"paths": { | ||
"credentialManagement": "." | ||
}, | ||
"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,11 @@ | ||
# credentialManagement | ||
|
||
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. |
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 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export const PLUGIN_ID = 'credentialManagement'; | ||
export const PLUGIN_NAME = 'credentialManagement'; |
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": "credentialManagement", | ||
"version": "1.0.0", | ||
"opensearchDashboardsVersion": "opensearchDashboards", | ||
"server": true, | ||
"ui": true, | ||
"requiredPlugins": ["navigation"], | ||
This comment has been minimized.
Sorry, something went wrong.
zengyan-amazon
Member
|
||
"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,28 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { AppMountParameters, CoreStart } from '../../../core/public'; | ||
import { AppPluginStartDependencies } from './types'; | ||
import { CredentialManagementApp } from './components/app'; | ||
|
||
export const renderApp = ( | ||
{ notifications, http }: CoreStart, | ||
{ navigation }: AppPluginStartDependencies, | ||
{ appBasePath, element }: AppMountParameters | ||
) => { | ||
ReactDOM.render( | ||
<CredentialManagementApp | ||
basename={appBasePath} | ||
This comment has been minimized.
Sorry, something went wrong. |
||
notifications={notifications} | ||
http={http} | ||
navigation={navigation} | ||
/>, | ||
element | ||
); | ||
|
||
return () => ReactDOM.unmountComponentAtNode(element); | ||
}; |
124 changes: 124 additions & 0 deletions
124
src/plugins/credential_management/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,124 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
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 { | ||
EuiButton, | ||
EuiHorizontalRule, | ||
EuiPage, | ||
EuiPageBody, | ||
EuiPageContent, | ||
EuiPageContentBody, | ||
EuiPageContentHeader, | ||
EuiPageHeader, | ||
EuiTitle, | ||
EuiText, | ||
} from '@elastic/eui'; | ||
|
||
import { CoreStart } from '../../../../core/public'; | ||
import { NavigationPublicPluginStart } from '../../../navigation/public'; | ||
|
||
import { PLUGIN_ID, PLUGIN_NAME } from '../../common'; | ||
|
||
interface CredentialManagementAppDeps { | ||
basename: string; | ||
notifications: CoreStart['notifications']; | ||
http: CoreStart['http']; | ||
navigation: NavigationPublicPluginStart; | ||
} | ||
|
||
export const CredentialManagementApp = ({ | ||
basename, | ||
notifications, | ||
http, | ||
navigation, | ||
}: CredentialManagementAppDeps) => { | ||
// Use React hooks to manage state. | ||
const [timestamp, setTimestamp] = useState<string | undefined>(); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
const onClickHandler = () => { | ||
// Use the core http service to make a response to the server API. | ||
http.get('/api/credential_management/example').then((res) => { | ||
setTimestamp(res.time); | ||
// Use the core notifications service to display a success message. | ||
notifications.toasts.addSuccess( | ||
i18n.translate('credentialManagement.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="credentialManagement.helloWorldText" | ||
defaultMessage="{name}" | ||
values={{ name: PLUGIN_NAME }} | ||
/> | ||
</h1> | ||
</EuiTitle> | ||
</EuiPageHeader> | ||
<EuiPageContent> | ||
<EuiPageContentHeader> | ||
<EuiTitle> | ||
<h2> | ||
<FormattedMessage | ||
id="credentialManagement.congratulationsTitle" | ||
defaultMessage="Congratulations, you have successfully created a new OpenSearch Dashboards Plugin!" | ||
/> | ||
</h2> | ||
</EuiTitle> | ||
</EuiPageContentHeader> | ||
<EuiPageContentBody> | ||
<EuiText> | ||
<p> | ||
<FormattedMessage | ||
id="credentialManagement.content" | ||
defaultMessage="Look through the generated code and check out the plugin development documentation." | ||
/> | ||
</p> | ||
<EuiHorizontalRule /> | ||
<p> | ||
<FormattedMessage | ||
id="credentialManagement.timestampText" | ||
defaultMessage="Last timestamp: {time}" | ||
values={{ time: timestamp ? timestamp : 'Unknown' }} | ||
/> | ||
</p> | ||
<EuiButton type="primary" size="s" onClick={onClickHandler}> | ||
<FormattedMessage | ||
id="credentialManagement.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,15 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import './index.scss'; | ||
|
||
import { CredentialManagementPlugin } from './plugin'; | ||
|
||
// This exports static code and TypeScript types, | ||
// as well as, OpenSearch Dashboards Platform `plugin()` initializer. | ||
export function plugin() { | ||
return new CredentialManagementPlugin(); | ||
} | ||
export { CredentialManagementPluginSetup, CredentialManagementPluginStart } 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,50 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { i18n } from '@osd/i18n'; | ||
import { AppMountParameters, CoreSetup, CoreStart, Plugin } from '../../../core/public'; | ||
import { | ||
CredentialManagementPluginSetup, | ||
CredentialManagementPluginStart, | ||
AppPluginStartDependencies, | ||
} from './types'; | ||
import { PLUGIN_NAME } from '../common'; | ||
|
||
export class CredentialManagementPlugin | ||
implements Plugin<CredentialManagementPluginSetup, CredentialManagementPluginStart> { | ||
public setup(core: CoreSetup): CredentialManagementPluginSetup { | ||
// Register an application into the side navigation menu | ||
core.application.register({ | ||
id: 'credentialManagement', | ||
title: PLUGIN_NAME, | ||
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() { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
return i18n.translate('credentialManagement.greetingText', { | ||
defaultMessage: 'Hello from {name}!', | ||
values: { | ||
name: PLUGIN_NAME, | ||
}, | ||
}); | ||
}, | ||
}; | ||
} | ||
|
||
public start(core: CoreStart): CredentialManagementPluginStart { | ||
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 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { NavigationPublicPluginStart } from '../../navigation/public'; | ||
|
||
export interface CredentialManagementPluginSetup { | ||
getGreeting: () => string; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface CredentialManagementPluginStart {} | ||
|
||
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,16 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { PluginInitializerContext } from '../../../core/server'; | ||
import { CredentialManagementPlugin } from './plugin'; | ||
|
||
// This exports static code and TypeScript types, | ||
// as well as, OpenSearch Dashboards Platform `plugin()` initializer. | ||
|
||
export function plugin(initializerContext: PluginInitializerContext) { | ||
return new CredentialManagementPlugin(initializerContext); | ||
} | ||
|
||
export { CredentialManagementPluginSetup, CredentialManagementPluginStart } 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 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { | ||
PluginInitializerContext, | ||
CoreSetup, | ||
CoreStart, | ||
Plugin, | ||
Logger, | ||
} from '../../../core/server'; | ||
|
||
import { CredentialManagementPluginSetup, CredentialManagementPluginStart } from './types'; | ||
import { defineRoutes } from './routes'; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
export class CredentialManagementPlugin | ||
implements Plugin<CredentialManagementPluginSetup, CredentialManagementPluginStart> { | ||
private readonly logger: Logger; | ||
|
||
constructor(initializerContext: PluginInitializerContext) { | ||
this.logger = initializerContext.logger.get(); | ||
} | ||
|
||
public setup(core: CoreSetup) { | ||
this.logger.debug('credentialManagement: Setup'); | ||
const router = core.http.createRouter(); | ||
|
||
// Register server side APIs | ||
defineRoutes(router); | ||
|
||
return {}; | ||
} | ||
|
||
public start(core: CoreStart) { | ||
this.logger.debug('credentialManagement: 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,22 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { IRouter } from '../../../../core/server'; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
export function defineRoutes(router: IRouter) { | ||
router.get( | ||
{ | ||
path: '/api/credential_management/example', | ||
validate: false, | ||
}, | ||
async (context, request, response) => { | ||
return 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,9 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface CredentialManagementPluginSetup {} | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface CredentialManagementPluginStart {} |
remove this file, we should use one single lint config for the entire repo