Skip to content

Commit

Permalink
Refcator test connection
Browse files Browse the repository at this point in the history
Signed-off-by: Bandini Bhopi <[email protected]>
  • Loading branch information
bandinib-amzn committed Feb 7, 2024
1 parent fe62897 commit 664b521
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 32 deletions.
13 changes: 6 additions & 7 deletions src/plugins/data_source/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ export class DataSourcePlugin implements Plugin<DataSourcePluginSetup, DataSourc
);

const router = core.http.createRouter();
registerTestConnectionRoute(router, dataSourceService, cryptographyServiceSetup);
registerTestConnectionRoute(
router,
dataSourceService,
cryptographyServiceSetup,
authRegistryPromise
);

const registerCredentialProvider = (name: string, authMethodValues: AuthMethodValues) => {
this.logger.info(
Expand Down Expand Up @@ -159,12 +164,6 @@ export class DataSourcePlugin implements Plugin<DataSourcePluginSetup, DataSourc
authRegistryPromise: Promise<IAuthenticationMethodRegistery>
): IContextProvider<RequestHandler<unknown, unknown, unknown>, '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) => {
Expand Down
46 changes: 23 additions & 23 deletions src/plugins/data_source/server/routes/test_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IAuthenticationMethodRegistery>
) => {
router.post(
{
Expand All @@ -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),
// ]),
// }),
// ])
// ),
})
),
}),
Expand All @@ -63,6 +62,7 @@ export const registerTestConnectionRoute = (
cryptography,
dataSourceId,
testClientDataSourceAttr: dataSourceAttr as DataSourceAttributes,
authRegistryPromise,
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
credentialsFormValues: AuthTypeContent;
}

export type IAuthenticationMethodRegistery = Omit<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -58,7 +62,7 @@ export interface CreateDataSourceState {
endpoint: string;
auth: {
type: AuthType;
credentials: UsernamePasswordTypedContent | SigV4Content;
credentials: UsernamePasswordTypedContent | SigV4Content | AuthTypeContent;
};
}

Expand Down Expand Up @@ -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}`);

Check failure on line 330 in src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx

View workflow job for this annotation

GitHub Actions / Build and Verify on Linux (ciGroup1)

Unexpected console statement

return {
title: this.state.title,
Expand Down

0 comments on commit 664b521

Please sign in to comment.