From 333987f187531b20862105479fde7184ef7cfaa4 Mon Sep 17 00:00:00 2001 From: Xinrui Bai Date: Tue, 20 Feb 2024 00:40:14 +0000 Subject: [PATCH 01/14] [AuthType Config] Add EnabledAuthType configuration in yml file and pass value to dataSourceManagement root mount Signed-off-by: Xinrui Bai --- config/opensearch_dashboards.yml | 9 +++++++++ src/plugins/data_source/config.ts | 3 +++ src/plugins/data_source/public/plugin.ts | 2 ++ src/plugins/data_source/public/types.ts | 2 ++ src/plugins/data_source/server/index.ts | 1 + .../public/management_app/mount_management_section.tsx | 5 ++++- src/plugins/data_source_management/public/plugin.ts | 6 ++++-- src/plugins/data_source_management/public/types.ts | 1 + 8 files changed, 26 insertions(+), 3 deletions(-) diff --git a/config/opensearch_dashboards.yml b/config/opensearch_dashboards.yml index 9797335e3cce..f483f89bbbc3 100644 --- a/config/opensearch_dashboards.yml +++ b/config/opensearch_dashboards.yml @@ -270,6 +270,15 @@ # 'ff00::/8', # ] +# Full AuthType list: ['NoAuth', 'UsernamePasswordType', 'SigV4']. +# Add / Remove elements in this list to Enable / Diasble auth types. +# If this setting is commented then all options will be available. +data_source.enabledAuthTypes: [ + 'NoAuth', + 'UsernamePasswordType', + 'SigV4', +] + # 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/config.ts b/src/plugins/data_source/config.ts index d5412d32f0ff..ec2335290e1e 100644 --- a/src/plugins/data_source/config.ts +++ b/src/plugins/data_source/config.ts @@ -39,6 +39,9 @@ export const configSchema = schema.object({ appender: fileAppenderSchema, }), endpointDeniedIPs: schema.maybe(schema.arrayOf(schema.string())), + enabledAuthTypes: schema.arrayOf(schema.string(), { + defaultValue: ['NoAuth', 'UsernamePasswordType', 'SigV4'], + }), }); export type DataSourcePluginConfigType = TypeOf; diff --git a/src/plugins/data_source/public/plugin.ts b/src/plugins/data_source/public/plugin.ts index 65bee912255e..5ec380c4a79c 100644 --- a/src/plugins/data_source/public/plugin.ts +++ b/src/plugins/data_source/public/plugin.ts @@ -22,6 +22,7 @@ export class DataSourcePlugin implements Plugin = { exposeToBrowser: { enabled: true, hideLocalCluster: true, + enabledAuthTypes: true, }, schema: configSchema, }; diff --git a/src/plugins/data_source_management/public/management_app/mount_management_section.tsx b/src/plugins/data_source_management/public/management_app/mount_management_section.tsx index 9fe1f2406382..70067e4c4777 100644 --- a/src/plugins/data_source_management/public/management_app/mount_management_section.tsx +++ b/src/plugins/data_source_management/public/management_app/mount_management_section.tsx @@ -10,6 +10,7 @@ import React from 'react'; import ReactDOM from 'react-dom'; import { Route, Router, Switch } from 'react-router-dom'; import { DataPublicPluginStart } from 'src/plugins/data/public'; +import { DataSourcePluginSetup } from 'src/plugins/data_source/public'; import { ManagementAppMountParams } from '../../../management/public'; import { OpenSearchDashboardsContextProvider } from '../../../opensearch_dashboards_react/public'; @@ -24,7 +25,8 @@ export interface DataSourceManagementStartDependencies { export async function mountManagementSection( getStartServices: StartServicesAccessor, - params: ManagementAppMountParams + params: ManagementAppMountParams, + dataSource: DataSourcePluginSetup ) { const [ { chrome, application, savedObjects, uiSettings, notifications, overlays, http, docLinks }, @@ -40,6 +42,7 @@ export async function mountManagementSection( http, docLinks, setBreadcrumbs: params.setBreadcrumbs, + enabledAuthTypes: dataSource.enabledAuthTypes, }; ReactDOM.render( diff --git a/src/plugins/data_source_management/public/plugin.ts b/src/plugins/data_source_management/public/plugin.ts index 0c7123e47a94..e36a9ffe42b0 100644 --- a/src/plugins/data_source_management/public/plugin.ts +++ b/src/plugins/data_source_management/public/plugin.ts @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { DataSourcePluginSetup } from 'src/plugins/data_source/public'; import { CoreSetup, CoreStart, Plugin } from '../../../core/public'; import { PLUGIN_NAME } from '../common'; @@ -19,6 +20,7 @@ import { export interface DataSourceManagementSetupDependencies { management: ManagementSetup; indexPatternManagement: IndexPatternManagementSetup; + dataSource: DataSourcePluginSetup; } export interface DataSourceManagementPluginSetup { @@ -43,7 +45,7 @@ export class DataSourceManagementPlugin public setup( core: CoreSetup, - { management, indexPatternManagement }: DataSourceManagementSetupDependencies + { management, indexPatternManagement, dataSource }: DataSourceManagementSetupDependencies ) { const opensearchDashboardsSection = management.sections.section.opensearchDashboards; @@ -65,7 +67,7 @@ export class DataSourceManagementPlugin mount: async (params) => { const { mountManagementSection } = await import('./management_app'); - return mountManagementSection(core.getStartServices, params); + return mountManagementSection(core.getStartServices, params, dataSource); }, }); diff --git a/src/plugins/data_source_management/public/types.ts b/src/plugins/data_source_management/public/types.ts index d461daba82cc..49cca56f83bc 100644 --- a/src/plugins/data_source_management/public/types.ts +++ b/src/plugins/data_source_management/public/types.ts @@ -32,6 +32,7 @@ export interface DataSourceManagementContext { http: HttpSetup; docLinks: DocLinksStart; setBreadcrumbs: ManagementAppMountParams['setBreadcrumbs']; + enabledAuthTypes: string[]; } export interface DataSourceTableItem { From 5327710d4f83a3be816b5497d11aaff6becd9c5d Mon Sep 17 00:00:00 2001 From: Xinrui Bai Date: Tue, 20 Feb 2024 02:13:41 +0000 Subject: [PATCH 02/14] [AuthType Config] provide default auth types when types array is empty Signed-off-by: Xinrui Bai --- .../components/create_form/create_data_source_form.tsx | 4 ++++ .../public/management_app/mount_management_section.tsx | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx index 86052cff8995..6ea159fb4492 100644 --- a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx +++ b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx @@ -66,9 +66,13 @@ export class CreateDataSourceForm extends React.Component< static contextType = contextType; public readonly context!: DataSourceManagementContextValue; + enabledAuthTypes: string[]; + constructor(props: CreateDataSourceProps, context: DataSourceManagementContextValue) { super(props, context); + this.enabledAuthTypes = context.services.enabledAuthTypes; + this.state = { formErrorsByField: { ...defaultValidation }, title: '', diff --git a/src/plugins/data_source_management/public/management_app/mount_management_section.tsx b/src/plugins/data_source_management/public/management_app/mount_management_section.tsx index 70067e4c4777..67d11c2086e3 100644 --- a/src/plugins/data_source_management/public/management_app/mount_management_section.tsx +++ b/src/plugins/data_source_management/public/management_app/mount_management_section.tsx @@ -16,7 +16,7 @@ import { ManagementAppMountParams } from '../../../management/public'; import { OpenSearchDashboardsContextProvider } from '../../../opensearch_dashboards_react/public'; import { CreateDataSourceWizardWithRouter } from '../components/create_data_source_wizard'; import { DataSourceTableWithRouter } from '../components/data_source_table'; -import { DataSourceManagementContext } from '../types'; +import { AuthType, DataSourceManagementContext } from '../types'; import { EditDataSourceWithRouter } from '../components/edit_data_source'; export interface DataSourceManagementStartDependencies { @@ -32,6 +32,8 @@ export async function mountManagementSection( { chrome, application, savedObjects, uiSettings, notifications, overlays, http, docLinks }, ] = await getStartServices(); + const allSupportedAuthTypes = Object.keys(AuthType); + const deps: DataSourceManagementContext = { chrome, application, @@ -42,7 +44,10 @@ export async function mountManagementSection( http, docLinks, setBreadcrumbs: params.setBreadcrumbs, - enabledAuthTypes: dataSource.enabledAuthTypes, + enabledAuthTypes: + dataSource.enabledAuthTypes.length === 0 + ? allSupportedAuthTypes + : dataSource.enabledAuthTypes, }; ReactDOM.render( From cc913190efa68b03967215a121d7e3203263ba10 Mon Sep 17 00:00:00 2001 From: Xinrui Bai Date: Thu, 22 Feb 2024 01:55:17 +0000 Subject: [PATCH 03/14] [AuthRegistry Onboard - DataSourceCreationForm] Integrate auth cofig with AuthRegistray and providing data source options from AuthRegistry Signed-off-by: Xinrui Bai --- config/opensearch_dashboards.yml | 20 +++--- src/plugins/data_source/config.ts | 12 +++- src/plugins/data_source/public/plugin.ts | 8 ++- src/plugins/data_source/public/types.ts | 8 ++- src/plugins/data_source/server/index.ts | 2 +- .../authentication_methods_registry.ts | 2 +- .../create_form/create_data_source_form.tsx | 14 ++-- .../mount_management_section.tsx | 11 +--- .../data_source_management/public/plugin.ts | 13 +++- .../data_source_management/public/types.ts | 64 +++++++++++++------ 10 files changed, 102 insertions(+), 52 deletions(-) diff --git a/config/opensearch_dashboards.yml b/config/opensearch_dashboards.yml index f483f89bbbc3..fc7adf128564 100644 --- a/config/opensearch_dashboards.yml +++ b/config/opensearch_dashboards.yml @@ -236,7 +236,7 @@ # vis_builder.enabled: false # Set the value of this setting to true to enable multiple data source feature. -#data_source.enabled: false +data_source.enabled: true # Set the value of this setting to true to hide local cluster in data source feature. #data_source.hideLocalCluster: false # Set the value of these settings to customize crypto materials to encryption saved credentials @@ -270,14 +270,16 @@ # 'ff00::/8', # ] -# Full AuthType list: ['NoAuth', 'UsernamePasswordType', 'SigV4']. -# Add / Remove elements in this list to Enable / Diasble auth types. -# If this setting is commented then all options will be available. -data_source.enabledAuthTypes: [ - 'NoAuth', - 'UsernamePasswordType', - 'SigV4', -] +# Set enabled false to hide authentication method in OpenSearch Dashboards. +# If this setting is commented then all 3 options will be available in OpenSearch Dashboards. +# Default value will be considered to True. +data_source.authTypes: + NoAuthentication: + enabled: true + UsernamePassword: + enabled: true + AWSSigV4: + enabled: true # 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/config.ts b/src/plugins/data_source/config.ts index ec2335290e1e..50013537b127 100644 --- a/src/plugins/data_source/config.ts +++ b/src/plugins/data_source/config.ts @@ -39,8 +39,16 @@ export const configSchema = schema.object({ appender: fileAppenderSchema, }), endpointDeniedIPs: schema.maybe(schema.arrayOf(schema.string())), - enabledAuthTypes: schema.arrayOf(schema.string(), { - defaultValue: ['NoAuth', 'UsernamePasswordType', 'SigV4'], + authTypes: schema.object({ + NoAuthentication: schema.object({ + enabled: schema.boolean({ defaultValue: true }), + }), + UsernamePassword: schema.object({ + enabled: schema.boolean({ defaultValue: true }), + }), + AWSSigV4: schema.object({ + enabled: schema.boolean({ defaultValue: true }), + }), }), }); diff --git a/src/plugins/data_source/public/plugin.ts b/src/plugins/data_source/public/plugin.ts index 5ec380c4a79c..dd2f70a7c193 100644 --- a/src/plugins/data_source/public/plugin.ts +++ b/src/plugins/data_source/public/plugin.ts @@ -22,7 +22,9 @@ export class DataSourcePlugin implements Plugin = { exposeToBrowser: { enabled: true, hideLocalCluster: true, - enabledAuthTypes: true, + authTypes: true, }, schema: configSchema, }; diff --git a/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts b/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts index 98cff913483f..5c3b3481583e 100644 --- a/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts +++ b/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts @@ -8,7 +8,7 @@ import { EuiSuperSelectOption } from '@elastic/eui'; export interface AuthenticationMethod { name: string; - credentialForm: React.JSX.Element; + credentialForm?: React.JSX.Element; credentialSourceOption: EuiSuperSelectOption; } diff --git a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx index 6ea159fb4492..735da5d0d68e 100644 --- a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx +++ b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx @@ -18,13 +18,13 @@ import { EuiSuperSelect, EuiSpacer, EuiText, + EuiSuperSelectOption, } from '@elastic/eui'; import { i18n } from '@osd/i18n'; import { FormattedMessage } from '@osd/i18n/react'; import { SigV4Content, SigV4ServiceName } from '../../../../../../data_source/common/data_sources'; import { AuthType, - credentialSourceOptions, DataSourceAttributes, DataSourceManagementContextValue, UsernamePasswordTypedContent, @@ -55,7 +55,7 @@ export interface CreateDataSourceState { endpoint: string; auth: { type: AuthType; - credentials: UsernamePasswordTypedContent | SigV4Content; + credentials: UsernamePasswordTypedContent | SigV4Content | undefined; }; } @@ -66,12 +66,16 @@ export class CreateDataSourceForm extends React.Component< static contextType = contextType; public readonly context!: DataSourceManagementContextValue; - enabledAuthTypes: string[]; + authOptions: Array>; constructor(props: CreateDataSourceProps, context: DataSourceManagementContextValue) { super(props, context); - this.enabledAuthTypes = context.services.enabledAuthTypes; + this.authOptions = context.services.authenticationMethodRegistery + .getAllAuthenticationMethods() + .map((authMethod) => { + return authMethod.credentialSourceOption; + }); this.state = { formErrorsByField: { ...defaultValidation }, @@ -602,7 +606,7 @@ export class CreateDataSourceForm extends React.Component< this.onChangeAuthType(value)} name="Credential" diff --git a/src/plugins/data_source_management/public/management_app/mount_management_section.tsx b/src/plugins/data_source_management/public/management_app/mount_management_section.tsx index 67d11c2086e3..ae932e48f852 100644 --- a/src/plugins/data_source_management/public/management_app/mount_management_section.tsx +++ b/src/plugins/data_source_management/public/management_app/mount_management_section.tsx @@ -10,7 +10,6 @@ import React from 'react'; import ReactDOM from 'react-dom'; import { Route, Router, Switch } from 'react-router-dom'; import { DataPublicPluginStart } from 'src/plugins/data/public'; -import { DataSourcePluginSetup } from 'src/plugins/data_source/public'; import { ManagementAppMountParams } from '../../../management/public'; import { OpenSearchDashboardsContextProvider } from '../../../opensearch_dashboards_react/public'; @@ -18,6 +17,7 @@ import { CreateDataSourceWizardWithRouter } from '../components/create_data_sour import { DataSourceTableWithRouter } from '../components/data_source_table'; import { AuthType, DataSourceManagementContext } from '../types'; import { EditDataSourceWithRouter } from '../components/edit_data_source'; +import { AuthenticationMethodRegistery } from '../auth_registry'; export interface DataSourceManagementStartDependencies { data: DataPublicPluginStart; @@ -26,14 +26,12 @@ export interface DataSourceManagementStartDependencies { export async function mountManagementSection( getStartServices: StartServicesAccessor, params: ManagementAppMountParams, - dataSource: DataSourcePluginSetup + authMethodsRegistry: AuthenticationMethodRegistery ) { const [ { chrome, application, savedObjects, uiSettings, notifications, overlays, http, docLinks }, ] = await getStartServices(); - const allSupportedAuthTypes = Object.keys(AuthType); - const deps: DataSourceManagementContext = { chrome, application, @@ -44,10 +42,7 @@ export async function mountManagementSection( http, docLinks, setBreadcrumbs: params.setBreadcrumbs, - enabledAuthTypes: - dataSource.enabledAuthTypes.length === 0 - ? allSupportedAuthTypes - : dataSource.enabledAuthTypes, + authenticationMethodRegistery: authMethodsRegistry, }; ReactDOM.render( diff --git a/src/plugins/data_source_management/public/plugin.ts b/src/plugins/data_source_management/public/plugin.ts index e36a9ffe42b0..131e38a9765c 100644 --- a/src/plugins/data_source_management/public/plugin.ts +++ b/src/plugins/data_source_management/public/plugin.ts @@ -16,6 +16,7 @@ import { IAuthenticationMethodRegistery, AuthenticationMethodRegistery, } from './auth_registry'; +import { noAuthCredentialAuthMethod, sigV4AuthMethod, usernamePasswordAuthMethod } from './types'; export interface DataSourceManagementSetupDependencies { management: ManagementSetup; @@ -67,7 +68,7 @@ export class DataSourceManagementPlugin mount: async (params) => { const { mountManagementSection } = await import('./management_app'); - return mountManagementSection(core.getStartServices, params, dataSource); + return mountManagementSection(core.getStartServices, params, this.authMethodsRegistry); }, }); @@ -80,6 +81,16 @@ export class DataSourceManagementPlugin this.authMethodsRegistry.registerAuthenticationMethod(authMethod); }; + if (dataSource.noAuthenticationTypeEnabled) { + registerAuthenticationMethod(noAuthCredentialAuthMethod); + } + if (dataSource.usernamePasswordAuthEnabled) { + registerAuthenticationMethod(usernamePasswordAuthMethod); + } + if (dataSource.awsSigV4AuthEnabled) { + registerAuthenticationMethod(sigV4AuthMethod); + } + return { registerAuthenticationMethod }; } diff --git a/src/plugins/data_source_management/public/types.ts b/src/plugins/data_source_management/public/types.ts index 49cca56f83bc..9d9dc016e991 100644 --- a/src/plugins/data_source_management/public/types.ts +++ b/src/plugins/data_source_management/public/types.ts @@ -18,6 +18,7 @@ import { SavedObjectAttributes } from 'src/core/types'; import { i18n } from '@osd/i18n'; import { SigV4ServiceName } from '../../data_source/common/data_sources'; import { OpenSearchDashboardsReactContextValue } from '../../opensearch_dashboards_react/public'; +import { AuthenticationMethodRegistery } from './auth_registry'; // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface DataSourceManagementPluginStart {} @@ -32,7 +33,7 @@ export interface DataSourceManagementContext { http: HttpSetup; docLinks: DocLinksStart; setBreadcrumbs: ManagementAppMountParams['setBreadcrumbs']; - enabledAuthTypes: string[]; + authenticationMethodRegistery: AuthenticationMethodRegistery; } export interface DataSourceTableItem { @@ -59,26 +60,26 @@ export enum AuthType { SigV4 = 'sigv4', } -export const credentialSourceOptions = [ - { - value: AuthType.NoAuth, - inputDisplay: i18n.translate('dataSourceManagement.credentialSourceOptions.NoAuthentication', { - defaultMessage: 'No authentication', - }), - }, - { - value: AuthType.UsernamePasswordType, - inputDisplay: i18n.translate('dataSourceManagement.credentialSourceOptions.UsernamePassword', { - defaultMessage: 'Username & Password', - }), - }, - { - value: AuthType.SigV4, - inputDisplay: i18n.translate('dataSourceManagement.credentialSourceOptions.AwsSigV4', { - defaultMessage: 'AWS SigV4', - }), - }, -]; +export const noAuthCredentialOption = { + value: AuthType.NoAuth, + inputDisplay: i18n.translate('dataSourceManagement.credentialSourceOptions.NoAuthentication', { + defaultMessage: 'No authentication', + }), +}; + +export const usernamePasswordCredentialOption = { + value: AuthType.UsernamePasswordType, + inputDisplay: i18n.translate('dataSourceManagement.credentialSourceOptions.UsernamePassword', { + defaultMessage: 'Username & Password', + }), +}; + +export const sigV4CredentialOption = { + value: AuthType.SigV4, + inputDisplay: i18n.translate('dataSourceManagement.credentialSourceOptions.AwsSigV4', { + defaultMessage: 'AWS SigV4', + }), +}; export const sigV4ServiceOptions = [ { @@ -95,6 +96,27 @@ export const sigV4ServiceOptions = [ }, ]; +export const noAuthCredentialAuthMethod = { + name: AuthType.NoAuth, + credentialSourceOption: noAuthCredentialOption, +}; + +export const usernamePasswordAuthMethod = { + name: AuthType.UsernamePasswordType, + credentialSourceOption: usernamePasswordCredentialOption, +}; + +export const sigV4AuthMethod = { + name: AuthType.SigV4, + credentialSourceOption: sigV4CredentialOption, +}; + +export const credentialSourceOptions = [ + noAuthCredentialOption, + usernamePasswordCredentialOption, + sigV4CredentialOption, +]; + export interface DataSourceAttributes extends SavedObjectAttributes { title: string; description?: string; From 0339047dc65b388bf38744ac909ffd2ab3cf312a Mon Sep 17 00:00:00 2001 From: Xinrui Bai Date: Fri, 23 Feb 2024 00:12:12 +0000 Subject: [PATCH 04/14] [AuthRegistry Onboard] Support default selected auth type in datasource creation page Signed-off-by: Xinrui Bai --- .../authentication_methods_registry.ts | 3 +- .../create_form/create_data_source_form.tsx | 27 ++++++++----- .../edit_form/edit_data_source_form.tsx | 13 +++++-- .../mount_management_section.tsx | 2 +- .../data_source_management/public/types.ts | 39 +++++++++++++++---- 5 files changed, 62 insertions(+), 22 deletions(-) diff --git a/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts b/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts index 5c3b3481583e..1f1ab81aa60a 100644 --- a/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts +++ b/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts @@ -8,8 +8,9 @@ import { EuiSuperSelectOption } from '@elastic/eui'; export interface AuthenticationMethod { name: string; - credentialForm?: React.JSX.Element; credentialSourceOption: EuiSuperSelectOption; + credentialForm?: React.JSX.Element; + crendentialFormField?: any; } export type IAuthenticationMethodRegistery = Omit< diff --git a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx index 735da5d0d68e..b462d5861159 100644 --- a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx +++ b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx @@ -28,6 +28,8 @@ import { DataSourceAttributes, DataSourceManagementContextValue, UsernamePasswordTypedContent, + defaultAuthType, + noAuthCredentialAuthMethod, sigV4ServiceOptions, } from '../../../../types'; import { Header } from '../header'; @@ -66,16 +68,24 @@ export class CreateDataSourceForm extends React.Component< static contextType = contextType; public readonly context!: DataSourceManagementContextValue; - authOptions: Array>; + authOptions: Array> = []; constructor(props: CreateDataSourceProps, context: DataSourceManagementContextValue) { super(props, context); - this.authOptions = context.services.authenticationMethodRegistery - .getAllAuthenticationMethods() - .map((authMethod) => { - return authMethod.credentialSourceOption; - }); + const authenticationMethodRegistery = context.services.authenticationMethodRegistery; + const registeredAuthMethods = authenticationMethodRegistery.getAllAuthenticationMethods(); + + this.authOptions = registeredAuthMethods.map((authMethod) => { + return authMethod.credentialSourceOption; + }); + + const defaultAuthMethod = + registeredAuthMethods.length > 0 + ? authenticationMethodRegistery.getAuthenticationMethod(registeredAuthMethods[0].name) + : noAuthCredentialAuthMethod; + const initialSelectedAuthMethod = + authenticationMethodRegistery.getAuthenticationMethod(defaultAuthType) ?? defaultAuthMethod; this.state = { formErrorsByField: { ...defaultValidation }, @@ -83,10 +93,9 @@ export class CreateDataSourceForm extends React.Component< description: '', endpoint: '', auth: { - type: AuthType.UsernamePasswordType, + type: initialSelectedAuthMethod?.name, credentials: { - username: '', - password: '', + ...initialSelectedAuthMethod?.crendentialFormField, }, }, }; diff --git a/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.tsx b/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.tsx index 9af843a64071..b3f83b372f05 100644 --- a/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.tsx +++ b/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.tsx @@ -20,6 +20,7 @@ import { EuiSuperSelect, EuiSpacer, EuiText, + EuiSuperSelectOption, } from '@elastic/eui'; import { i18n } from '@osd/i18n'; import { FormattedMessage } from '@osd/i18n/react'; @@ -27,7 +28,6 @@ import { SigV4Content, SigV4ServiceName } from '../../../../../../data_source/co import { Header } from '../header'; import { AuthType, - credentialSourceOptions, DataSourceAttributes, DataSourceManagementContextValue, sigV4ServiceOptions, @@ -71,10 +71,17 @@ export class EditDataSourceForm extends React.Component> = []; constructor(props: EditDataSourceProps, context: DataSourceManagementContextValue) { super(props, context); + this.authOptions = context.services.authenticationMethodRegistery + .getAllAuthenticationMethods() + .map((authMethod) => { + return authMethod.credentialSourceOption; + }); + this.state = { formErrorsByField: { ...defaultValidation }, title: '', @@ -772,9 +779,9 @@ export class EditDataSourceForm extends React.Component this.onChangeAuthType(value)} name="Credential" data-test-subj="editDataSourceSelectAuthType" /> diff --git a/src/plugins/data_source_management/public/management_app/mount_management_section.tsx b/src/plugins/data_source_management/public/management_app/mount_management_section.tsx index ae932e48f852..6b421a32d2b2 100644 --- a/src/plugins/data_source_management/public/management_app/mount_management_section.tsx +++ b/src/plugins/data_source_management/public/management_app/mount_management_section.tsx @@ -15,7 +15,7 @@ import { ManagementAppMountParams } from '../../../management/public'; import { OpenSearchDashboardsContextProvider } from '../../../opensearch_dashboards_react/public'; import { CreateDataSourceWizardWithRouter } from '../components/create_data_source_wizard'; import { DataSourceTableWithRouter } from '../components/data_source_table'; -import { AuthType, DataSourceManagementContext } from '../types'; +import { DataSourceManagementContext } from '../types'; import { EditDataSourceWithRouter } from '../components/edit_data_source'; import { AuthenticationMethodRegistery } from '../auth_registry'; diff --git a/src/plugins/data_source_management/public/types.ts b/src/plugins/data_source_management/public/types.ts index 9d9dc016e991..7b669da15e5e 100644 --- a/src/plugins/data_source_management/public/types.ts +++ b/src/plugins/data_source_management/public/types.ts @@ -60,6 +60,8 @@ export enum AuthType { SigV4 = 'sigv4', } +export const defaultAuthType = AuthType.UsernamePasswordType; + export const noAuthCredentialOption = { value: AuthType.NoAuth, inputDisplay: i18n.translate('dataSourceManagement.credentialSourceOptions.NoAuthentication', { @@ -67,6 +69,18 @@ export const noAuthCredentialOption = { }), }; +export const noAuthCredentialField = { + username: '', + password: '', + service: 'es', +}; + +export const noAuthCredentialAuthMethod = { + name: AuthType.NoAuth, + credentialSourceOption: noAuthCredentialOption, + crendentialFormField: noAuthCredentialField, +}; + export const usernamePasswordCredentialOption = { value: AuthType.UsernamePasswordType, inputDisplay: i18n.translate('dataSourceManagement.credentialSourceOptions.UsernamePassword', { @@ -74,6 +88,17 @@ export const usernamePasswordCredentialOption = { }), }; +export const usernamePasswordCredentialField = { + username: '', + password: '', +}; + +export const usernamePasswordAuthMethod = { + name: AuthType.UsernamePasswordType, + credentialSourceOption: usernamePasswordCredentialOption, + crendentialFormField: usernamePasswordCredentialField, +}; + export const sigV4CredentialOption = { value: AuthType.SigV4, inputDisplay: i18n.translate('dataSourceManagement.credentialSourceOptions.AwsSigV4', { @@ -96,19 +121,17 @@ export const sigV4ServiceOptions = [ }, ]; -export const noAuthCredentialAuthMethod = { - name: AuthType.NoAuth, - credentialSourceOption: noAuthCredentialOption, -}; - -export const usernamePasswordAuthMethod = { - name: AuthType.UsernamePasswordType, - credentialSourceOption: usernamePasswordCredentialOption, +export const sigV4CredentialField = { + region: '', + accessKey: '', + secretKey: '', + service: '', }; export const sigV4AuthMethod = { name: AuthType.SigV4, credentialSourceOption: sigV4CredentialOption, + crendentialFormField: sigV4CredentialField, }; export const credentialSourceOptions = [ From 9b138fe0b5433eb5ca6698af20d386cb835ab43d Mon Sep 17 00:00:00 2001 From: Xinrui Bai Date: Fri, 23 Feb 2024 00:59:52 +0000 Subject: [PATCH 05/14] [AuthRegistry Onboard] SDisable auth option selector when auth options no more than 1 Signed-off-by: Xinrui Bai --- .../components/create_form/create_data_source_form.tsx | 2 ++ .../components/edit_form/edit_data_source_form.tsx | 1 + 2 files changed, 3 insertions(+) diff --git a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx index b462d5861159..2a2b7d4bd632 100644 --- a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx +++ b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx @@ -84,6 +84,7 @@ export class CreateDataSourceForm extends React.Component< registeredAuthMethods.length > 0 ? authenticationMethodRegistery.getAuthenticationMethod(registeredAuthMethods[0].name) : noAuthCredentialAuthMethod; + const initialSelectedAuthMethod = authenticationMethodRegistery.getAuthenticationMethod(defaultAuthType) ?? defaultAuthMethod; @@ -618,6 +619,7 @@ export class CreateDataSourceForm extends React.Component< options={this.authOptions} valueOfSelected={this.state.auth.type} onChange={(value) => this.onChangeAuthType(value)} + disabled={this.authOptions.length <= 1} name="Credential" data-test-subj="createDataSourceFormAuthTypeSelect" /> diff --git a/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.tsx b/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.tsx index b3f83b372f05..c3d7daa7db48 100644 --- a/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.tsx +++ b/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.tsx @@ -782,6 +782,7 @@ export class EditDataSourceForm extends React.Component this.onChangeAuthType(value)} + disabled={this.authOptions.length <= 1} name="Credential" data-test-subj="editDataSourceSelectAuthType" /> From f0b4c88b4f713babf88589d752bb16c81dbb06b0 Mon Sep 17 00:00:00 2001 From: Xinrui Bai Date: Fri, 23 Feb 2024 01:32:27 +0000 Subject: [PATCH 06/14] [AuthRegistry Onboard] clear credential attribute every time use select NoAuth option. Also update credentialField data type Signed-off-by: Xinrui Bai --- .../public/auth_registry/authentication_methods_registry.ts | 2 +- .../components/create_form/create_data_source_form.tsx | 4 ++++ src/plugins/data_source_management/public/types.ts | 6 +----- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts b/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts index 1f1ab81aa60a..0f64eb585572 100644 --- a/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts +++ b/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts @@ -10,7 +10,7 @@ export interface AuthenticationMethod { name: string; credentialSourceOption: EuiSuperSelectOption; credentialForm?: React.JSX.Element; - crendentialFormField?: any; + crendentialFormField?: { [key: string]: [value: string] }; } export type IAuthenticationMethodRegistery = Omit< diff --git a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx index 2a2b7d4bd632..2a1d47f812f6 100644 --- a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx +++ b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx @@ -30,6 +30,7 @@ import { UsernamePasswordTypedContent, defaultAuthType, noAuthCredentialAuthMethod, + noAuthCredentialField, sigV4ServiceOptions, } from '../../../../types'; import { Header } from '../header'; @@ -315,6 +316,9 @@ export class CreateDataSourceForm extends React.Component< service: this.state.auth.credentials.service || SigV4ServiceName.OpenSearch, } as SigV4Content; } + if (this.state.auth.type === AuthType.NoAuth) { + credentials = {}; + } return { title: this.state.title, diff --git a/src/plugins/data_source_management/public/types.ts b/src/plugins/data_source_management/public/types.ts index 7b669da15e5e..b0dd6caf1a11 100644 --- a/src/plugins/data_source_management/public/types.ts +++ b/src/plugins/data_source_management/public/types.ts @@ -69,11 +69,7 @@ export const noAuthCredentialOption = { }), }; -export const noAuthCredentialField = { - username: '', - password: '', - service: 'es', -}; +export const noAuthCredentialField = {}; export const noAuthCredentialAuthMethod = { name: AuthType.NoAuth, From 1ebd2e232a076be6c2a8e0a802b3bfb376c66bf0 Mon Sep 17 00:00:00 2001 From: Xinrui Bai Date: Fri, 23 Feb 2024 01:45:19 +0000 Subject: [PATCH 07/14] Update yml file to disable config Signed-off-by: Xinrui Bai --- config/opensearch_dashboards.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/config/opensearch_dashboards.yml b/config/opensearch_dashboards.yml index fc7adf128564..4f86a8729a3e 100644 --- a/config/opensearch_dashboards.yml +++ b/config/opensearch_dashboards.yml @@ -236,7 +236,7 @@ # vis_builder.enabled: false # Set the value of this setting to true to enable multiple data source feature. -data_source.enabled: true +#data_source.enabled: false # Set the value of this setting to true to hide local cluster in data source feature. #data_source.hideLocalCluster: false # Set the value of these settings to customize crypto materials to encryption saved credentials @@ -273,13 +273,13 @@ data_source.enabled: true # Set enabled false to hide authentication method in OpenSearch Dashboards. # If this setting is commented then all 3 options will be available in OpenSearch Dashboards. # Default value will be considered to True. -data_source.authTypes: - NoAuthentication: - enabled: true - UsernamePassword: - enabled: true - AWSSigV4: - enabled: true +#data_source.authTypes: +# NoAuthentication: +# enabled: true +# UsernamePassword: +# enabled: true +# AWSSigV4: +# enabled: true # 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" From 91e734e6b72cab14f8b55db86485c5eb9f37ba7a Mon Sep 17 00:00:00 2001 From: Xinrui Bai Date: Fri, 23 Feb 2024 01:51:32 +0000 Subject: [PATCH 08/14] Update change.md file Signed-off-by: Xinrui Bai --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d4a5efcb1ef..0c5b581e20db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - [Multiple Datasource] Able to Hide "Local Cluster" option from datasource DropDown ([#5827](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5827)) - [Multiple Datasource] Add api registry and allow it to be added into client config in data source plugin ([#5895](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5895)) - [Multiple Datasource] Concatenate data source name with index pattern name and change delimiter to double colon ([#5907](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5907)) +- [Multiple Datasource] Hide/Show authentication method in multi data source plugin based on configuration ([#5916](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5916)) ### 🐛 Bug Fixes From fc0369e1da131c097dc3eb5e8917906bfdc39f0d Mon Sep 17 00:00:00 2001 From: Xinrui Bai Date: Fri, 23 Feb 2024 06:15:55 +0000 Subject: [PATCH 09/14] [UT] Fix broken test cases Signed-off-by: Xinrui Bai --- .../authentication_methods_registry.ts | 2 +- .../create_form/create_data_source_form.test.tsx | 15 ++++++++++++++- .../create_form/create_data_source_form.tsx | 1 - .../edit_form/edit_data_source_form.test.tsx | 15 ++++++++++++++- .../edit_data_source/edit_data_source.test.tsx | 13 +++++++++++++ .../data_source_management/public/mocks.ts | 12 +++++++++++- 6 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts b/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts index 0f64eb585572..00c3b0dbf0ee 100644 --- a/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts +++ b/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts @@ -10,7 +10,7 @@ export interface AuthenticationMethod { name: string; credentialSourceOption: EuiSuperSelectOption; credentialForm?: React.JSX.Element; - crendentialFormField?: { [key: string]: [value: string] }; + crendentialFormField?: { [key: string]: string }; } export type IAuthenticationMethodRegistery = Omit< diff --git a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx index c3c34cbdab1d..272ff1ba88eb 100644 --- a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx +++ b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx @@ -11,7 +11,12 @@ import { OpenSearchDashboardsContextProvider } from '../../../../../../opensearc import { CreateDataSourceForm } from './create_data_source_form'; // @ts-ignore import { findTestSubject } from '@elastic/eui/lib/test'; -import { AuthType } from '../../../../types'; +import { + AuthType, + noAuthCredentialAuthMethod, + sigV4AuthMethod, + usernamePasswordAuthMethod, +} from '../../../../types'; const titleIdentifier = '[data-test-subj="createDataSourceFormTitleField"]'; const descriptionIdentifier = `[data-test-subj="createDataSourceFormDescriptionField"]`; @@ -24,6 +29,14 @@ const testConnectionButtonIdentifier = '[data-test-subj="createDataSourceTestCon describe('Datasource Management: Create Datasource form', () => { const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); + mockedContext.authenticationMethodRegistery.registerAuthenticationMethod( + noAuthCredentialAuthMethod + ); + mockedContext.authenticationMethodRegistery.registerAuthenticationMethod( + usernamePasswordAuthMethod + ); + mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(sigV4AuthMethod); + let component: ReactWrapper, React.Component<{}, {}, any>>; const mockSubmitHandler = jest.fn(); const mockTestConnectionHandler = jest.fn(); diff --git a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx index 2a1d47f812f6..e98e2d7ff960 100644 --- a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx +++ b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx @@ -30,7 +30,6 @@ import { UsernamePasswordTypedContent, defaultAuthType, noAuthCredentialAuthMethod, - noAuthCredentialField, sigV4ServiceOptions, } from '../../../../types'; import { Header } from '../header'; diff --git a/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.test.tsx b/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.test.tsx index c57b5b414ed3..4326d6e6832d 100644 --- a/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.test.tsx +++ b/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.test.tsx @@ -15,7 +15,12 @@ import { import { OpenSearchDashboardsContextProvider } from '../../../../../../opensearch_dashboards_react/public'; import { EditDataSourceForm } from './edit_data_source_form'; import { act } from 'react-dom/test-utils'; -import { AuthType } from '../../../../types'; +import { + AuthType, + noAuthCredentialAuthMethod, + sigV4AuthMethod, + usernamePasswordAuthMethod, +} from '../../../../types'; const titleFieldIdentifier = 'dataSourceTitle'; const titleFormRowIdentifier = '[data-test-subj="editDataSourceTitleFormRow"]'; @@ -29,6 +34,14 @@ const passwordFieldIdentifier = '[data-test-subj="updateDataSourceFormPasswordFi const updatePasswordBtnIdentifier = '[data-test-subj="editDatasourceUpdatePasswordBtn"]'; describe('Datasource Management: Edit Datasource Form', () => { const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); + mockedContext.authenticationMethodRegistery.registerAuthenticationMethod( + noAuthCredentialAuthMethod + ); + mockedContext.authenticationMethodRegistery.registerAuthenticationMethod( + usernamePasswordAuthMethod + ); + mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(sigV4AuthMethod); + let component: ReactWrapper, React.Component<{}, {}, any>>; const mockFn = jest.fn(); diff --git a/src/plugins/data_source_management/public/components/edit_data_source/edit_data_source.test.tsx b/src/plugins/data_source_management/public/components/edit_data_source/edit_data_source.test.tsx index 5f6e823e0f86..c1516a507d4a 100644 --- a/src/plugins/data_source_management/public/components/edit_data_source/edit_data_source.test.tsx +++ b/src/plugins/data_source_management/public/components/edit_data_source/edit_data_source.test.tsx @@ -18,12 +18,25 @@ import { wrapWithIntl } from 'test_utils/enzyme_helpers'; import { RouteComponentProps } from 'react-router-dom'; import { OpenSearchDashboardsContextProvider } from '../../../../opensearch_dashboards_react/public'; import { EditDataSource } from './edit_data_source'; +import { + noAuthCredentialAuthMethod, + sigV4AuthMethod, + usernamePasswordAuthMethod, +} from '../../types'; const formIdentifier = 'EditDataSourceForm'; const notFoundIdentifier = '[data-test-subj="dataSourceNotFound"]'; describe('Datasource Management: Edit Datasource Wizard', () => { const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); + mockedContext.authenticationMethodRegistery.registerAuthenticationMethod( + noAuthCredentialAuthMethod + ); + mockedContext.authenticationMethodRegistery.registerAuthenticationMethod( + usernamePasswordAuthMethod + ); + mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(sigV4AuthMethod); + let component: ReactWrapper, React.Component<{}, {}, any>>; const history = (scopedHistoryMock.create() as unknown) as ScopedHistory; diff --git a/src/plugins/data_source_management/public/mocks.ts b/src/plugins/data_source_management/public/mocks.ts index 7b170c4a7c79..71e0310cb870 100644 --- a/src/plugins/data_source_management/public/mocks.ts +++ b/src/plugins/data_source_management/public/mocks.ts @@ -15,7 +15,7 @@ import { } from './plugin'; import { managementPluginMock } from '../../management/public/mocks'; import { mockManagementPlugin as indexPatternManagementPluginMock } from '../../index_pattern_management/public/mocks'; -import { AuthenticationMethod } from './auth_registry'; +import { AuthenticationMethod, AuthenticationMethodRegistery } from './auth_registry'; /* Mock Types */ @@ -30,6 +30,8 @@ export const docLinks = { }, }; +export const authenticationMethodRegistery = new AuthenticationMethodRegistery(); + const createDataSourceManagementContext = () => { const { chrome, @@ -51,6 +53,7 @@ const createDataSourceManagementContext = () => { http, docLinks, setBreadcrumbs: () => {}, + authenticationMethodRegistery, }; }; @@ -220,6 +223,13 @@ export const testDataSourceManagementPlugin = ( const setup = plugin.setup(coreSetup, { management: managementPluginMock.createSetupContract(), indexPatternManagement: indexPatternManagementPluginMock.createSetupContract(), + dataSource: { + dataSourceEnabled: true, + hideLocalCluster: true, + noAuthenticationTypeEnabled: true, + usernamePasswordAuthEnabled: true, + awsSigV4AuthEnabled: true, + }, }); const doStart = () => { const start = plugin.start(coreStart); From f0201efc953fc3ec5b18a24687352c3c07d246b1 Mon Sep 17 00:00:00 2001 From: Xinrui Bai Date: Fri, 23 Feb 2024 19:39:21 +0000 Subject: [PATCH 10/14] [UT] Add more unit tests Signed-off-by: Xinrui Bai --- .../create_data_source_form.test.tsx | 128 ++++++++++++++++++ .../create_form/create_data_source_form.tsx | 13 +- .../public/components/utils.test.ts | 55 +++++++- .../public/components/utils.ts | 24 +++- 4 files changed, 207 insertions(+), 13 deletions(-) diff --git a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx index 272ff1ba88eb..36d415712178 100644 --- a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx +++ b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx @@ -17,6 +17,7 @@ import { sigV4AuthMethod, usernamePasswordAuthMethod, } from '../../../../types'; +import { AuthenticationMethodRegistery } from 'src/plugins/data_source_management/public/auth_registry'; const titleIdentifier = '[data-test-subj="createDataSourceFormTitleField"]'; const descriptionIdentifier = `[data-test-subj="createDataSourceFormDescriptionField"]`; @@ -26,6 +27,7 @@ const usernameIdentifier = '[data-test-subj="createDataSourceFormUsernameField"] const passwordIdentifier = '[data-test-subj="createDataSourceFormPasswordField"]'; const createButtonIdentifier = '[data-test-subj="createDataSourceButton"]'; const testConnectionButtonIdentifier = '[data-test-subj="createDataSourceTestConnectionButton"]'; +const authOptionSelectorIdentifier = '[data-test-subj="createDataSourceFormAuthTypeSelect"]'; describe('Datasource Management: Create Datasource form', () => { const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); @@ -235,3 +237,129 @@ describe('Datasource Management: Create Datasource form', () => { expect(component.find(passwordIdentifier).first().props().isInvalid).toBe(false); }); }); + +describe('Datasource Management: Create Datasource form with different authType configurations', () => { + let component: ReactWrapper, React.Component<{}, {}, any>>; + const mockSubmitHandler = jest.fn(); + const mockTestConnectionHandler = jest.fn(); + const mockCancelHandler = jest.fn(); + + /* Scenario 1: Should render the page normally with all authMethod combinations */ + test('should render normally with all authMethod combinations', () => { + const authMethodCombinationsToBeTested = [ + [noAuthCredentialAuthMethod], + [usernamePasswordAuthMethod], + [sigV4AuthMethod], + [noAuthCredentialAuthMethod, usernamePasswordAuthMethod], + [noAuthCredentialAuthMethod, sigV4AuthMethod], + [usernamePasswordAuthMethod, sigV4AuthMethod], + [noAuthCredentialAuthMethod, usernamePasswordAuthMethod, sigV4AuthMethod], + ]; + + authMethodCombinationsToBeTested.forEach((authMethodCombination) => { + const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); + mockedContext.authenticationMethodRegistery = new AuthenticationMethodRegistery(); + + authMethodCombination.forEach((authMethod) => { + mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(authMethod); + }); + + component = mount( + wrapWithIntl( + + ), + { + wrappingComponent: OpenSearchDashboardsContextProvider, + wrappingComponentProps: { + services: mockedContext, + }, + } + ); + + const testConnBtn = component.find(testConnectionButtonIdentifier).last(); + expect(testConnBtn.prop('disabled')).toBe(true); + }); + }); + + /* Scenario 2: options selector should be disabled when only one authMethod supported */ + test('options selector should be disabled when only one authMethod supported', () => { + const authMethodCombinationsToBeTested = [ + [noAuthCredentialAuthMethod], + [usernamePasswordAuthMethod], + [sigV4AuthMethod], + ]; + + authMethodCombinationsToBeTested.forEach((authMethodCombination) => { + const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); + mockedContext.authenticationMethodRegistery = new AuthenticationMethodRegistery(); + + authMethodCombination.forEach((authMethod) => { + mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(authMethod); + }); + + component = mount( + wrapWithIntl( + + ), + { + wrappingComponent: OpenSearchDashboardsContextProvider, + wrappingComponentProps: { + services: mockedContext, + }, + } + ); + + const authOptionSelector = component.find(authOptionSelectorIdentifier).last(); + expect(authOptionSelector.prop('disabled')).toBe(true); + }); + }); + + /* Scenario 3: options selector should not be disabled when more than one authMethod supported */ + test('options selector should not be disabled when more than one authMethod supported', () => { + const authMethodCombinationsToBeTested = [ + [sigV4AuthMethod, usernamePasswordAuthMethod], + [noAuthCredentialAuthMethod, sigV4AuthMethod], + [noAuthCredentialAuthMethod, usernamePasswordAuthMethod], + [noAuthCredentialAuthMethod, sigV4AuthMethod, usernamePasswordAuthMethod], + ]; + + authMethodCombinationsToBeTested.forEach((authMethodCombination) => { + const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); + mockedContext.authenticationMethodRegistery = new AuthenticationMethodRegistery(); + + authMethodCombination.forEach((authMethod) => { + mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(authMethod); + }); + + component = mount( + wrapWithIntl( + + ), + { + wrappingComponent: OpenSearchDashboardsContextProvider, + wrappingComponentProps: { + services: mockedContext, + }, + } + ); + + const authOptionSelector = component.find(authOptionSelectorIdentifier).last(); + expect(authOptionSelector.prop('disabled')).toBe(false); + }); + }); +}); diff --git a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx index e98e2d7ff960..2fb89bb64554 100644 --- a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx +++ b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx @@ -28,8 +28,6 @@ import { DataSourceAttributes, DataSourceManagementContextValue, UsernamePasswordTypedContent, - defaultAuthType, - noAuthCredentialAuthMethod, sigV4ServiceOptions, } from '../../../../types'; import { Header } from '../header'; @@ -40,7 +38,7 @@ import { isTitleValid, performDataSourceFormValidation, } from '../../../validation'; -import { isValidUrl } from '../../../utils'; +import { getDefaultAuthMethod, isValidUrl } from '../../../utils'; export interface CreateDataSourceProps { existingDatasourceNamesList: string[]; @@ -75,19 +73,12 @@ export class CreateDataSourceForm extends React.Component< const authenticationMethodRegistery = context.services.authenticationMethodRegistery; const registeredAuthMethods = authenticationMethodRegistery.getAllAuthenticationMethods(); + const initialSelectedAuthMethod = getDefaultAuthMethod(authenticationMethodRegistery); this.authOptions = registeredAuthMethods.map((authMethod) => { return authMethod.credentialSourceOption; }); - const defaultAuthMethod = - registeredAuthMethods.length > 0 - ? authenticationMethodRegistery.getAuthenticationMethod(registeredAuthMethods[0].name) - : noAuthCredentialAuthMethod; - - const initialSelectedAuthMethod = - authenticationMethodRegistery.getAuthenticationMethod(defaultAuthType) ?? defaultAuthMethod; - this.state = { formErrorsByField: { ...defaultValidation }, title: '', diff --git a/src/plugins/data_source_management/public/components/utils.test.ts b/src/plugins/data_source_management/public/components/utils.test.ts index a94d5b2260e6..1b78b20e19d1 100644 --- a/src/plugins/data_source_management/public/components/utils.test.ts +++ b/src/plugins/data_source_management/public/components/utils.test.ts @@ -9,6 +9,7 @@ import { deleteMultipleDataSources, getDataSourceById, getDataSources, + getDefaultAuthMethod, isValidUrl, testConnection, updateDataSourceById, @@ -23,8 +24,14 @@ import { mockErrorResponseForSavedObjectsCalls, mockResponseForSavedObjectsCalls, } from '../mocks'; -import { AuthType } from '../types'; +import { + AuthType, + noAuthCredentialAuthMethod, + sigV4AuthMethod, + usernamePasswordAuthMethod, +} from '../types'; import { HttpStart } from 'opensearch-dashboards/public'; +import { AuthenticationMethodRegistery } from '../auth_registry'; const { savedObjects } = coreMock.createStart(); @@ -219,4 +226,50 @@ describe('DataSourceManagement: Utils.ts', () => { /* True cases: port number scenario*/ expect(isValidUrl('http://192.168.1.1:1234/')).toBeTruthy(); }); + + describe('Check default auth method', () => { + test('default auth method is Username & Password when Username & Password is enabled', () => { + const authMethodCombinationsToBeTested = [ + [usernamePasswordAuthMethod], + [sigV4AuthMethod, usernamePasswordAuthMethod], + [noAuthCredentialAuthMethod, usernamePasswordAuthMethod], + [noAuthCredentialAuthMethod, sigV4AuthMethod, usernamePasswordAuthMethod], + ]; + + authMethodCombinationsToBeTested.forEach((authOptions) => { + const authenticationMethodRegistery = new AuthenticationMethodRegistery(); + + authOptions.forEach((authMethod) => { + authenticationMethodRegistery.registerAuthenticationMethod(authMethod); + }); + + expect(getDefaultAuthMethod(authenticationMethodRegistery)?.name).toBe( + AuthType.UsernamePasswordType + ); + }); + }); + + test('default auth method is first one in AuthList when Username & Password is not enabled', () => { + const authMethodCombinationsToBeTested = [ + [sigV4AuthMethod], + [noAuthCredentialAuthMethod], + [sigV4AuthMethod, noAuthCredentialAuthMethod], + ]; + + authMethodCombinationsToBeTested.forEach((authOptions) => { + const authenticationMethodRegistery = new AuthenticationMethodRegistery(); + + authOptions.forEach((authMethod) => { + authenticationMethodRegistery.registerAuthenticationMethod(authMethod); + }); + + expect(getDefaultAuthMethod(authenticationMethodRegistery)?.name).toBe(authOptions[0].name); + }); + }); + + test('default auth method is NoAuth when no auth options configured', () => { + const authenticationMethodRegistery = new AuthenticationMethodRegistery(); + expect(getDefaultAuthMethod(authenticationMethodRegistery)?.name).toBe(AuthType.NoAuth); + }); + }); }); diff --git a/src/plugins/data_source_management/public/components/utils.ts b/src/plugins/data_source_management/public/components/utils.ts index 5f2cfb2337ad..726fcc527f30 100644 --- a/src/plugins/data_source_management/public/components/utils.ts +++ b/src/plugins/data_source_management/public/components/utils.ts @@ -4,7 +4,13 @@ */ import { HttpStart, SavedObjectsClientContract } from 'src/core/public'; -import { DataSourceAttributes, DataSourceTableItem } from '../types'; +import { + DataSourceAttributes, + DataSourceTableItem, + defaultAuthType, + noAuthCredentialAuthMethod, +} from '../types'; +import { AuthenticationMethodRegistery } from '../auth_registry'; export async function getDataSources(savedObjectsClient: SavedObjectsClientContract) { return savedObjectsClient @@ -108,3 +114,19 @@ export const isValidUrl = (endpoint: string) => { return false; } }; + +export const getDefaultAuthMethod = ( + authenticationMethodRegistery: AuthenticationMethodRegistery +) => { + const registeredAuthMethods = authenticationMethodRegistery.getAllAuthenticationMethods(); + + const defaultAuthMethod = + registeredAuthMethods.length > 0 + ? authenticationMethodRegistery.getAuthenticationMethod(registeredAuthMethods[0].name) + : noAuthCredentialAuthMethod; + + const initialSelectedAuthMethod = + authenticationMethodRegistery.getAuthenticationMethod(defaultAuthType) ?? defaultAuthMethod; + + return initialSelectedAuthMethod; +}; From c2da4e2ac9f5231e09ce37409e1995bfde5a4304 Mon Sep 17 00:00:00 2001 From: Xinrui Bai Date: Tue, 27 Feb 2024 01:07:37 +0000 Subject: [PATCH 11/14] [UT] update unit test and handle scenario when no options enabled Signed-off-by: Xinrui Bai --- .../create_data_source_form.test.tsx.snap | 1657 +++++++++++++++++ .../create_data_source_form.test.tsx | 18 +- .../create_form/create_data_source_form.tsx | 18 +- 3 files changed, 1679 insertions(+), 14 deletions(-) create mode 100644 src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/__snapshots__/create_data_source_form.test.tsx.snap diff --git a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/__snapshots__/create_data_source_form.test.tsx.snap b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/__snapshots__/create_data_source_form.test.tsx.snap new file mode 100644 index 000000000000..2bb1bd8053d7 --- /dev/null +++ b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/__snapshots__/create_data_source_form.test.tsx.snap @@ -0,0 +1,1657 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Datasource Management: Create Datasource form with different authType configurations should render normally with all authMethod combinations 1`] = ` + + + } + isOpen={false} + panelPaddingSize="none" + > + + [Function] + + } + buttonRef={[Function]} + className="euiInputPopover euiSuperSelect" + closePopover={[Function]} + display="block" + hasArrow={true} + isOpen={false} + ownFocus={false} + panelPaddingSize="none" + panelRef={[Function]} + > + +
+
+ +
+ + + +
+
+ + + + Select an option: AWS SigV4, is selected + + + + + +
+ + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+`; + +exports[`Datasource Management: Create Datasource form with different authType configurations should render normally with all authMethod combinations 2`] = ` + + + } + isOpen={false} + panelPaddingSize="none" + > + + [Function] + + } + buttonRef={[Function]} + className="euiInputPopover euiSuperSelect" + closePopover={[Function]} + display="block" + hasArrow={true} + isOpen={false} + ownFocus={false} + panelPaddingSize="none" + panelRef={[Function]} + > + +
+
+ +
+ + + +
+
+ + + + Select an option: No authentication, is selected + + + + + +
+ + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+`; + +exports[`Datasource Management: Create Datasource form with different authType configurations should render normally with all authMethod combinations 3`] = ` + + + } + isOpen={false} + panelPaddingSize="none" + > + + [Function] + + } + buttonRef={[Function]} + className="euiInputPopover euiSuperSelect" + closePopover={[Function]} + display="block" + hasArrow={true} + isOpen={false} + ownFocus={false} + panelPaddingSize="none" + panelRef={[Function]} + > + +
+
+ +
+ + + +
+
+ + + + Select an option: Username & Password, is selected + + + + + +
+ + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+`; + +exports[`Datasource Management: Create Datasource form with different authType configurations should render normally with all authMethod combinations 4`] = ` + + + } + isOpen={false} + panelPaddingSize="none" + > + + [Function] + + } + buttonRef={[Function]} + className="euiInputPopover euiSuperSelect" + closePopover={[Function]} + display="block" + hasArrow={true} + isOpen={false} + ownFocus={false} + panelPaddingSize="none" + panelRef={[Function]} + > + +
+
+ +
+ + + +
+
+ + + + Select an option: No authentication, is selected + + + + + +
+ + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+`; + +exports[`Datasource Management: Create Datasource form with different authType configurations should render normally with all authMethod combinations 5`] = ` + + + } + isOpen={false} + panelPaddingSize="none" + > + + [Function] + + } + buttonRef={[Function]} + className="euiInputPopover euiSuperSelect" + closePopover={[Function]} + display="block" + hasArrow={true} + isOpen={false} + ownFocus={false} + panelPaddingSize="none" + panelRef={[Function]} + > + +
+
+ +
+ + + +
+
+ + + + Select an option: Username & Password, is selected + + + + + +
+ + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+`; + +exports[`Datasource Management: Create Datasource form with different authType configurations should render normally with all authMethod combinations 6`] = ` + + + } + isOpen={false} + panelPaddingSize="none" + > + + [Function] + + } + buttonRef={[Function]} + className="euiInputPopover euiSuperSelect" + closePopover={[Function]} + display="block" + hasArrow={true} + isOpen={false} + ownFocus={false} + panelPaddingSize="none" + panelRef={[Function]} + > + +
+
+ +
+ + + +
+
+ + + + Select an option: Username & Password, is selected + + + + + +
+ + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+`; + +exports[`Datasource Management: Create Datasource form with different authType configurations should render normally with all authMethod combinations 7`] = ` + + + } + isOpen={false} + panelPaddingSize="none" + > + + [Function] + + } + buttonRef={[Function]} + className="euiInputPopover euiSuperSelect" + closePopover={[Function]} + display="block" + hasArrow={true} + isOpen={false} + ownFocus={false} + panelPaddingSize="none" + panelRef={[Function]} + > + +
+
+ +
+ + + +
+
+ + + + Select an option: Username & Password, is selected + + + + + +
+ + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+`; diff --git a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx index 36d415712178..4f30ba9da5e4 100644 --- a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx +++ b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx @@ -27,7 +27,6 @@ const usernameIdentifier = '[data-test-subj="createDataSourceFormUsernameField"] const passwordIdentifier = '[data-test-subj="createDataSourceFormPasswordField"]'; const createButtonIdentifier = '[data-test-subj="createDataSourceButton"]'; const testConnectionButtonIdentifier = '[data-test-subj="createDataSourceTestConnectionButton"]'; -const authOptionSelectorIdentifier = '[data-test-subj="createDataSourceFormAuthTypeSelect"]'; describe('Datasource Management: Create Datasource form', () => { const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); @@ -247,12 +246,12 @@ describe('Datasource Management: Create Datasource form with different authType /* Scenario 1: Should render the page normally with all authMethod combinations */ test('should render normally with all authMethod combinations', () => { const authMethodCombinationsToBeTested = [ + [sigV4AuthMethod], [noAuthCredentialAuthMethod], [usernamePasswordAuthMethod], - [sigV4AuthMethod], - [noAuthCredentialAuthMethod, usernamePasswordAuthMethod], [noAuthCredentialAuthMethod, sigV4AuthMethod], [usernamePasswordAuthMethod, sigV4AuthMethod], + [noAuthCredentialAuthMethod, usernamePasswordAuthMethod], [noAuthCredentialAuthMethod, usernamePasswordAuthMethod, sigV4AuthMethod], ]; @@ -281,17 +280,18 @@ describe('Datasource Management: Create Datasource form with different authType } ); - const testConnBtn = component.find(testConnectionButtonIdentifier).last(); - expect(testConnBtn.prop('disabled')).toBe(true); + const authOptionSelector = component.find(authTypeIdentifier).first(); + expect(authOptionSelector).toMatchSnapshot(); }); }); /* Scenario 2: options selector should be disabled when only one authMethod supported */ - test('options selector should be disabled when only one authMethod supported', () => { + test('options selector should be disabled when less than or equal to one authMethod supported', () => { const authMethodCombinationsToBeTested = [ + [], + [sigV4AuthMethod], [noAuthCredentialAuthMethod], [usernamePasswordAuthMethod], - [sigV4AuthMethod], ]; authMethodCombinationsToBeTested.forEach((authMethodCombination) => { @@ -319,7 +319,7 @@ describe('Datasource Management: Create Datasource form with different authType } ); - const authOptionSelector = component.find(authOptionSelectorIdentifier).last(); + const authOptionSelector = component.find(authTypeIdentifier).last(); expect(authOptionSelector.prop('disabled')).toBe(true); }); }); @@ -358,7 +358,7 @@ describe('Datasource Management: Create Datasource form with different authType } ); - const authOptionSelector = component.find(authOptionSelectorIdentifier).last(); + const authOptionSelector = component.find(authTypeIdentifier).last(); expect(authOptionSelector.prop('disabled')).toBe(false); }); }); diff --git a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx index 2fb89bb64554..f62f2f7d4261 100644 --- a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx +++ b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx @@ -595,14 +595,22 @@ export class CreateDataSourceForm extends React.Component< - + {this.authOptions.length > 0 && ( - + )} + {this.authOptions.length > 0 && ( + + + + )}
From 8f2c75a016a1643b919a1fecf97ae7564d96b174 Mon Sep 17 00:00:00 2001 From: Xinrui Bai Date: Tue, 27 Feb 2024 01:17:04 +0000 Subject: [PATCH 12/14] [UT] update description of unit test case Signed-off-by: Xinrui Bai --- .../data_source_management/public/components/utils.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/data_source_management/public/components/utils.test.ts b/src/plugins/data_source_management/public/components/utils.test.ts index 1b78b20e19d1..d19136d62f50 100644 --- a/src/plugins/data_source_management/public/components/utils.test.ts +++ b/src/plugins/data_source_management/public/components/utils.test.ts @@ -267,7 +267,7 @@ describe('DataSourceManagement: Utils.ts', () => { }); }); - test('default auth method is NoAuth when no auth options configured', () => { + test('default auth type is NoAuth when no auth options registered in authenticationMethodRegistery, this should not happen in real customer scenario for MD', () => { const authenticationMethodRegistery = new AuthenticationMethodRegistery(); expect(getDefaultAuthMethod(authenticationMethodRegistery)?.name).toBe(AuthType.NoAuth); }); From 6d7463edcea183be263867220cbc31596bb36d71 Mon Sep 17 00:00:00 2001 From: Xinrui Bai Date: Tue, 27 Feb 2024 01:26:19 +0000 Subject: [PATCH 13/14] [UT] update unit test cases to resolve comment Signed-off-by: Xinrui Bai --- .../create_data_source_form.test.tsx.snap | 1657 ----------------- .../create_data_source_form.test.tsx | 4 +- 2 files changed, 2 insertions(+), 1659 deletions(-) delete mode 100644 src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/__snapshots__/create_data_source_form.test.tsx.snap diff --git a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/__snapshots__/create_data_source_form.test.tsx.snap b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/__snapshots__/create_data_source_form.test.tsx.snap deleted file mode 100644 index 2bb1bd8053d7..000000000000 --- a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/__snapshots__/create_data_source_form.test.tsx.snap +++ /dev/null @@ -1,1657 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Datasource Management: Create Datasource form with different authType configurations should render normally with all authMethod combinations 1`] = ` - - - } - isOpen={false} - panelPaddingSize="none" - > - - [Function] - - } - buttonRef={[Function]} - className="euiInputPopover euiSuperSelect" - closePopover={[Function]} - display="block" - hasArrow={true} - isOpen={false} - ownFocus={false} - panelPaddingSize="none" - panelRef={[Function]} - > - -
-
- -
- - - -
-
- - - - Select an option: AWS SigV4, is selected - - - - - -
- - - - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-`; - -exports[`Datasource Management: Create Datasource form with different authType configurations should render normally with all authMethod combinations 2`] = ` - - - } - isOpen={false} - panelPaddingSize="none" - > - - [Function] - - } - buttonRef={[Function]} - className="euiInputPopover euiSuperSelect" - closePopover={[Function]} - display="block" - hasArrow={true} - isOpen={false} - ownFocus={false} - panelPaddingSize="none" - panelRef={[Function]} - > - -
-
- -
- - - -
-
- - - - Select an option: No authentication, is selected - - - - - -
- - - - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-`; - -exports[`Datasource Management: Create Datasource form with different authType configurations should render normally with all authMethod combinations 3`] = ` - - - } - isOpen={false} - panelPaddingSize="none" - > - - [Function] - - } - buttonRef={[Function]} - className="euiInputPopover euiSuperSelect" - closePopover={[Function]} - display="block" - hasArrow={true} - isOpen={false} - ownFocus={false} - panelPaddingSize="none" - panelRef={[Function]} - > - -
-
- -
- - - -
-
- - - - Select an option: Username & Password, is selected - - - - - -
- - - - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-`; - -exports[`Datasource Management: Create Datasource form with different authType configurations should render normally with all authMethod combinations 4`] = ` - - - } - isOpen={false} - panelPaddingSize="none" - > - - [Function] - - } - buttonRef={[Function]} - className="euiInputPopover euiSuperSelect" - closePopover={[Function]} - display="block" - hasArrow={true} - isOpen={false} - ownFocus={false} - panelPaddingSize="none" - panelRef={[Function]} - > - -
-
- -
- - - -
-
- - - - Select an option: No authentication, is selected - - - - - -
- - - - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-`; - -exports[`Datasource Management: Create Datasource form with different authType configurations should render normally with all authMethod combinations 5`] = ` - - - } - isOpen={false} - panelPaddingSize="none" - > - - [Function] - - } - buttonRef={[Function]} - className="euiInputPopover euiSuperSelect" - closePopover={[Function]} - display="block" - hasArrow={true} - isOpen={false} - ownFocus={false} - panelPaddingSize="none" - panelRef={[Function]} - > - -
-
- -
- - - -
-
- - - - Select an option: Username & Password, is selected - - - - - -
- - - - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-`; - -exports[`Datasource Management: Create Datasource form with different authType configurations should render normally with all authMethod combinations 6`] = ` - - - } - isOpen={false} - panelPaddingSize="none" - > - - [Function] - - } - buttonRef={[Function]} - className="euiInputPopover euiSuperSelect" - closePopover={[Function]} - display="block" - hasArrow={true} - isOpen={false} - ownFocus={false} - panelPaddingSize="none" - panelRef={[Function]} - > - -
-
- -
- - - -
-
- - - - Select an option: Username & Password, is selected - - - - - -
- - - - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-`; - -exports[`Datasource Management: Create Datasource form with different authType configurations should render normally with all authMethod combinations 7`] = ` - - - } - isOpen={false} - panelPaddingSize="none" - > - - [Function] - - } - buttonRef={[Function]} - className="euiInputPopover euiSuperSelect" - closePopover={[Function]} - display="block" - hasArrow={true} - isOpen={false} - ownFocus={false} - panelPaddingSize="none" - panelRef={[Function]} - > - -
-
- -
- - - -
-
- - - - Select an option: Username & Password, is selected - - - - - -
- - - - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-`; diff --git a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx index 4f30ba9da5e4..c4e298043b47 100644 --- a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx +++ b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx @@ -280,8 +280,8 @@ describe('Datasource Management: Create Datasource form with different authType } ); - const authOptionSelector = component.find(authTypeIdentifier).first(); - expect(authOptionSelector).toMatchSnapshot(); + const testConnBtn = component.find(testConnectionButtonIdentifier).last(); + expect(testConnBtn.prop('disabled')).toBe(true); }); }); From 9d3959879e75614ac7f12c945cd7a05e568b987c Mon Sep 17 00:00:00 2001 From: Xinrui Bai Date: Tue, 27 Feb 2024 21:26:36 +0000 Subject: [PATCH 14/14] [UT] Snapshot auth option super selector for unit test. Also upate the default message in datasorurce creation form ---> auth type section Signed-off-by: Xinrui Bai --- .../create_data_source_form.test.tsx.snap | 1657 +++++++++++++++++ .../create_data_source_form.test.tsx | 4 +- .../create_form/create_data_source_form.tsx | 8 +- 3 files changed, 1665 insertions(+), 4 deletions(-) create mode 100644 src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/__snapshots__/create_data_source_form.test.tsx.snap diff --git a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/__snapshots__/create_data_source_form.test.tsx.snap b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/__snapshots__/create_data_source_form.test.tsx.snap new file mode 100644 index 000000000000..2bb1bd8053d7 --- /dev/null +++ b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/__snapshots__/create_data_source_form.test.tsx.snap @@ -0,0 +1,1657 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Datasource Management: Create Datasource form with different authType configurations should render normally with all authMethod combinations 1`] = ` + + + } + isOpen={false} + panelPaddingSize="none" + > + + [Function] + + } + buttonRef={[Function]} + className="euiInputPopover euiSuperSelect" + closePopover={[Function]} + display="block" + hasArrow={true} + isOpen={false} + ownFocus={false} + panelPaddingSize="none" + panelRef={[Function]} + > + +
+
+ +
+ + + +
+
+ + + + Select an option: AWS SigV4, is selected + + + + + +
+ + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+`; + +exports[`Datasource Management: Create Datasource form with different authType configurations should render normally with all authMethod combinations 2`] = ` + + + } + isOpen={false} + panelPaddingSize="none" + > + + [Function] + + } + buttonRef={[Function]} + className="euiInputPopover euiSuperSelect" + closePopover={[Function]} + display="block" + hasArrow={true} + isOpen={false} + ownFocus={false} + panelPaddingSize="none" + panelRef={[Function]} + > + +
+
+ +
+ + + +
+
+ + + + Select an option: No authentication, is selected + + + + + +
+ + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+`; + +exports[`Datasource Management: Create Datasource form with different authType configurations should render normally with all authMethod combinations 3`] = ` + + + } + isOpen={false} + panelPaddingSize="none" + > + + [Function] + + } + buttonRef={[Function]} + className="euiInputPopover euiSuperSelect" + closePopover={[Function]} + display="block" + hasArrow={true} + isOpen={false} + ownFocus={false} + panelPaddingSize="none" + panelRef={[Function]} + > + +
+
+ +
+ + + +
+
+ + + + Select an option: Username & Password, is selected + + + + + +
+ + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+`; + +exports[`Datasource Management: Create Datasource form with different authType configurations should render normally with all authMethod combinations 4`] = ` + + + } + isOpen={false} + panelPaddingSize="none" + > + + [Function] + + } + buttonRef={[Function]} + className="euiInputPopover euiSuperSelect" + closePopover={[Function]} + display="block" + hasArrow={true} + isOpen={false} + ownFocus={false} + panelPaddingSize="none" + panelRef={[Function]} + > + +
+
+ +
+ + + +
+
+ + + + Select an option: No authentication, is selected + + + + + +
+ + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+`; + +exports[`Datasource Management: Create Datasource form with different authType configurations should render normally with all authMethod combinations 5`] = ` + + + } + isOpen={false} + panelPaddingSize="none" + > + + [Function] + + } + buttonRef={[Function]} + className="euiInputPopover euiSuperSelect" + closePopover={[Function]} + display="block" + hasArrow={true} + isOpen={false} + ownFocus={false} + panelPaddingSize="none" + panelRef={[Function]} + > + +
+
+ +
+ + + +
+
+ + + + Select an option: Username & Password, is selected + + + + + +
+ + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+`; + +exports[`Datasource Management: Create Datasource form with different authType configurations should render normally with all authMethod combinations 6`] = ` + + + } + isOpen={false} + panelPaddingSize="none" + > + + [Function] + + } + buttonRef={[Function]} + className="euiInputPopover euiSuperSelect" + closePopover={[Function]} + display="block" + hasArrow={true} + isOpen={false} + ownFocus={false} + panelPaddingSize="none" + panelRef={[Function]} + > + +
+
+ +
+ + + +
+
+ + + + Select an option: Username & Password, is selected + + + + + +
+ + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+`; + +exports[`Datasource Management: Create Datasource form with different authType configurations should render normally with all authMethod combinations 7`] = ` + + + } + isOpen={false} + panelPaddingSize="none" + > + + [Function] + + } + buttonRef={[Function]} + className="euiInputPopover euiSuperSelect" + closePopover={[Function]} + display="block" + hasArrow={true} + isOpen={false} + ownFocus={false} + panelPaddingSize="none" + panelRef={[Function]} + > + +
+
+ +
+ + + +
+
+ + + + Select an option: Username & Password, is selected + + + + + +
+ + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+`; diff --git a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx index c4e298043b47..4f30ba9da5e4 100644 --- a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx +++ b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx @@ -280,8 +280,8 @@ describe('Datasource Management: Create Datasource form with different authType } ); - const testConnBtn = component.find(testConnectionButtonIdentifier).last(); - expect(testConnBtn.prop('disabled')).toBe(true); + const authOptionSelector = component.find(authTypeIdentifier).first(); + expect(authOptionSelector).toMatchSnapshot(); }); }); diff --git a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx index f62f2f7d4261..e178ea1bcffa 100644 --- a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx +++ b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx @@ -67,6 +67,7 @@ export class CreateDataSourceForm extends React.Component< public readonly context!: DataSourceManagementContextValue; authOptions: Array> = []; + isNoAuthOptionEnabled: boolean; constructor(props: CreateDataSourceProps, context: DataSourceManagementContextValue) { super(props, context); @@ -75,6 +76,9 @@ export class CreateDataSourceForm extends React.Component< const registeredAuthMethods = authenticationMethodRegistery.getAllAuthenticationMethods(); const initialSelectedAuthMethod = getDefaultAuthMethod(authenticationMethodRegistery); + this.isNoAuthOptionEnabled = + authenticationMethodRegistery.getAuthenticationMethod(AuthType.NoAuth) !== undefined; + this.authOptions = registeredAuthMethods.map((authMethod) => { return authMethod.credentialSourceOption; }); @@ -597,13 +601,13 @@ export class CreateDataSourceForm extends React.Component< id="dataSourcesManagement.createDataSource.authenticationMethodDescription" defaultMessage="Enter the authentication details to access the endpoint." /> - {this.authOptions.length > 0 && ( + {this.isNoAuthOptionEnabled && ( )} - {this.authOptions.length > 0 && ( + {this.isNoAuthOptionEnabled && (