diff --git a/src/plugins/data_source/server/plugin.ts b/src/plugins/data_source/server/plugin.ts index 2374e32b9183..b70f73a7d7de 100644 --- a/src/plugins/data_source/server/plugin.ts +++ b/src/plugins/data_source/server/plugin.ts @@ -119,7 +119,12 @@ export class DataSourcePlugin implements Plugin { this.logger.info( @@ -159,12 +164,6 @@ export class DataSourcePlugin implements Plugin ): IContextProvider, 'dataSource'> => { return (context, req) => { - authRegistryPromise.then((auth) => { - if (auth !== undefined) - logger.info( - `Total item found in auth registry is ${auth.getAllAuthenticationMethods().length}` - ); - }); return { opensearch: { getClient: (dataSourceId: string) => { diff --git a/src/plugins/data_source/server/routes/test_connection.ts b/src/plugins/data_source/server/routes/test_connection.ts index cba42517e535..93d996e05b90 100644 --- a/src/plugins/data_source/server/routes/test_connection.ts +++ b/src/plugins/data_source/server/routes/test_connection.ts @@ -9,11 +9,13 @@ import { AuthType, DataSourceAttributes, SigV4ServiceName } from '../../common/d import { DataSourceConnectionValidator } from './data_source_connection_validator'; import { DataSourceServiceSetup } from '../data_source_service'; import { CryptographyServiceSetup } from '../cryptography_service'; +import { IAuthenticationMethodRegistery } from '../../common/auth_registry'; export const registerTestConnectionRoute = ( router: IRouter, dataSourceServiceSetup: DataSourceServiceSetup, - cryptography: CryptographyServiceSetup + cryptography: CryptographyServiceSetup, + authRegistryPromise: Promise ) => { router.post( { @@ -25,28 +27,25 @@ export const registerTestConnectionRoute = ( endpoint: schema.string(), auth: schema.maybe( schema.object({ - type: schema.oneOf([ - schema.literal(AuthType.UsernamePasswordType), - schema.literal(AuthType.NoAuth), - schema.literal(AuthType.SigV4), - ]), - credentials: schema.maybe( - schema.oneOf([ - schema.object({ - username: schema.string(), - password: schema.string(), - }), - schema.object({ - region: schema.string(), - accessKey: schema.string(), - secretKey: schema.string(), - service: schema.oneOf([ - schema.literal(SigV4ServiceName.OpenSearch), - schema.literal(SigV4ServiceName.OpenSearchServerless), - ]), - }), - ]) - ), + type: schema.maybe(schema.string()), + credentials: schema.any(), + // credentials: schema.maybe( + // schema.oneOf([ + // schema.object({ + // username: schema.string(), + // password: schema.string(), + // }), + // schema.object({ + // region: schema.string(), + // accessKey: schema.string(), + // secretKey: schema.string(), + // service: schema.oneOf([ + // schema.literal(SigV4ServiceName.OpenSearch), + // schema.literal(SigV4ServiceName.OpenSearchServerless), + // ]), + // }), + // ]) + // ), }) ), }), @@ -63,6 +62,7 @@ export const registerTestConnectionRoute = ( cryptography, dataSourceId, testClientDataSourceAttr: dataSourceAttr as DataSourceAttributes, + authRegistryPromise, } ); diff --git a/src/plugins/data_source_management/common/auth_registry/authentication_methods_registry.ts b/src/plugins/data_source_management/common/auth_registry/authentication_methods_registry.ts index 059500b78059..6f8e81ae9ec1 100644 --- a/src/plugins/data_source_management/common/auth_registry/authentication_methods_registry.ts +++ b/src/plugins/data_source_management/common/auth_registry/authentication_methods_registry.ts @@ -4,10 +4,12 @@ */ import { EuiSuperSelectOption } from '@elastic/eui'; +import { AuthTypeContent } from 'src/plugins/data_source/common/data_sources'; export interface AuthMethodUIElements { credentialForm: React.JSX.Element; credentialSourceOption: EuiSuperSelectOption; + credentialsFormValues: AuthTypeContent; } 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 8f4c37476302..f0858392a179 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 @@ -22,7 +22,11 @@ import { } from '@elastic/eui'; import { i18n } from '@osd/i18n'; import { FormattedMessage } from '@osd/i18n/react'; -import { SigV4Content, SigV4ServiceName } from '../../../../../../data_source/common/data_sources'; +import { + AuthTypeContent, + SigV4Content, + SigV4ServiceName, +} from '../../../../../../data_source/common/data_sources'; import { AuthType, credentialSourceOptions, @@ -58,7 +62,7 @@ export interface CreateDataSourceState { endpoint: string; auth: { type: AuthType; - credentials: UsernamePasswordTypedContent | SigV4Content; + credentials: UsernamePasswordTypedContent | SigV4Content | AuthTypeContent; }; } @@ -320,6 +324,10 @@ export class CreateDataSourceForm extends React.Component< service: this.state.auth.credentials.service || SigV4ServiceName.OpenSearch, } as SigV4Content; } + // Get credentials from authRegistry. + const authMethod = this.props.authRegistry.getAuthenticationMethod(this.state.auth.type); + credentials = authMethod?.credentialsFormValues; + console.log(`Inside getFormValues > credentials ${credentials}`); return { title: this.state.title,