Skip to content

Commit

Permalink
Add registerCredentialProvider in data source plugin setup
Browse files Browse the repository at this point in the history
Signed-off-by: Bandini Bhopi <[email protected]>
  • Loading branch information
bandinib-amzn committed Jan 27, 2024
1 parent f8ee03a commit 3b96379
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/plugins/data_source/common/data_sources/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { SavedObjectAttributes } from 'src/core/types';

export interface DataSourceAttributes extends SavedObjectAttributes {
Expand All @@ -11,7 +10,7 @@ export interface DataSourceAttributes extends SavedObjectAttributes {
endpoint: string;
auth: {
type: AuthType;
credentials: UsernamePasswordTypedContent | SigV4Content | undefined;
credentials: UsernamePasswordTypedContent | SigV4Content | undefined | SavedObjectAttributes;
};
lastUpdatedTime?: string;
}
Expand All @@ -26,6 +25,7 @@ export interface SigV4Content extends SavedObjectAttributes {
secretKey: string;
region: string;
service?: SigV4ServiceName;
sessionToken?: string;
}

export interface UsernamePasswordTypedContent extends SavedObjectAttributes {
Expand Down
12 changes: 10 additions & 2 deletions src/plugins/data_source/server/client/configure_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Client, ClientOptions } from '@opensearch-project/opensearch';
import { Client as LegacyClient } from 'elasticsearch';
import { Credentials } from 'aws-sdk';
import { AwsSigv4Signer } from '@opensearch-project/opensearch/aws';
import { Logger } from '../../../../../src/core/server';
import { Logger, OpenSearchDashboardsRequest } from '../../../../../src/core/server';
import {
AuthType,
DataSourceAttributes,
Expand All @@ -29,7 +29,13 @@ import {
} from './configure_client_utils';

export const configureClient = async (
{ dataSourceId, savedObjects, cryptography, testClientDataSourceAttr }: DataSourceClientParams,
{
dataSourceId,
savedObjects,
cryptography,
testClientDataSourceAttr,
request,
}: DataSourceClientParams,
openSearchClientPoolSetup: OpenSearchClientPoolSetup,
config: DataSourcePluginConfigType,
logger: Logger
Expand Down Expand Up @@ -68,6 +74,7 @@ export const configureClient = async (
dataSource,
openSearchClientPoolSetup.addClientToPool,
config,
request,
cryptography,
rootClient,
dataSourceId,
Expand Down Expand Up @@ -98,6 +105,7 @@ const getQueryClient = async (
dataSourceAttr: DataSourceAttributes,
addClientToPool: (endpoint: string, authType: AuthType, client: Client | LegacyClient) => void,
config: DataSourcePluginConfigType,
request: OpenSearchDashboardsRequest,
cryptography?: CryptographyServiceSetup,
rootClient?: Client,
dataSourceId?: string,
Expand Down
20 changes: 19 additions & 1 deletion src/plugins/data_source/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import { LoggingAuditor } from './audit/logging_auditor';
import { CryptographyService, CryptographyServiceSetup } from './cryptography_service';
import { DataSourceService, DataSourceServiceSetup } from './data_source_service';
import { DataSourceSavedObjectsClientWrapper, dataSource } from './saved_objects';
import { DataSourcePluginSetup, DataSourcePluginStart } from './types';
import {
DataSourcePluginSetup,
DataSourcePluginStart,
DataSourceCredentialsProvider,
} from './types';
import { DATA_SOURCE_SAVED_OBJECT_TYPE } from '../common';

// eslint-disable-next-line @osd/eslint/no-restricted-paths
Expand Down Expand Up @@ -109,8 +113,20 @@ export class DataSourcePlugin implements Plugin<DataSourcePluginSetup, DataSourc
const router = core.http.createRouter();
registerTestConnectionRoute(router, dataSourceService, cryptographyServiceSetup);

const registerCredentialProvider = (
authType: string,
credentialProvider: DataSourceCredentialsProvider
) => {
this.logger.info(`Registered Credential Provider for authType = ${authType}`);
/*
Add in auth registry
this.authRegistery.registerAuth(authType, credentialProvider);
*/
};

return {
createDataSourceError: (e: any) => createDataSourceError(e),
registerCredentialProvider,
};
}

Expand Down Expand Up @@ -142,6 +158,7 @@ export class DataSourcePlugin implements Plugin<DataSourcePluginSetup, DataSourc
dataSourceId,
savedObjects: context.core.savedObjects.client,
cryptography,
request: req,
});
},
legacy: {
Expand All @@ -150,6 +167,7 @@ export class DataSourcePlugin implements Plugin<DataSourcePluginSetup, DataSourc
dataSourceId,
savedObjects: context.core.savedObjects.client,
cryptography,
request: req,
});
},
},
Expand Down
17 changes: 17 additions & 0 deletions src/plugins/data_source/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
LegacyCallAPIOptions,
OpenSearchClient,
SavedObjectsClientContract,
OpenSearchDashboardsRequest,
} from 'src/core/server';
import { DataSourceAttributes } from '../common/data_sources';

Expand All @@ -27,8 +28,19 @@ export interface DataSourceClientParams {
dataSourceId?: string;
// required when creating test client
testClientDataSourceAttr?: DataSourceAttributes;
request: OpenSearchDashboardsRequest;
}

export interface DataSourceCredentialsProviderOptions {
dataSourceAttr: DataSourceAttributes;
request: OpenSearchDashboardsRequest;
cryptography?: CryptographyServiceSetup;
}

export type DataSourceCredentialsProvider = (
options: DataSourceCredentialsProviderOptions
) => UsernamePasswordTypedContent | SigV4Content;

export interface DataSourcePluginRequestContext {
opensearch: {
getClient: (dataSourceId: string) => Promise<OpenSearchClient>;
Expand All @@ -53,6 +65,11 @@ declare module 'src/core/server' {

export interface DataSourcePluginSetup {
createDataSourceError: (err: any) => DataSourceError;

registerCredentialProvider: (
authType: string,
credentialProvider: DataSourceCredentialsProvider
) => void;
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface DataSourcePluginStart {}
1 change: 1 addition & 0 deletions src/plugins/data_source_management/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export function plugin() {
return new DataSourceManagementPlugin();
}
export { DataSourceManagementPluginStart } from './types';
export { DataSourceManagementPlugin } from './plugin';

0 comments on commit 3b96379

Please sign in to comment.