forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MD] Feature test connection (opensearch-project#2973)
* test connection intial code Signed-off-by: mpabba3003 <amazonmanideep@gmail.com> * error handling Signed-off-by: mpabba3003 <amazonmanideep@gmail.com> * refactor Signed-off-by: mpabba3003 <amazonmanideep@gmail.com> * removing get cluster info dependency Signed-off-by: mpabba3003 <amazonmanideep@gmail.com> * refactor test connection Signed-off-by: mpabba3003 <amazonmanideep@gmail.com> * adding test cases and test connection on edit datasource Signed-off-by: mpabba3003 <amazonmanideep@gmail.com> * adding changelog comment Signed-off-by: mpabba3003 <amazonmanideep@gmail.com> * fixing bug on edit datasource page Signed-off-by: mpabba3003 <amazonmanideep@gmail.com> * refactor based on PR comments Signed-off-by: mpabba3003 <amazonmanideep@gmail.com> Signed-off-by: mpabba3003 <amazonmanideep@gmail.com> Signed-off-by: Arpit Bandejiya <abandeji@amazon.com>
- Loading branch information
1 parent
026c1a3
commit ece5519
Showing
27 changed files
with
491 additions
and
9,200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/plugins/data_source/server/routes/data_source_connection_validator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { OpenSearchClient } from 'opensearch-dashboards/server'; | ||
import { createDataSourceError } from '../lib/error'; | ||
|
||
export class DataSourceConnectionValidator { | ||
constructor(private readonly callDataCluster: OpenSearchClient) {} | ||
|
||
async validate() { | ||
try { | ||
return await this.callDataCluster.info<OpenSearchClient>(); | ||
} catch (e) { | ||
if (e.statusCode === 403) { | ||
return true; | ||
} else { | ||
throw createDataSourceError(e); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { schema } from '@osd/config-schema'; | ||
import { IRouter, OpenSearchClient } from 'opensearch-dashboards/server'; | ||
import { DataSourceAttributes } from '../../common/data_sources'; | ||
import { DataSourceConnectionValidator } from './data_source_connection_validator'; | ||
import { DataSourceServiceSetup } from '../data_source_service'; | ||
import { CryptographyServiceSetup } from '../cryptography_service'; | ||
|
||
export const registerTestConnectionRoute = ( | ||
router: IRouter, | ||
dataSourceServiceSetup: DataSourceServiceSetup, | ||
cryptography: CryptographyServiceSetup | ||
) => { | ||
router.post( | ||
{ | ||
path: '/internal/data-source-management/validate', | ||
validate: { | ||
body: schema.object({ | ||
id: schema.string(), | ||
endpoint: schema.string(), | ||
auth: schema.maybe( | ||
schema.object({ | ||
type: schema.oneOf([schema.literal('username_password'), schema.literal('no_auth')]), | ||
credentials: schema.oneOf([ | ||
schema.object({ | ||
username: schema.string(), | ||
password: schema.string(), | ||
}), | ||
schema.literal(null), | ||
]), | ||
}) | ||
), | ||
}), | ||
}, | ||
}, | ||
async (context, request, response) => { | ||
const dataSource: DataSourceAttributes = request.body as DataSourceAttributes; | ||
|
||
const dataSourceClient: OpenSearchClient = await dataSourceServiceSetup.getTestingClient( | ||
{ | ||
dataSourceId: dataSource.id || '', | ||
savedObjects: context.core.savedObjects.client, | ||
cryptography, | ||
}, | ||
dataSource | ||
); | ||
|
||
try { | ||
const dsValidator = new DataSourceConnectionValidator(dataSourceClient); | ||
|
||
await dsValidator.validate(); | ||
|
||
return response.ok({ | ||
body: { | ||
success: true, | ||
}, | ||
}); | ||
} catch (err) { | ||
return response.customError({ | ||
statusCode: err.statusCode || 500, | ||
body: { | ||
message: err.message, | ||
attributes: { | ||
error: err.body?.error || err.message, | ||
}, | ||
}, | ||
}); | ||
} | ||
} | ||
); | ||
}; |
Oops, something went wrong.