From e863cbfae0c1cfd5eb96266cead057f8f4836433 Mon Sep 17 00:00:00 2001 From: Ryan Liang Date: Fri, 19 Jul 2024 10:25:57 -0700 Subject: [PATCH] Add the server setup Co-authored-by: Shenoy Pratik Signed-off-by: Ryan Liang --- .../opensearch_dashboards.json | 2 +- .../data_source_management/server/index.ts | 16 ++++++++ .../data_source_management/server/plugin.ts | 41 +++++++++++++++++++ .../server/routes/index.ts | 22 ++++++++++ .../data_source_management/server/types.ts | 9 ++++ 5 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 src/plugins/data_source_management/server/index.ts create mode 100644 src/plugins/data_source_management/server/plugin.ts create mode 100644 src/plugins/data_source_management/server/routes/index.ts create mode 100644 src/plugins/data_source_management/server/types.ts diff --git a/src/plugins/data_source_management/opensearch_dashboards.json b/src/plugins/data_source_management/opensearch_dashboards.json index 691667eee458..a8790d04823d 100644 --- a/src/plugins/data_source_management/opensearch_dashboards.json +++ b/src/plugins/data_source_management/opensearch_dashboards.json @@ -1,7 +1,7 @@ { "id": "dataSourceManagement", "version": "opensearchDashboards", - "server": false, + "server": true, "ui": true, "requiredPlugins": ["management", "indexPatternManagement"], "optionalPlugins": ["dataSource"], diff --git a/src/plugins/data_source_management/server/index.ts b/src/plugins/data_source_management/server/index.ts new file mode 100644 index 000000000000..bf4fb4377c93 --- /dev/null +++ b/src/plugins/data_source_management/server/index.ts @@ -0,0 +1,16 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { PluginInitializerContext } from '../../../core/server'; +import { DataSourceManagementPlugin } from './plugin'; + +// This exports static code and TypeScript types, +// as well as, OpenSearch Dashboards Platform `plugin()` initializer. + +export function plugin(initializerContext: PluginInitializerContext) { + return new DataSourceManagementPlugin(initializerContext); +} + +export { DataSourceManagementPluginSetup, DataSourceManagementPluginStart } from './types'; diff --git a/src/plugins/data_source_management/server/plugin.ts b/src/plugins/data_source_management/server/plugin.ts new file mode 100644 index 000000000000..8cbb44c231f5 --- /dev/null +++ b/src/plugins/data_source_management/server/plugin.ts @@ -0,0 +1,41 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + CoreSetup, + CoreStart, + Logger, + Plugin, + PluginInitializerContext, +} from '../../../core/server'; + +import { defineRoutes } from './routes'; +import { DataSourceManagementPluginSetup, DataSourceManagementPluginStart } from './types'; + +export class DataSourceManagementPlugin + implements Plugin { + private readonly logger: Logger; + + constructor(initializerContext: PluginInitializerContext) { + this.logger = initializerContext.logger.get(); + } + + public setup(core: CoreSetup) { + this.logger.debug('dataSourceManagement: Setup'); + const router = core.http.createRouter(); + + // Register server side APIs + defineRoutes(router); + + return {}; + } + + public start(core: CoreStart) { + this.logger.debug('dataSourceManagement: Started'); + return {}; + } + + public stop() {} +} diff --git a/src/plugins/data_source_management/server/routes/index.ts b/src/plugins/data_source_management/server/routes/index.ts new file mode 100644 index 000000000000..f36d0d203fc1 --- /dev/null +++ b/src/plugins/data_source_management/server/routes/index.ts @@ -0,0 +1,22 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { IRouter } from '../../../../core/server'; + +export function defineRoutes(router: IRouter) { + router.get( + { + path: '/api/data_source_management/example', + validate: false, + }, + async (context, request, response) => { + return response.ok({ + body: { + time: new Date().toISOString(), + }, + }); + } + ); +} diff --git a/src/plugins/data_source_management/server/types.ts b/src/plugins/data_source_management/server/types.ts new file mode 100644 index 000000000000..165220d2b81a --- /dev/null +++ b/src/plugins/data_source_management/server/types.ts @@ -0,0 +1,9 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface DataSourceManagementPluginSetup {} +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface DataSourceManagementPluginStart {}