Skip to content

Commit

Permalink
[Bug][Data Source] Move data source manageable feature flag to DSM pl…
Browse files Browse the repository at this point in the history
…ugin (#7440)

* Move data source manageable feature flag to DSM plugin

Signed-off-by: yubonluo <[email protected]>

* Changeset file for PR #7440 created/updated

---------

Signed-off-by: yubonluo <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
yubonluo and opensearch-changeset-bot[bot] authored Jul 24, 2024
1 parent c2577f2 commit dfcd2e1
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 35 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/7440.yml
Original file line number Diff line number Diff line change
@@ -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))
2 changes: 1 addition & 1 deletion config/opensearch_dashboards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 0 additions & 6 deletions src/plugins/data_source/common/data_sources/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,3 @@ export enum DataSourceEngineType {
Elasticsearch = 'Elasticsearch',
NA = 'No Engine Type Available',
}

export enum ManageableBy {
All = 'all',
DashboardAdmin = 'dashboard_admin',
None = 'none',
}
4 changes: 0 additions & 4 deletions src/plugins/data_source/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof configSchema>;
21 changes: 0 additions & 21 deletions src/plugins/data_source/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataSourcePluginSetup, DataSourcePluginStart> {
private readonly logger: Logger;
Expand Down Expand Up @@ -83,25 +81,6 @@ export class DataSourcePlugin implements Plugin<DataSourcePluginSetup, DataSourc
dataSourceSavedObjectsClientWrapper.wrapperFactory
);

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 } };
});

core.logging.configure(
this.config$.pipe<LoggerContextConfigInput>(
map((dataSourceConfig) => ({
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data_source_management/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
10 changes: 10 additions & 0 deletions src/plugins/data_source_management/common/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export enum ManageableBy {
All = 'all',
DashboardAdmin = 'dashboard_admin',
None = 'none',
}
15 changes: 15 additions & 0 deletions src/plugins/data_source_management/config.ts
Original file line number Diff line number Diff line change
@@ -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<typeof configSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
7 changes: 6 additions & 1 deletion src/plugins/data_source_management/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -13,4 +14,8 @@ export function plugin(initializerContext: PluginInitializerContext) {
return new DataSourceManagementPlugin(initializerContext);
}

export const config: PluginConfigDescriptor<ConfigSchema> = {
schema: configSchema,
};

export { DataSourceManagementPluginSetup, DataSourceManagementPluginStart } from './types';
30 changes: 29 additions & 1 deletion src/plugins/data_source_management/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -18,27 +20,34 @@ 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;
}

export class DataSourceManagementPlugin
implements Plugin<DataSourceManagementPluginSetup, DataSourceManagementPluginStart> {
private readonly config$: Observable<ConfigSchema>;
private readonly logger: Logger;

constructor(initializerContext: PluginInitializerContext) {
this.logger = initializerContext.logger.get();
this.config$ = initializerContext.config.create<ConfigSchema>();
}

public setup(
public async setup(
core: CoreSetup,
deps: {
dataSource: DataSourceManagementPluginDependencies;
}
) {
const { dataSource } = deps;

const config: ConfigSchema = await this.config$.pipe(first()).toPromise();

const dataSourceEnabled = !!dataSource;

const openSearchDataSourceManagementClient: ILegacyClusterClient = core.opensearch.legacy.createClient(
Expand All @@ -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);
Expand Down

0 comments on commit dfcd2e1

Please sign in to comment.