diff --git a/changelogs/fragments/7440.yml b/changelogs/fragments/7440.yml new file mode 100644 index 000000000000..9c314cc7263a --- /dev/null +++ b/changelogs/fragments/7440.yml @@ -0,0 +1,2 @@ +fix: +- [Bug][Data Source] Move data source manageable feature flag to DSM plugin ([#7440](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7440)) \ No newline at end of file diff --git a/config/opensearch_dashboards.yml b/config/opensearch_dashboards.yml index 4833c3f96e30..7ba83c9248b6 100644 --- a/config/opensearch_dashboards.yml +++ b/config/opensearch_dashboards.yml @@ -325,7 +325,7 @@ # "none": The data source is readonly for all users. # "dashboard_admin": The data source can only be managed by dashboard admin. # "all": The data source can be managed by all users. Default to "all". -# data_source.manageableBy: "all" +# data_source_management.manageableBy: "all" # Set the value of this setting to false to hide the help menu link to the OpenSearch Dashboards user survey # opensearchDashboards.survey.url: "https://survey.opensearch.org" diff --git a/src/plugins/data_source/common/data_sources/types.ts b/src/plugins/data_source/common/data_sources/types.ts index bd147ac00c04..cde21f648c61 100644 --- a/src/plugins/data_source/common/data_sources/types.ts +++ b/src/plugins/data_source/common/data_sources/types.ts @@ -60,9 +60,3 @@ export enum DataSourceEngineType { Elasticsearch = 'Elasticsearch', NA = 'No Engine Type Available', } - -export enum ManageableBy { - All = 'all', - DashboardAdmin = 'dashboard_admin', - None = 'none', -} diff --git a/src/plugins/data_source/config.ts b/src/plugins/data_source/config.ts index 36c298cde119..30824b486257 100644 --- a/src/plugins/data_source/config.ts +++ b/src/plugins/data_source/config.ts @@ -59,10 +59,6 @@ export const configSchema = schema.object({ enabled: schema.boolean({ defaultValue: true }), }), }), - manageableBy: schema.oneOf( - [schema.literal('all'), schema.literal('dashboard_admin'), schema.literal('none')], - { defaultValue: 'all' } - ), }); export type DataSourcePluginConfigType = TypeOf; diff --git a/src/plugins/data_source/server/plugin.ts b/src/plugins/data_source/server/plugin.ts index fa3085a63935..bbf5a89d1b53 100644 --- a/src/plugins/data_source/server/plugin.ts +++ b/src/plugins/data_source/server/plugin.ts @@ -33,8 +33,6 @@ import { registerTestConnectionRoute } from './routes/test_connection'; import { registerFetchDataSourceMetaDataRoute } from './routes/fetch_data_source_metadata'; import { AuthenticationMethodRegistry, IAuthenticationMethodRegistry } from './auth_registry'; import { CustomApiSchemaRegistry } from './schema_registry'; -import { ManageableBy } from '../common/data_sources'; -import { getWorkspaceState } from '../../../../src/core/server/utils'; export class DataSourcePlugin implements Plugin { private readonly logger: Logger; @@ -83,25 +81,6 @@ export class DataSourcePlugin implements Plugin ({ - dataSource: { - canManage: false, - }, - })); - - core.capabilities.registerSwitcher((request) => { - const { requestWorkspaceId, isDashboardAdmin } = getWorkspaceState(request); - // User can not manage data source in the workspace. - const canManage = - (manageableBy === ManageableBy.All && !requestWorkspaceId) || - (manageableBy === ManageableBy.DashboardAdmin && - isDashboardAdmin !== false && - !requestWorkspaceId); - - return { dataSource: { canManage } }; - }); - core.logging.configure( this.config$.pipe( map((dataSourceConfig) => ({ diff --git a/src/plugins/data_source_management/common/index.ts b/src/plugins/data_source_management/common/index.ts index 980bf8939456..2b9b3a4454bf 100644 --- a/src/plugins/data_source_management/common/index.ts +++ b/src/plugins/data_source_management/common/index.ts @@ -6,3 +6,4 @@ export const PLUGIN_ID = 'dataSourceManagement'; export const PLUGIN_NAME = 'Data sources'; export const DEFAULT_DATA_SOURCE_UI_SETTINGS_ID = 'defaultDataSource'; +export * from './types'; diff --git a/src/plugins/data_source_management/common/types.ts b/src/plugins/data_source_management/common/types.ts new file mode 100644 index 000000000000..23b2f437e248 --- /dev/null +++ b/src/plugins/data_source_management/common/types.ts @@ -0,0 +1,10 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export enum ManageableBy { + All = 'all', + DashboardAdmin = 'dashboard_admin', + None = 'none', +} diff --git a/src/plugins/data_source_management/config.ts b/src/plugins/data_source_management/config.ts new file mode 100644 index 000000000000..1a56a126a943 --- /dev/null +++ b/src/plugins/data_source_management/config.ts @@ -0,0 +1,15 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { schema, TypeOf } from '@osd/config-schema'; + +export const configSchema = schema.object({ + manageableBy: schema.oneOf( + [schema.literal('all'), schema.literal('dashboard_admin'), schema.literal('none')], + { defaultValue: 'all' } + ), +}); + +export type ConfigSchema = TypeOf; diff --git a/src/plugins/data_source_management/opensearch_dashboards.json b/src/plugins/data_source_management/opensearch_dashboards.json index a8790d04823d..fb37a16eea0f 100644 --- a/src/plugins/data_source_management/opensearch_dashboards.json +++ b/src/plugins/data_source_management/opensearch_dashboards.json @@ -6,5 +6,6 @@ "requiredPlugins": ["management", "indexPatternManagement"], "optionalPlugins": ["dataSource"], "requiredBundles": ["opensearchDashboardsReact", "dataSource", "opensearchDashboardsUtils"], - "extraPublicDirs": ["public/components/utils"] + "extraPublicDirs": ["public/components/utils"], + "configPath": ["data_source_management"] } diff --git a/src/plugins/data_source_management/server/index.ts b/src/plugins/data_source_management/server/index.ts index bf4fb4377c93..f3d229ea3f1d 100644 --- a/src/plugins/data_source_management/server/index.ts +++ b/src/plugins/data_source_management/server/index.ts @@ -3,7 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { PluginInitializerContext } from '../../../core/server'; +import { PluginConfigDescriptor, PluginInitializerContext } from '../../../core/server'; +import { ConfigSchema, configSchema } from '../config'; import { DataSourceManagementPlugin } from './plugin'; // This exports static code and TypeScript types, @@ -13,4 +14,8 @@ export function plugin(initializerContext: PluginInitializerContext) { return new DataSourceManagementPlugin(initializerContext); } +export const config: PluginConfigDescriptor = { + schema: configSchema, +}; + 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 index 97ac8cacc237..de8dcf74cf96 100644 --- a/src/plugins/data_source_management/server/plugin.ts +++ b/src/plugins/data_source_management/server/plugin.ts @@ -5,6 +5,8 @@ // eslint-disable-next-line @osd/eslint/no-restricted-paths import { DataSourcePluginSetup } from 'src/plugins/data_source/server/types'; +import { Observable } from 'rxjs'; +import { first } from 'rxjs/operators'; import { CoreSetup, CoreStart, @@ -18,6 +20,9 @@ import { setupRoutes } from './routes'; import { DataSourceManagementPluginSetup, DataSourceManagementPluginStart } from './types'; import { OpenSearchDataSourceManagementPlugin } from './adaptors/opensearch_data_source_management_plugin'; import { PPLPlugin } from './adaptors/ppl_plugin'; +import { ConfigSchema } from '../config'; +import { getWorkspaceState } from '../../../../src/core/server/utils'; +import { ManageableBy } from '../common'; export interface DataSourceManagementPluginDependencies { dataSource: DataSourcePluginSetup; @@ -25,13 +30,15 @@ export interface DataSourceManagementPluginDependencies { export class DataSourceManagementPlugin implements Plugin { + private readonly config$: Observable; private readonly logger: Logger; constructor(initializerContext: PluginInitializerContext) { this.logger = initializerContext.logger.get(); + this.config$ = initializerContext.config.create(); } - public setup( + public async setup( core: CoreSetup, deps: { dataSource: DataSourceManagementPluginDependencies; @@ -39,6 +46,8 @@ export class DataSourceManagementPlugin ) { const { dataSource } = deps; + const config: ConfigSchema = await this.config$.pipe(first()).toPromise(); + const dataSourceEnabled = !!dataSource; const openSearchDataSourceManagementClient: ILegacyClusterClient = core.opensearch.legacy.createClient( @@ -51,6 +60,25 @@ export class DataSourceManagementPlugin this.logger.debug('dataSourceManagement: Setup'); const router = core.http.createRouter(); + const { manageableBy } = config; + core.capabilities.registerProvider(() => ({ + dataSource: { + canManage: false, + }, + })); + + core.capabilities.registerSwitcher((request) => { + const { requestWorkspaceId, isDashboardAdmin } = getWorkspaceState(request); + // User can not manage data source in the workspace. + const canManage = + (manageableBy === ManageableBy.All && !requestWorkspaceId) || + (manageableBy === ManageableBy.DashboardAdmin && + isDashboardAdmin !== false && + !requestWorkspaceId); + + return { dataSource: { canManage } }; + }); + if (dataSourceEnabled) { dataSource.registerCustomApiSchema(PPLPlugin); dataSource.registerCustomApiSchema(OpenSearchDataSourceManagementPlugin);