diff --git a/CHANGELOG.md b/CHANGELOG.md index 31e3f5a1541f..3e276e756d15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ # CHANGELOG + Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] + ### 💥 Breaking Changes ### Deprecations @@ -10,11 +12,13 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### 📈 Features/Enhancements +- [MD] Support legacy client for data source ([#2204](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2204)) + ### 🐛 Bug Fixes ### 🚞 Infrastructure -* Add CHANGELOG.md and related workflows ([#2414](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2414)) +- Add CHANGELOG.md and related workflows ([#2414](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2414)) ### 📝 Documentation @@ -25,47 +29,47 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### 🔩 Tests ## [2.x] + ### 💥 Breaking Changes ### Deprecations ### 🛡 Security -* Use a forced CSP-compliant interpreter with Vega visualizations ([#2352](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2352)) -* Bump moment-timezone from 0.5.34 to 0.5.37 ([#2361](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2361)) -* [CVE-2022-33987] Upgrade geckodriver to 3.0.2 ([#2166](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2166)) +- Use a forced CSP-compliant interpreter with Vega visualizations ([#2352](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2352)) +- Bump moment-timezone from 0.5.34 to 0.5.37 ([#2361](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2361)) +- [CVE-2022-33987] Upgrade geckodriver to 3.0.2 ([#2166](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2166)) ### 📈 Features/Enhancements -* Add updated_at column to objects' tables ([#1218](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/1218)) +- Add updated_at column to objects' tables ([#1218](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/1218)) ### 🐛 Bug Fixes -* [Viz Builder] Fixes time series for new chart types ([#2309](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2309)) -* [Viz Builder] Add index pattern info when loading embeddable ([#2363](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2363)) -* Fixes management app breadcrumb error ([#2344](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2344)) +- [Viz Builder] Fixes time series for new chart types ([#2309](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2309)) +- [Viz Builder] Add index pattern info when loading embeddable ([#2363](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2363)) +- Fixes management app breadcrumb error ([#2344](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2344)) ### 🚞 Infrastructure -* Add path ignore for markdown files for CI ([#2312](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2312)) -* Updating WS scans to ignore BWC artifacts in `cypress` ([#2408](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2408)) - +- Add path ignore for markdown files for CI ([#2312](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2312)) +- Updating WS scans to ignore BWC artifacts in `cypress` ([#2408](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2408)) ### 📝 Documentation -* README.md for saving index pattern relationship ([#2276](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2276)) -* Remove extra typo from README. ([#2403](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2403)) +- README.md for saving index pattern relationship ([#2276](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2276)) +- Remove extra typo from README. ([#2403](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2403)) ### 🛠 Maintenance -* Increment from 2.3 to 2.4. ([#2295](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2295)) -* Adding @zengyan-amazon as maintainer. +- Increment from 2.3 to 2.4. ([#2295](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2295)) +- Adding @zengyan-amazon as maintainer. ### 🪛 Refactoring ### 🔩 Tests -* Update caniuse to fix failed integration tests ([#2322](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2322)) +- Update caniuse to fix failed integration tests ([#2322](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2322)) -[Unreleased]: https://github.com/opensearch-project/OpenSearch-Dashboards/compare/2.3.0...HEAD +[unreleased]: https://github.com/opensearch-project/OpenSearch-Dashboards/compare/2.3.0...HEAD [2.x]: https://github.com/opensearch-project/OpenSearch-Dashboards/compare/2.3.0...2.x diff --git a/src/core/server/opensearch/legacy/cluster_client.ts b/src/core/server/opensearch/legacy/cluster_client.ts index ab8bd4f8ceb0..bb8884fd3952 100644 --- a/src/core/server/opensearch/legacy/cluster_client.ts +++ b/src/core/server/opensearch/legacy/cluster_client.ts @@ -65,7 +65,7 @@ const noop = () => undefined; * OpenSearch JS client. * @param options Options that affect the way we call the API and process the result. */ -export const callAPI = async ( +const callAPI = async ( client: Client, endpoint: string, clientParams: Record = {}, diff --git a/src/plugins/data_source/server/legacy/configure_legacy_client.ts b/src/plugins/data_source/server/legacy/configure_legacy_client.ts index 84514c85b048..63ca6c714744 100644 --- a/src/plugins/data_source/server/legacy/configure_legacy_client.ts +++ b/src/plugins/data_source/server/legacy/configure_legacy_client.ts @@ -4,9 +4,15 @@ */ import { Client } from 'elasticsearch'; -// eslint-disable-next-line @osd/eslint/no-restricted-paths -import { callAPI } from '../../../../../src/core/server/opensearch/legacy/cluster_client'; -import { Headers, LegacyAPICaller, Logger, SavedObject } from '../../../../../src/core/server'; +import { get } from 'lodash'; +import { + Headers, + LegacyAPICaller, + LegacyCallAPIOptions, + LegacyOpenSearchErrorHelpers, + Logger, + SavedObject, +} from '../../../../../src/core/server'; import { AuthType, DataSourceAttributes, @@ -87,6 +93,48 @@ const getRootClient = ( } }; +/** + * Calls the OpenSearch API endpoint with the specified parameters. + * @param client Raw OpenSearch JS client instance to use. + * @param endpoint Name of the API endpoint to call. + * @param clientParams Parameters that will be directly passed to the + * OpenSearch JS client. + * @param options Options that affect the way we call the API and process the result. + * make wrap401Errors default to false, because we don't want browser login pop-up + */ +const callAPI = async ( + client: Client, + endpoint: string, + clientParams: Record = {}, + options: LegacyCallAPIOptions = { wrap401Errors: false } +) => { + const clientPath = endpoint.split('.'); + const api: any = get(client, clientPath); + if (!api) { + throw new Error(`called with an invalid endpoint: ${endpoint}`); + } + + const apiContext = clientPath.length === 1 ? client : get(client, clientPath.slice(0, -1)); + try { + return await new Promise((resolve, reject) => { + const request = api.call(apiContext, clientParams); + if (options.signal) { + options.signal.addEventListener('abort', () => { + request.abort(); + reject(new Error('Request was aborted')); + }); + } + return request.then(resolve, reject); + }); + } catch (err) { + if (!options.wrap401Errors || err.statusCode !== 401) { + throw err; + } + + throw LegacyOpenSearchErrorHelpers.decorateNotAuthorizedError(err); + } +}; + /** * Wrapper to expose API that allow calling the OpenSearch API endpoint with the specified * parameters, using legacy client. diff --git a/src/plugins/data_source/server/lib/error.ts b/src/plugins/data_source/server/lib/error.ts index e921a8d8043f..71830a440c9f 100644 --- a/src/plugins/data_source/server/lib/error.ts +++ b/src/plugins/data_source/server/lib/error.ts @@ -14,8 +14,8 @@ export class DataSourceConfigError extends OsdError { ? error.output.payload.message : error.message; super(messagePrefix + messageContent); - // Cast all 5xx error returned by saveObjectClient to 500, 400 for both savedObject client - // 4xx errors, and other errors + // Cast all 5xx error returned by saveObjectClient to 500. + // Case both savedObject client 4xx errors, and other errors to 400 this.statusCode = SavedObjectsErrorHelpers.isOpenSearchUnavailableError(error) ? 500 : 400; } }