-
Notifications
You must be signed in to change notification settings - Fork 907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Multiple DataSource] Refactor test connection to support SigV4 auth type #3456
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,13 +29,35 @@ import { | |
} from './configure_client_utils'; | ||
|
||
export const configureClient = async ( | ||
{ dataSourceId, savedObjects, cryptography }: DataSourceClientParams, | ||
{ dataSourceId, savedObjects, cryptography, testClientDataSourceAttr }: DataSourceClientParams, | ||
openSearchClientPoolSetup: OpenSearchClientPoolSetup, | ||
config: DataSourcePluginConfigType, | ||
logger: Logger | ||
): Promise<Client> => { | ||
let dataSource; | ||
let requireDecryption = true; | ||
|
||
try { | ||
const dataSource = await getDataSource(dataSourceId!, savedObjects); | ||
// configure test client | ||
if (testClientDataSourceAttr) { | ||
const { | ||
auth: { type, credentials }, | ||
} = testClientDataSourceAttr; | ||
// handle test connection case when changing non-credential field of existing data source | ||
if ( | ||
dataSourceId && | ||
((type === AuthType.UsernamePasswordType && !credentials?.password) || | ||
(type === AuthType.SigV4 && !credentials?.accessKey && !credentials?.secretKey)) | ||
Comment on lines
+49
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit, how about give variable to these conditions for readability? Also we don't check if region is not empty? |
||
) { | ||
dataSource = await getDataSource(dataSourceId, savedObjects); | ||
} else { | ||
dataSource = testClientDataSourceAttr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some comment here? explain which case will enter this block There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's comment in line 7
|
||
requireDecryption = false; | ||
} | ||
} else { | ||
dataSource = await getDataSource(dataSourceId!, savedObjects); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let me add more comments |
||
} | ||
|
||
const rootClient = getRootClient( | ||
dataSource, | ||
openSearchClientPoolSetup.getClientFromPool, | ||
|
@@ -48,7 +70,8 @@ export const configureClient = async ( | |
config, | ||
cryptography, | ||
rootClient, | ||
dataSourceId | ||
dataSourceId, | ||
requireDecryption | ||
); | ||
} catch (error: any) { | ||
logger.error( | ||
|
@@ -59,46 +82,6 @@ export const configureClient = async ( | |
} | ||
}; | ||
|
||
export const configureTestClient = async ( | ||
{ savedObjects, cryptography, dataSourceId }: DataSourceClientParams, | ||
dataSourceAttr: DataSourceAttributes, | ||
openSearchClientPoolSetup: OpenSearchClientPoolSetup, | ||
config: DataSourcePluginConfigType, | ||
logger: Logger | ||
): Promise<Client> => { | ||
try { | ||
const { | ||
auth: { type, credentials }, | ||
} = dataSourceAttr; | ||
let requireDecryption = false; | ||
|
||
const rootClient = getRootClient( | ||
dataSourceAttr, | ||
openSearchClientPoolSetup.getClientFromPool, | ||
dataSourceId | ||
) as Client; | ||
|
||
if (type === AuthType.UsernamePasswordType && !credentials?.password && dataSourceId) { | ||
dataSourceAttr = await getDataSource(dataSourceId, savedObjects); | ||
requireDecryption = true; | ||
} | ||
|
||
return getQueryClient( | ||
dataSourceAttr, | ||
openSearchClientPoolSetup.addClientToPool, | ||
config, | ||
cryptography, | ||
rootClient, | ||
dataSourceId, | ||
requireDecryption | ||
); | ||
} catch (error: any) { | ||
logger.error(`Failed to get test client. ${error}: ${error.stack}`); | ||
// Re-throw as DataSourceError | ||
throw createDataSourceError(error); | ||
} | ||
}; | ||
|
||
/** | ||
* Create a child client object with given auth info. | ||
* | ||
|
@@ -108,7 +91,7 @@ export const configureTestClient = async ( | |
* @param config data source config | ||
* @param addClientToPool function to add client to client pool | ||
* @param dataSourceId id of data source saved Object | ||
* @param requireDecryption boolean | ||
* @param requireDecryption false when creating test client before data source exists | ||
* @returns Promise of query client | ||
*/ | ||
const getQueryClient = async ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
testClientDataSourceAttr
as condition seems a bit confuse to me, Wondering if we should pass an explicit flag from the browser side to indicate testing client instead of using the existence of some params. likeisPreFlightClient=true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am removing all the separate functions to getTestClient, so that we can reuse the same logic for both test client and non-test client. We still need to keep the
testClientDataSourceAttr
even tho we add a flag.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I am fine to merge them, and testClientDataSourceAttr is still needed, but in future the api could accept other dataSourceAttr but not necessarily for test client.