Skip to content

Commit

Permalink
Change field
Browse files Browse the repository at this point in the history
Signed-off-by: Bandini Bhopi <bandinib@amazon.com>
  • Loading branch information
bandinib-amzn committed Jan 31, 2024
1 parent 71cae27 commit 75f0268
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ export class AuthenticationMethodRegistery {
* Register a authMethods with function to return credentials inside the registry.
* Authentication Method can only be registered once. subsequent calls with the same method name will throw an error.
*/
public registerAuthenticationMethod(type: string, authMethodValues: AuthMethodValues) {
if (this.authMethods.has(type)) {
throw new Error(`Authentication method '${type}' is already registered`);
public registerAuthenticationMethod(name: string, authMethodValues: AuthMethodValues) {
if (this.authMethods.has(name)) {
throw new Error(`Authentication method '${name}' is already registered`);
}
this.authMethods.set(type, authMethodValues);
this.authMethods.set(name, authMethodValues);
}

public getAllAuthenticationMethods() {
return [...this.authMethods.values()];
}

public getAuthenticationMethod(authType: string) {
return this.authMethods.get(authType);
public getAuthenticationMethod(name: string) {
return this.authMethods.get(name);
}
}
2 changes: 1 addition & 1 deletion src/plugins/data_source/common/data_sources/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface DataSourceAttributes extends SavedObjectAttributes {
credentials: UsernamePasswordTypedContent | SigV4Content | undefined | AuthTypeContent;
};
lastUpdatedTime?: string;
authMethodType: AuthType | string;
name: AuthType | string;
}

export interface AuthTypeContent {
Expand Down
10 changes: 4 additions & 6 deletions src/plugins/data_source/server/client/configure_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,19 @@ const getQueryClient = async (
console.log(`I'm inside getQueryClient`);
let {
auth: { type },
authMethodType = 'token_exchange',
name,
} = dataSourceAttr;
const { endpoint } = dataSourceAttr;
authMethodType = authMethodType ?? type;
name = name ?? type;
const clientOptions = parseClientOptions(config, endpoint);
const cacheKey = generateCacheKey(dataSourceAttr, dataSourceId);
let awsCredential;
if (authRegistryPromise !== undefined) {
console.log(`authRegistryPromise is defined`);
await authRegistryPromise.then((auth) => {
if (auth !== undefined) {
console.log(
`auth is defined, calling getAuthenticationMethod with param = ${authMethodType}`
);
const authMethod = auth.getAuthenticationMethod(authMethodType);
console.log(`auth is defined, calling getAuthenticationMethod with param = ${name}`);
const authMethod = auth.getAuthenticationMethod(name);
console.log(`authMethod = ${JSON.stringify(authMethod)}`);
awsCredential = authMethod?.credentialProvider({ dataSourceAttr, request, cryptography });
type = authMethod?.authType;
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/data_source/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,16 @@ export class DataSourcePlugin implements Plugin<DataSourcePluginSetup, DataSourc
const router = core.http.createRouter();
registerTestConnectionRoute(router, dataSourceService, cryptographyServiceSetup);

const registerCredentialProvider = (type: string, authMethodValues: AuthMethodValues) => {
const registerCredentialProvider = (name: string, authMethodValues: AuthMethodValues) => {
this.logger.info(
`Registered Credential Provider for authType = ${type} and authMethodValues = ${JSON.stringify(
`Registered Credential Provider for authType = ${name} and authMethodValues = ${JSON.stringify(
authMethodValues
)}`
);
if (this.started) {
throw new Error('cannot call `registerCredentialProvider` after service startup.');
}
this.authMethodsRegistry.registerAuthenticationMethod(type, authMethodValues);
this.authMethodsRegistry.registerAuthenticationMethod(name, authMethodValues);
};

return {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data_source/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ declare module 'src/core/server' {
export interface DataSourcePluginSetup {
createDataSourceError: (err: any) => DataSourceError;

registerCredentialProvider: (type: string, authMethodValues: AuthMethodValues) => void;
registerCredentialProvider: (name: string, authMethodValues: AuthMethodValues) => void;
}

export interface DataSourcePluginStart {
Expand Down

0 comments on commit 75f0268

Please sign in to comment.