From 33d06602db64320a7cedaba9e436f395fca29d72 Mon Sep 17 00:00:00 2001 From: "Christiane (Tina) Heiligers" Date: Thu, 7 Nov 2024 13:49:05 -0700 Subject: [PATCH 1/2] Changes deprecated SO HTTP APIs deprecation field to object (#197936) fix https://github.com/elastic/kibana/issues/197721. The route deprecation field changed from a boolean to an object, where the object contains information that is used in deprecation issues that the Upgrade Assistant shows. This PR makes the necessary changes in the deprecated Saved Objects HTTP APIs. This PR also includes a release notes entry for the API deprecations that was missing. ![Screenshot 2024-10-29 at 12 01 29](https://github.com/user-attachments/assets/5c47c697-fbae-4b2e-8c6c-cd4701a667df) ### Checklist - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [x] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### How to test this: - Pull PR, run es against a trial license and start kibana as usual. - Make a curl request to Kibana to get the config saved object: ``` curl --location 'localhost:5601/abc/api/saved_objects/config/9.0.0' \ --header 'Content-Type: application/json' \ --header 'Accept-Encoding: gzip, deflate, br' \ --header 'kbn-xsrf: kibana' \ --header 'Kbn-Version: 9.0.0' \ --header 'Authorization: Basic ZWxhc3RpYzpjaGFuZ2VtZQ==' ``` - Navigate to Upgrade Assistant and observe Kibana has at least 1 deprecation warning. - View Kibana's warnings, you should see a warning entry for `The "GET /api/saved_objects/{type}/{id}" route is deprecated` ![Screenshot 2024-11-06 at 16 26 26](https://github.com/user-attachments/assets/3b6a5644-3e5e-403e-a0f6-015686675b9f) - click on the deprecation and you should see more detail about the deprecated API that's been used in the flyout: ![Screenshot 2024-11-06 at 16 26 44](https://github.com/user-attachments/assets/696aaf8f-fb6b-4c61-bc3c-b3745f85059a) - resolve the deprecation warning - Kibana should continue to issue requests to the deprecated SO HTTP APIs because these APIs have not been removed yet. ### Risk Matrix | Risk | Probability | Severity | Mitigation/Notes | |---------------------------|-------------|----------|-------------------------| | End user concern from the deprecation warning that says the routes have been deprecated | Low | Low | The APIs have been deprecated since 8.7 and recommends using public APIs instead. | ### For maintainers - [x] This will appear in the **Release Notes** and follow the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: Elastic Machine Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit 0df2e9838119d202eba0c6b2bcb7068b160f6005) # Conflicts: # oas_docs/output/kibana.serverless.yaml # oas_docs/output/kibana.yaml # packages/core/deprecations/core-deprecations-server-internal/src/routes/post_validation_handler.ts # packages/core/http/core-http-server/index.ts # packages/core/http/core-http-server/src/router/index.ts --- docs/upgrade-notes.asciidoc | 29 +++++ .../core-root-server-internal/src/server.ts | 1 + .../src/routes/bulk_create.ts | 8 +- .../src/routes/bulk_delete.ts | 8 +- .../src/routes/bulk_get.ts | 8 +- .../src/routes/bulk_resolve.ts | 8 +- .../src/routes/bulk_update.ts | 8 +- .../src/routes/create.ts | 8 +- .../src/routes/delete.ts | 8 +- .../src/routes/find.ts | 8 +- .../src/routes/get.ts | 8 +- .../src/routes/index.ts | 102 ++++++++++++++++-- .../src/routes/legacy_import_export/export.ts | 5 +- .../src/routes/legacy_import_export/import.ts | 5 +- .../src/routes/resolve.ts | 8 +- .../src/routes/update.ts | 8 +- .../src/saved_objects_service.test.ts | 13 +++ .../src/saved_objects_service.ts | 6 +- .../saved-objects/docs/openapi/bundled.json | 4 +- .../saved-objects/docs/openapi/bundled.yaml | 6 +- .../docs/openapi/bundled_serverless.json | 4 +- .../docs/openapi/bundled_serverless.yaml | 2 +- .../docs/openapi/entrypoint.yaml | 4 +- .../docs/openapi/entrypoint_serverless.yaml | 4 +- packages/kbn-doc-links/src/get_doc_links.ts | 2 + packages/kbn-doc-links/src/types.ts | 1 + .../allow_api_access/bulk_create.test.ts | 11 +- .../allow_api_access/bulk_delete.test.ts | 10 +- .../routes/allow_api_access/bulk_get.test.ts | 11 +- .../allow_api_access/bulk_resolve.test.ts | 11 +- .../allow_api_access/bulk_update.test.ts | 11 +- .../routes/allow_api_access/create.test.ts | 11 +- .../routes/allow_api_access/delete.test.ts | 11 +- .../routes/allow_api_access/find.test.ts | 10 +- .../routes/allow_api_access/get.test.ts | 11 +- .../routes/allow_api_access/resolve.test.ts | 10 +- .../routes/allow_api_access/update.test.ts | 11 +- .../saved_objects/routes/bulk_create.test.ts | 32 +++++- .../saved_objects/routes/bulk_delete.test.ts | 29 ++++- .../saved_objects/routes/bulk_get.test.ts | 28 ++++- .../saved_objects/routes/bulk_resolve.test.ts | 29 ++++- .../saved_objects/routes/bulk_update.test.ts | 43 +++++++- .../saved_objects/routes/create.test.ts | 28 ++++- .../saved_objects/routes/delete.test.ts | 22 +++- .../saved_objects/routes/find.test.ts | 22 +++- .../saved_objects/routes/get.test.ts | 23 +++- .../legacy_import_export/export.test.ts | 3 + .../legacy_import_export/import.test.ts | 3 + .../saved_objects/routes/resolve.test.ts | 23 +++- .../saved_objects/routes/routes_test_utils.ts | 16 +++ .../saved_objects/routes/update.test.ts | 23 +++- 51 files changed, 603 insertions(+), 115 deletions(-) diff --git a/docs/upgrade-notes.asciidoc b/docs/upgrade-notes.asciidoc index a6e5a34db20e9..9abb898550740 100644 --- a/docs/upgrade-notes.asciidoc +++ b/docs/upgrade-notes.asciidoc @@ -1419,6 +1419,35 @@ The `/agent_status` Fleet API now returns the following statuses: * `active` — All active ==== +[discrete] +[[kibana-150267]] +.Deprecated Saved objects APIs. (8.7) +[%collapsible] +==== +*Details* + +The following saved objects APIs have been deprecated. + +[source,text] +-- +/api/saved_objects/{type}/{id} +/api/saved_objects/resolve/{type}/{id} +/api/saved_objects/{type}/{id?} +/api/saved_objects/{type}/{id} +/api/saved_objects/_find +/api/saved_objects/{type}/{id} +/api/saved_objects/_bulk_get +/api/saved_objects/_bulk_create +/api/saved_objects/_bulk_resolve +/api/saved_objects/_bulk_update +/api/saved_objects/_bulk_delete +-- + +For more information, refer to ({kibana-pull}150267[#150267]). + +*Impact* + +Use dedicated public APIs instead, for example use <> to manage Data Views. +==== + [discrete] [[deprecation-119494]] .Updates Fleet API to improve consistency. (8.0) diff --git a/packages/core/root/core-root-server-internal/src/server.ts b/packages/core/root/core-root-server-internal/src/server.ts index 5082a27930e87..d38a52b73494b 100644 --- a/packages/core/root/core-root-server-internal/src/server.ts +++ b/packages/core/root/core-root-server-internal/src/server.ts @@ -309,6 +309,7 @@ export class Server { elasticsearch: elasticsearchServiceSetup, deprecations: deprecationsSetup, coreUsageData: coreUsageDataSetup, + docLinks: docLinksSetup, }); const uiSettingsSetup = await this.uiSettings.setup({ diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/bulk_create.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/bulk_create.ts index c9a8656b3f753..c0df8b57094eb 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/bulk_create.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/bulk_create.ts @@ -8,7 +8,7 @@ */ import { schema } from '@kbn/config-schema'; -import type { RouteAccess } from '@kbn/core-http-server'; +import type { RouteAccess, RouteDeprecationInfo } from '@kbn/core-http-server'; import { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal'; import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal'; import type { Logger } from '@kbn/logging'; @@ -24,11 +24,12 @@ interface RouteDependencies { coreUsageData: InternalCoreUsageDataSetup; logger: Logger; access: RouteAccess; + deprecationInfo: RouteDeprecationInfo; } export const registerBulkCreateRoute = ( router: InternalSavedObjectRouter, - { config, coreUsageData, logger, access }: RouteDependencies + { config, coreUsageData, logger, access, deprecationInfo }: RouteDependencies ) => { const { allowHttpApiAccess } = config; router.post( @@ -38,8 +39,7 @@ export const registerBulkCreateRoute = ( summary: `Create saved objects`, tags: ['oas-tag:saved objects'], access, - // @ts-expect-error TODO(https://github.com/elastic/kibana/issues/196095): Replace {RouteDeprecationInfo} - deprecated: true, + deprecated: deprecationInfo, }, validate: { query: schema.object({ diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/bulk_delete.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/bulk_delete.ts index 65209a6072748..21ea532cae170 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/bulk_delete.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/bulk_delete.ts @@ -8,7 +8,7 @@ */ import { schema } from '@kbn/config-schema'; -import type { RouteAccess } from '@kbn/core-http-server'; +import type { RouteAccess, RouteDeprecationInfo } from '@kbn/core-http-server'; import { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal'; import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal'; import type { Logger } from '@kbn/logging'; @@ -24,11 +24,12 @@ interface RouteDependencies { coreUsageData: InternalCoreUsageDataSetup; logger: Logger; access: RouteAccess; + deprecationInfo: RouteDeprecationInfo; } export const registerBulkDeleteRoute = ( router: InternalSavedObjectRouter, - { config, coreUsageData, logger, access }: RouteDependencies + { config, coreUsageData, logger, access, deprecationInfo }: RouteDependencies ) => { const { allowHttpApiAccess } = config; router.post( @@ -38,8 +39,7 @@ export const registerBulkDeleteRoute = ( summary: `Delete saved objects`, tags: ['oas-tag:saved objects'], access, - // @ts-expect-error TODO(https://github.com/elastic/kibana/issues/196095): Replace {RouteDeprecationInfo} - deprecated: true, + deprecated: deprecationInfo, }, validate: { body: schema.arrayOf( diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/bulk_get.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/bulk_get.ts index 3f87ca12248ae..1a97377f872f6 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/bulk_get.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/bulk_get.ts @@ -8,7 +8,7 @@ */ import { schema } from '@kbn/config-schema'; -import type { RouteAccess } from '@kbn/core-http-server'; +import type { RouteAccess, RouteDeprecationInfo } from '@kbn/core-http-server'; import { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal'; import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal'; import type { Logger } from '@kbn/logging'; @@ -24,11 +24,12 @@ interface RouteDependencies { coreUsageData: InternalCoreUsageDataSetup; logger: Logger; access: RouteAccess; + deprecationInfo: RouteDeprecationInfo; } export const registerBulkGetRoute = ( router: InternalSavedObjectRouter, - { config, coreUsageData, logger, access }: RouteDependencies + { config, coreUsageData, logger, access, deprecationInfo }: RouteDependencies ) => { const { allowHttpApiAccess } = config; router.post( @@ -38,8 +39,7 @@ export const registerBulkGetRoute = ( summary: `Get saved objects`, tags: ['oas-tag:saved objects'], access, - // @ts-expect-error TODO(https://github.com/elastic/kibana/issues/196095): Replace {RouteDeprecationInfo} - deprecated: true, + deprecated: deprecationInfo, }, validate: { body: schema.arrayOf( diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/bulk_resolve.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/bulk_resolve.ts index 8e19114e798e0..b464e06ac15c8 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/bulk_resolve.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/bulk_resolve.ts @@ -8,7 +8,7 @@ */ import { schema } from '@kbn/config-schema'; -import type { RouteAccess } from '@kbn/core-http-server'; +import type { RouteAccess, RouteDeprecationInfo } from '@kbn/core-http-server'; import { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal'; import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal'; import type { Logger } from '@kbn/logging'; @@ -24,11 +24,12 @@ interface RouteDependencies { coreUsageData: InternalCoreUsageDataSetup; logger: Logger; access: RouteAccess; + deprecationInfo: RouteDeprecationInfo; } export const registerBulkResolveRoute = ( router: InternalSavedObjectRouter, - { config, coreUsageData, logger, access }: RouteDependencies + { config, coreUsageData, logger, access, deprecationInfo }: RouteDependencies ) => { const { allowHttpApiAccess } = config; router.post( @@ -38,8 +39,7 @@ export const registerBulkResolveRoute = ( summary: `Resolve saved objects`, tags: ['oas-tag:saved objects'], access, - // @ts-expect-error TODO(https://github.com/elastic/kibana/issues/196095): Replace {RouteDeprecationInfo} - deprecated: true, + deprecated: deprecationInfo, description: `Retrieve multiple Kibana saved objects by ID, using any legacy URL aliases if they exist. Under certain circumstances, when Kibana is upgraded, saved object migrations may necessitate regenerating some object IDs to enable new features. When an object's ID is regenerated, a legacy URL alias is created for that object, preserving its old ID. In such a scenario, that object can be retrieved with the bulk resolve API using either its new ID or its old ID.`, }, diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/bulk_update.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/bulk_update.ts index 825a5f95482c0..7793484e01819 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/bulk_update.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/bulk_update.ts @@ -8,7 +8,7 @@ */ import { schema } from '@kbn/config-schema'; -import type { RouteAccess } from '@kbn/core-http-server'; +import type { RouteAccess, RouteDeprecationInfo } from '@kbn/core-http-server'; import { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal'; import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal'; import type { Logger } from '@kbn/logging'; @@ -24,11 +24,12 @@ interface RouteDependencies { coreUsageData: InternalCoreUsageDataSetup; logger: Logger; access: RouteAccess; + deprecationInfo: RouteDeprecationInfo; } export const registerBulkUpdateRoute = ( router: InternalSavedObjectRouter, - { config, coreUsageData, logger, access }: RouteDependencies + { config, coreUsageData, logger, access, deprecationInfo }: RouteDependencies ) => { const { allowHttpApiAccess } = config; router.put( @@ -38,8 +39,7 @@ export const registerBulkUpdateRoute = ( summary: `Update saved objects`, tags: ['oas-tag:saved objects'], access, - // @ts-expect-error TODO(https://github.com/elastic/kibana/issues/196095): Replace {RouteDeprecationInfo} - deprecated: true, + deprecated: deprecationInfo, }, validate: { body: schema.arrayOf( diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/create.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/create.ts index 57f4a10ed9377..4b6a58b107f12 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/create.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/create.ts @@ -8,7 +8,7 @@ */ import { schema } from '@kbn/config-schema'; -import type { RouteAccess } from '@kbn/core-http-server'; +import type { RouteAccess, RouteDeprecationInfo } from '@kbn/core-http-server'; import { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal'; import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal'; import type { Logger } from '@kbn/logging'; @@ -24,11 +24,12 @@ interface RouteDependencies { coreUsageData: InternalCoreUsageDataSetup; logger: Logger; access: RouteAccess; + deprecationInfo: RouteDeprecationInfo; } export const registerCreateRoute = ( router: InternalSavedObjectRouter, - { config, coreUsageData, logger, access }: RouteDependencies + { config, coreUsageData, logger, access, deprecationInfo }: RouteDependencies ) => { const { allowHttpApiAccess } = config; router.post( @@ -38,8 +39,7 @@ export const registerCreateRoute = ( summary: `Create a saved object`, tags: ['oas-tag:saved objects'], access, - // @ts-expect-error TODO(https://github.com/elastic/kibana/issues/196095): Replace {RouteDeprecationInfo} - deprecated: true, + deprecated: deprecationInfo, }, validate: { params: schema.object({ diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/delete.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/delete.ts index 69287821d8049..b3e1bdab6da47 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/delete.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/delete.ts @@ -8,7 +8,7 @@ */ import { schema } from '@kbn/config-schema'; -import type { RouteAccess } from '@kbn/core-http-server'; +import type { RouteAccess, RouteDeprecationInfo } from '@kbn/core-http-server'; import { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal'; import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal'; import type { Logger } from '@kbn/logging'; @@ -24,11 +24,12 @@ interface RouteDependencies { coreUsageData: InternalCoreUsageDataSetup; logger: Logger; access: RouteAccess; + deprecationInfo: RouteDeprecationInfo; } export const registerDeleteRoute = ( router: InternalSavedObjectRouter, - { config, coreUsageData, logger, access }: RouteDependencies + { config, coreUsageData, logger, access, deprecationInfo }: RouteDependencies ) => { const { allowHttpApiAccess } = config; router.delete( @@ -38,8 +39,7 @@ export const registerDeleteRoute = ( summary: `Delete a saved object`, tags: ['oas-tag:saved objects'], access, - // @ts-expect-error TODO(https://github.com/elastic/kibana/issues/196095): Replace {RouteDeprecationInfo} - deprecated: true, + deprecated: deprecationInfo, }, validate: { params: schema.object({ diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/find.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/find.ts index 884ba1ed5c423..534d765080be2 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/find.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/find.ts @@ -8,7 +8,7 @@ */ import { schema } from '@kbn/config-schema'; -import type { RouteAccess } from '@kbn/core-http-server'; +import type { RouteAccess, RouteDeprecationInfo } from '@kbn/core-http-server'; import { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal'; import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal'; import type { Logger } from '@kbn/logging'; @@ -21,11 +21,12 @@ interface RouteDependencies { coreUsageData: InternalCoreUsageDataSetup; logger: Logger; access: RouteAccess; + deprecationInfo: RouteDeprecationInfo; } export const registerFindRoute = ( router: InternalSavedObjectRouter, - { config, coreUsageData, logger, access }: RouteDependencies + { config, coreUsageData, logger, access, deprecationInfo }: RouteDependencies ) => { const referenceSchema = schema.object({ type: schema.string(), @@ -42,8 +43,7 @@ export const registerFindRoute = ( summary: `Search for saved objects`, tags: ['oas-tag:saved objects'], access, - // @ts-expect-error TODO(https://github.com/elastic/kibana/issues/196095): Replace {RouteDeprecationInfo} - deprecated: true, + deprecated: deprecationInfo, }, validate: { query: schema.object({ diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/get.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/get.ts index 9fe3aa8ff20c7..12c9c774ae7b4 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/get.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/get.ts @@ -8,7 +8,7 @@ */ import { schema } from '@kbn/config-schema'; -import type { RouteAccess } from '@kbn/core-http-server'; +import type { RouteAccess, RouteDeprecationInfo } from '@kbn/core-http-server'; import { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal'; import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal'; import type { Logger } from '@kbn/logging'; @@ -24,11 +24,12 @@ interface RouteDependencies { coreUsageData: InternalCoreUsageDataSetup; logger: Logger; access: RouteAccess; + deprecationInfo: RouteDeprecationInfo; } export const registerGetRoute = ( router: InternalSavedObjectRouter, - { config, coreUsageData, logger, access }: RouteDependencies + { config, coreUsageData, logger, access, deprecationInfo }: RouteDependencies ) => { const { allowHttpApiAccess } = config; router.get( @@ -38,8 +39,7 @@ export const registerGetRoute = ( summary: `Get a saved object`, tags: ['oas-tag:saved objects'], access, - // @ts-expect-error TODO(https://github.com/elastic/kibana/issues/196095): Replace {RouteDeprecationInfo} - deprecated: true, + deprecated: deprecationInfo, }, validate: { params: schema.object({ diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/index.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/index.ts index 48ac75e045148..a9a83d55a0daa 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/index.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/index.ts @@ -14,6 +14,8 @@ import type { IKibanaMigrator, } from '@kbn/core-saved-objects-base-server-internal'; import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal'; +import { DocLinksServiceSetup } from '@kbn/core-doc-links-server'; +import { RouteDeprecationInfo } from '@kbn/core-http-server'; import type { InternalSavedObjectsRequestHandlerContext } from '../internal_types'; import { registerGetRoute } from './get'; import { registerResolveRoute } from './resolve'; @@ -43,6 +45,7 @@ export function registerRoutes({ kibanaVersion, kibanaIndex, isServerless, + docLinks, }: { http: InternalHttpServiceSetup; coreUsageData: InternalCoreUsageDataSetup; @@ -52,28 +55,105 @@ export function registerRoutes({ kibanaVersion: string; kibanaIndex: string; isServerless: boolean; + docLinks: DocLinksServiceSetup; }) { const router = http.createRouter('/api/saved_objects/'); const internalOnServerless = isServerless ? 'internal' : 'public'; + const deprecationInfo: RouteDeprecationInfo = { + documentationUrl: `${docLinks.links.management.savedObjectsApiList}`, + severity: 'warning' as const, // will not break deployment upon upgrade + reason: { + type: 'deprecate' as const, + }, + }; - registerGetRoute(router, { config, coreUsageData, logger, access: internalOnServerless }); - registerResolveRoute(router, { config, coreUsageData, logger, access: internalOnServerless }); + const legacyDeprecationInfo = { + documentationUrl: `${docLinks.links.kibana.dashboardImportExport}`, + severity: 'warning' as const, // will not break deployment upon upgrade + reason: { + type: 'remove' as const, // no alternative for posting `.json`, requires file format change to `.ndjson` + }, + }; + + registerGetRoute(router, { + config, + coreUsageData, + logger, + access: internalOnServerless, + deprecationInfo, + }); + registerResolveRoute(router, { + config, + coreUsageData, + logger, + access: internalOnServerless, + deprecationInfo, + }); registerCreateRoute(router, { config, coreUsageData, logger, access: internalOnServerless, + deprecationInfo, + }); + registerDeleteRoute(router, { + config, + coreUsageData, + logger, + access: internalOnServerless, + deprecationInfo, + }); + registerFindRoute(router, { + config, + coreUsageData, + logger, + access: internalOnServerless, + deprecationInfo, + }); + registerUpdateRoute(router, { + config, + coreUsageData, + logger, + access: internalOnServerless, + deprecationInfo, + }); + registerBulkGetRoute(router, { + config, + coreUsageData, + logger, + access: internalOnServerless, + deprecationInfo, + }); + registerBulkCreateRoute(router, { + config, + coreUsageData, + logger, + access: internalOnServerless, + deprecationInfo, + }); + registerBulkResolveRoute(router, { + config, + coreUsageData, + logger, + access: internalOnServerless, + deprecationInfo, + }); + registerBulkUpdateRoute(router, { + config, + coreUsageData, + logger, + access: internalOnServerless, + deprecationInfo, + }); + registerBulkDeleteRoute(router, { + config, + coreUsageData, + logger, + access: internalOnServerless, + deprecationInfo, }); - registerDeleteRoute(router, { config, coreUsageData, logger, access: internalOnServerless }); - registerFindRoute(router, { config, coreUsageData, logger, access: internalOnServerless }); - registerUpdateRoute(router, { config, coreUsageData, logger, access: internalOnServerless }); - registerBulkGetRoute(router, { config, coreUsageData, logger, access: internalOnServerless }); - registerBulkCreateRoute(router, { config, coreUsageData, logger, access: internalOnServerless }); - registerBulkResolveRoute(router, { config, coreUsageData, logger, access: internalOnServerless }); - registerBulkUpdateRoute(router, { config, coreUsageData, logger, access: internalOnServerless }); - registerBulkDeleteRoute(router, { config, coreUsageData, logger, access: internalOnServerless }); registerExportRoute(router, { config, coreUsageData }); registerImportRoute(router, { config, coreUsageData }); @@ -85,12 +165,14 @@ export function registerRoutes({ coreUsageData, logger, access: internalOnServerless, + legacyDeprecationInfo, }); registerLegacyExportRoute(legacyRouter, { kibanaVersion, coreUsageData, logger, access: internalOnServerless, + legacyDeprecationInfo, }); const internalRouter = http.createRouter( diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/export.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/export.ts index f3cf776f7d977..6da4acf798e1b 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/export.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/export.ts @@ -11,7 +11,7 @@ import moment from 'moment'; import { schema } from '@kbn/config-schema'; import type { Logger } from '@kbn/logging'; import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal'; -import type { RouteAccess } from '@kbn/core-http-server'; +import type { RouteAccess, RouteDeprecationInfo } from '@kbn/core-http-server'; import type { InternalSavedObjectRouter } from '../../internal_types'; import { exportDashboards } from './lib'; @@ -22,11 +22,13 @@ export const registerLegacyExportRoute = ( coreUsageData, logger, access, + legacyDeprecationInfo, }: { kibanaVersion: string; coreUsageData: InternalCoreUsageDataSetup; logger: Logger; access: RouteAccess; + legacyDeprecationInfo: RouteDeprecationInfo; } ) => { router.get( @@ -39,6 +41,7 @@ export const registerLegacyExportRoute = ( }, options: { access, + deprecated: legacyDeprecationInfo, tags: ['api'], }, }, diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/import.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/import.ts index e45ef3205af18..ad205bf65f841 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/import.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/import.ts @@ -11,7 +11,7 @@ import { schema } from '@kbn/config-schema'; import type { Logger } from '@kbn/logging'; import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal'; -import type { RouteAccess } from '@kbn/core-http-server'; +import type { RouteAccess, RouteDeprecationInfo } from '@kbn/core-http-server'; import type { InternalSavedObjectRouter } from '../../internal_types'; import { importDashboards } from './lib'; @@ -22,11 +22,13 @@ export const registerLegacyImportRoute = ( coreUsageData, logger, access, + legacyDeprecationInfo, }: { maxImportPayloadBytes: number; coreUsageData: InternalCoreUsageDataSetup; logger: Logger; access: RouteAccess; + legacyDeprecationInfo: RouteDeprecationInfo; } ) => { router.post( @@ -50,6 +52,7 @@ export const registerLegacyImportRoute = ( body: { maxBytes: maxImportPayloadBytes, }, + deprecated: legacyDeprecationInfo, }, }, async (context, request, response) => { diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/resolve.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/resolve.ts index 28a6c82e9ffdf..debbacbb06337 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/resolve.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/resolve.ts @@ -8,7 +8,7 @@ */ import { schema } from '@kbn/config-schema'; -import type { RouteAccess } from '@kbn/core-http-server'; +import type { RouteAccess, RouteDeprecationInfo } from '@kbn/core-http-server'; import { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal'; import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal'; import type { Logger } from '@kbn/logging'; @@ -20,11 +20,12 @@ interface RouteDependencies { coreUsageData: InternalCoreUsageDataSetup; logger: Logger; access: RouteAccess; + deprecationInfo: RouteDeprecationInfo; } export const registerResolveRoute = ( router: InternalSavedObjectRouter, - { config, coreUsageData, logger, access }: RouteDependencies + { config, coreUsageData, logger, access, deprecationInfo }: RouteDependencies ) => { const { allowHttpApiAccess } = config; router.get( @@ -34,8 +35,7 @@ export const registerResolveRoute = ( summary: `Resolve a saved object`, tags: ['oas-tag:saved objects'], access, - // @ts-expect-error TODO(https://github.com/elastic/kibana/issues/196095): Replace {RouteDeprecationInfo} - deprecated: true, + deprecated: deprecationInfo, description: `Retrieve a single Kibana saved object by ID, using any legacy URL alias if it exists. Under certain circumstances, when Kibana is upgraded, saved object migrations may necessitate regenerating some object IDs to enable new features. When an object's ID is regenerated, a legacy URL alias is created for that object, preserving its old ID. In such a scenario, that object can be retrieved with the resolve API using either its new ID or its old ID.`, }, diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/update.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/update.ts index cfedc3ce03d2a..6f372235070b4 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/update.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/update.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import type { RouteAccess } from '@kbn/core-http-server'; +import type { RouteAccess, RouteDeprecationInfo } from '@kbn/core-http-server'; import { schema } from '@kbn/config-schema'; import type { SavedObjectsUpdateOptions } from '@kbn/core-saved-objects-api-server'; import type { Logger } from '@kbn/logging'; @@ -25,11 +25,12 @@ interface RouteDependencies { coreUsageData: InternalCoreUsageDataSetup; logger: Logger; access: RouteAccess; + deprecationInfo: RouteDeprecationInfo; } export const registerUpdateRoute = ( router: InternalSavedObjectRouter, - { config, coreUsageData, logger, access }: RouteDependencies + { config, coreUsageData, logger, access, deprecationInfo }: RouteDependencies ) => { const { allowHttpApiAccess } = config; router.put( @@ -39,8 +40,7 @@ export const registerUpdateRoute = ( summary: `Update a saved object`, tags: ['oas-tag:saved objects'], access, - // @ts-expect-error TODO(https://github.com/elastic/kibana/issues/196095): Replace {RouteDeprecationInfo} - deprecated: true, + deprecated: deprecationInfo, }, validate: { params: schema.object({ diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/saved_objects_service.test.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/saved_objects_service.test.ts index 667c4a5cea915..70e8fcf17c797 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/saved_objects_service.test.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/saved_objects_service.test.ts @@ -98,6 +98,7 @@ describe('SavedObjectsService', () => { elasticsearch: elasticsearchMock, deprecations: deprecationsSetup, coreUsageData: createCoreUsageDataSetupMock(), + docLinks: docLinksServiceMock.createSetupContract(), }; }; @@ -180,6 +181,18 @@ describe('SavedObjectsService', () => { expect(registerRoutesMock).toHaveBeenCalledWith(expect.objectContaining({ kibanaVersion })); }); + it('calls registerRoutes with docLinks', async () => { + const coreContext = createCoreContext(); + const mockedLinks = docLinksServiceMock.createSetupContract(); + + const soService = new SavedObjectsService(coreContext); + await soService.setup(createSetupDeps()); + + expect(registerRoutesMock).toHaveBeenCalledWith( + expect.objectContaining({ docLinks: mockedLinks }) + ); + }); + describe('#setClientFactoryProvider', () => { it('registers the factory to the clientProvider', async () => { const coreContext = createCoreContext(); diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/saved_objects_service.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/saved_objects_service.ts index 522a8e1943a28..04be2f5929f0b 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/saved_objects_service.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/saved_objects_service.ts @@ -13,7 +13,7 @@ import type { Logger } from '@kbn/logging'; import { stripVersionQualifier } from '@kbn/std'; import type { ServiceStatus } from '@kbn/core-status-common'; import type { CoreContext, CoreService } from '@kbn/core-base-server-internal'; -import type { DocLinksServiceStart } from '@kbn/core-doc-links-server'; +import type { DocLinksServiceSetup, DocLinksServiceStart } from '@kbn/core-doc-links-server'; import type { KibanaRequest } from '@kbn/core-http-server'; import type { InternalHttpServiceSetup } from '@kbn/core-http-server-internal'; import type { @@ -99,6 +99,7 @@ export interface SavedObjectsSetupDeps { elasticsearch: InternalElasticsearchServiceSetup; coreUsageData: InternalCoreUsageDataSetup; deprecations: DeprecationRegistryProvider; + docLinks: DocLinksServiceSetup; } /** @internal */ @@ -135,7 +136,7 @@ export class SavedObjectsService this.logger.debug('Setting up SavedObjects service'); this.setupDeps = setupDeps; - const { http, elasticsearch, coreUsageData, deprecations } = setupDeps; + const { http, elasticsearch, coreUsageData, deprecations, docLinks } = setupDeps; const savedObjectsConfig = await firstValueFrom( this.coreContext.configService.atPath('savedObjects') @@ -164,6 +165,7 @@ export class SavedObjectsService kibanaIndex: MAIN_SAVED_OBJECT_INDEX, kibanaVersion: this.kibanaVersion, isServerless: this.coreContext.env.packageInfo.buildFlavor === 'serverless', + docLinks, }); registerCoreObjectTypes(this.typeRegistry); diff --git a/packages/core/saved-objects/docs/openapi/bundled.json b/packages/core/saved-objects/docs/openapi/bundled.json index 5b8f30b0f34c1..45cfdd7fa5055 100644 --- a/packages/core/saved-objects/docs/openapi/bundled.json +++ b/packages/core/saved-objects/docs/openapi/bundled.json @@ -21,7 +21,7 @@ { "name": "saved objects", "x-displayName": "Saved objects", - "description": "Export sets of saved objects that you want to import into {kib}, resolve import errors, and rotate an encryption key for encrypted saved objects with the saved objects APIs.\n\nTo manage a specific type of saved object, use the corresponding APIs.\nFor example, use:\n\n* [Data views](../group/endpoint-data-views)\n* [Spaces](https://www.elastic.co/guide/en/kibana/current/spaces-api.html)\n* [Short URLs](https://www.elastic.co/guide/en/kibana/current/short-urls-api.html)\n\nWarning: Do not write documents directly to the `.kibana` index. When you write directly to the `.kibana` index, the data becomes corrupted and permanently breaks future Kibana versions.\n" + "description": "Export sets of saved objects that you want to import into Kibana, resolve import errors, and rotate an encryption key for encrypted saved objects with the saved objects APIs.\n\nTo manage a specific type of saved object, use the corresponding APIs.\nFor example, use:\n\n* [Data views](../group/endpoint-data-views)\n* [Spaces](https://www.elastic.co/guide/en/kibana/current/spaces-api.html)\n* [Short URLs](https://www.elastic.co/guide/en/kibana/current/short-urls-api.html)\n\nWarning: Do not write documents directly to the `.kibana` index. When you write directly to the `.kibana` index, the data becomes corrupted and permanently breaks future Kibana versions.\n" } ], "paths": { @@ -1423,4 +1423,4 @@ } } } -} \ No newline at end of file +} diff --git a/packages/core/saved-objects/docs/openapi/bundled.yaml b/packages/core/saved-objects/docs/openapi/bundled.yaml index 68c79b406c2b0..9b5aad6e54958 100644 --- a/packages/core/saved-objects/docs/openapi/bundled.yaml +++ b/packages/core/saved-objects/docs/openapi/bundled.yaml @@ -14,7 +14,7 @@ tags: - name: saved objects x-displayName: Saved objects description: | - Export sets of saved objects that you want to import into {kib}, resolve import errors, and rotate an encryption key for encrypted saved objects with the saved objects APIs. + Export sets of saved objects that you want to import into Kibana, resolve import errors, and rotate an encryption key for encrypted saved objects with the saved objects APIs. To manage a specific type of saved object, use the corresponding APIs. For example, use: @@ -216,7 +216,7 @@ paths: responses: '200': description: | - Indicates a successful call. NOTE: This HTTP response code indicates that the bulk operation succeeded. Errors pertaining to individual objects will be returned in the response body. + Indicates a successful call. NOTE: This HTTP response code indicates that the bulk operation succeeded. Errors pertaining to individual objects will be returned in the response body. content: application/json: schema: @@ -248,7 +248,7 @@ paths: responses: '200': description: | - Indicates a successful call. NOTE: This HTTP response code indicates that the bulk operation succeeded. Errors pertaining to individual objects will be returned in the response body. + Indicates a successful call. NOTE: This HTTP response code indicates that the bulk operation succeeded. Errors pertaining to individual objects will be returned in the response body. content: application/json: schema: diff --git a/packages/core/saved-objects/docs/openapi/bundled_serverless.json b/packages/core/saved-objects/docs/openapi/bundled_serverless.json index fe4b832c495b7..67b8a710b5bcd 100644 --- a/packages/core/saved-objects/docs/openapi/bundled_serverless.json +++ b/packages/core/saved-objects/docs/openapi/bundled_serverless.json @@ -26,7 +26,7 @@ { "name": "saved objects", "x-displayName": "Saved objects", - "description": "Export sets of saved objects that you want to import into {kib}, resolve import errors, and rotate an encryption key for encrypted saved objects with the saved objects APIs.\n\nTo manage a specific type of saved object, use the corresponding APIs.\nFor example, use:\n\n[Data views](../group/endpoint-data-views)\n\nWarning: Do not write documents directly to the `.kibana` index. When you write directly to the `.kibana` index, the data becomes corrupted and permanently breaks future Kibana versions.\n" + "description": "Export sets of saved objects that you want to import into Kibana, resolve import errors, and rotate an encryption key for encrypted saved objects with the saved objects APIs.\n\nTo manage a specific type of saved object, use the corresponding APIs.\nFor example, use:\n\n[Data views](../group/endpoint-data-views)\n\nWarning: Do not write documents directly to the `.kibana` index. When you write directly to the `.kibana` index, the data becomes corrupted and permanently breaks future Kibana versions.\n" } ], "paths": { @@ -358,4 +358,4 @@ } } } -} \ No newline at end of file +} diff --git a/packages/core/saved-objects/docs/openapi/bundled_serverless.yaml b/packages/core/saved-objects/docs/openapi/bundled_serverless.yaml index 4517629a29a61..b874f0e32361b 100644 --- a/packages/core/saved-objects/docs/openapi/bundled_serverless.yaml +++ b/packages/core/saved-objects/docs/openapi/bundled_serverless.yaml @@ -17,7 +17,7 @@ tags: - name: saved objects x-displayName: Saved objects description: | - Export sets of saved objects that you want to import into {kib}, resolve import errors, and rotate an encryption key for encrypted saved objects with the saved objects APIs. + Export sets of saved objects that you want to import into Kibana, resolve import errors, and rotate an encryption key for encrypted saved objects with the saved objects APIs. To manage a specific type of saved object, use the corresponding APIs. For example, use: diff --git a/packages/core/saved-objects/docs/openapi/entrypoint.yaml b/packages/core/saved-objects/docs/openapi/entrypoint.yaml index 5cd9039988186..adb960a06dc4e 100644 --- a/packages/core/saved-objects/docs/openapi/entrypoint.yaml +++ b/packages/core/saved-objects/docs/openapi/entrypoint.yaml @@ -12,8 +12,8 @@ tags: - name: saved objects x-displayName: Saved objects description: | - Export sets of saved objects that you want to import into {kib}, resolve import errors, and rotate an encryption key for encrypted saved objects with the saved objects APIs. - + Export sets of saved objects that you want to import into Kibana, resolve import errors, and rotate an encryption key for encrypted saved objects with the saved objects APIs. + To manage a specific type of saved object, use the corresponding APIs. For example, use: diff --git a/packages/core/saved-objects/docs/openapi/entrypoint_serverless.yaml b/packages/core/saved-objects/docs/openapi/entrypoint_serverless.yaml index 69c742a8d7acd..f0d0be2ccf76b 100644 --- a/packages/core/saved-objects/docs/openapi/entrypoint_serverless.yaml +++ b/packages/core/saved-objects/docs/openapi/entrypoint_serverless.yaml @@ -12,8 +12,8 @@ tags: - name: saved objects x-displayName: Saved objects description: | - Export sets of saved objects that you want to import into {kib}, resolve import errors, and rotate an encryption key for encrypted saved objects with the saved objects APIs. - + Export sets of saved objects that you want to import into Kibana, resolve import errors, and rotate an encryption key for encrypted saved objects with the saved objects APIs. + To manage a specific type of saved object, use the corresponding APIs. For example, use: diff --git a/packages/kbn-doc-links/src/get_doc_links.ts b/packages/kbn-doc-links/src/get_doc_links.ts index b2323b07e38d1..71a4f1e8c8a55 100644 --- a/packages/kbn-doc-links/src/get_doc_links.ts +++ b/packages/kbn-doc-links/src/get_doc_links.ts @@ -359,6 +359,8 @@ export const getDocLinks = ({ kibanaBranch, buildFlavor }: GetDocLinkOptions): D autocompleteSuggestions: `${KIBANA_DOCS}kibana-concepts-analysts.html#autocomplete-suggestions`, secureSavedObject: `${KIBANA_DOCS}xpack-security-secure-saved-objects.html`, xpackSecurity: `${KIBANA_DOCS}xpack-security.html`, + restApis: `${KIBANA_DOCS}api.html`, + dashboardImportExport: `${KIBANA_DOCS}dashboard-api.html`, }, upgradeAssistant: { overview: `${KIBANA_DOCS}upgrade-assistant.html`, diff --git a/packages/kbn-doc-links/src/types.ts b/packages/kbn-doc-links/src/types.ts index 4c629ee2d68f7..91d5aa6f47635 100644 --- a/packages/kbn-doc-links/src/types.ts +++ b/packages/kbn-doc-links/src/types.ts @@ -317,6 +317,7 @@ export interface DocLinks { readonly autocompleteSuggestions: string; readonly secureSavedObject: string; readonly xpackSecurity: string; + readonly dashboardImportExport: string; }; readonly upgradeAssistant: { readonly overview: string; diff --git a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_create.test.ts b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_create.test.ts index 8d40280806379..e824e5124f6c6 100644 --- a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_create.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_create.test.ts @@ -21,7 +21,7 @@ import { } from '@kbn/core-saved-objects-server-internal'; import { createHiddenTypeVariants, setupServer } from '@kbn/core-test-helpers-test-utils'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from '../routes_test_utils'; +import { deprecationMock, setupConfig } from '../routes_test_utils'; type SetupServerReturn = Awaited>; @@ -56,7 +56,14 @@ describe('POST /api/saved_objects/_bulk_create with allowApiAccess true', () => const logger = loggerMock.create(); const config = setupConfig(true); const access = 'public'; - registerBulkCreateRoute(router, { config, coreUsageData, logger, access }); + + registerBulkCreateRoute(router, { + config, + coreUsageData, + logger, + access, + deprecationInfo: deprecationMock, + }); await server.start(); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_delete.test.ts b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_delete.test.ts index 26a2d22403bc1..114b682fa51b4 100644 --- a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_delete.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_delete.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from '../routes_test_utils'; +import { deprecationMock, setupConfig } from '../routes_test_utils'; type SetupServerReturn = Awaited>; @@ -61,7 +61,13 @@ describe('POST /api/saved_objects/_bulk_delete with allowApiAccess as true', () const config = setupConfig(true); const access = 'public'; - registerBulkDeleteRoute(router, { config, coreUsageData, logger, access }); + registerBulkDeleteRoute(router, { + config, + coreUsageData, + logger, + access, + deprecationInfo: deprecationMock, + }); await server.start(); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_get.test.ts b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_get.test.ts index da491110b0717..bd6caca6233c8 100644 --- a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_get.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_get.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from '../routes_test_utils'; +import { deprecationMock, setupConfig } from '../routes_test_utils'; type SetupServerReturn = Awaited>; @@ -58,7 +58,14 @@ describe('POST /api/saved_objects/_bulk_get with allowApiAccess true', () => { const config = setupConfig(true); const access = 'public'; - registerBulkGetRoute(router, { config, coreUsageData, logger, access }); + + registerBulkGetRoute(router, { + config, + coreUsageData, + logger, + access, + deprecationInfo: deprecationMock, + }); await server.start(); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_resolve.test.ts b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_resolve.test.ts index 054f55f518a66..f297f1b6a8cb4 100644 --- a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_resolve.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_resolve.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from '../routes_test_utils'; +import { deprecationMock, setupConfig } from '../routes_test_utils'; type SetupServerReturn = Awaited>; @@ -59,7 +59,14 @@ describe('POST /api/saved_objects/_bulk_resolve with allowApiAccess true', () => const config = setupConfig(true); const access = 'public'; - registerBulkResolveRoute(router, { config, coreUsageData, logger, access }); + + registerBulkResolveRoute(router, { + config, + coreUsageData, + logger, + access, + deprecationInfo: deprecationMock, + }); await server.start(); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_update.test.ts b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_update.test.ts index 275e803f6ceb3..7625334bbe638 100644 --- a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_update.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_update.test.ts @@ -19,7 +19,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from '../routes_test_utils'; +import { deprecationMock, setupConfig } from '../routes_test_utils'; type SetupServerReturn = Awaited>; const testTypes = [ @@ -52,7 +52,14 @@ describe('PUT /api/saved_objects/_bulk_update with allowApiAccess true', () => { const config = setupConfig(true); const access = 'public'; - registerBulkUpdateRoute(router, { config, coreUsageData, logger, access }); + + registerBulkUpdateRoute(router, { + config, + coreUsageData, + logger, + access, + deprecationInfo: deprecationMock, + }); await server.start(); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/create.test.ts b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/create.test.ts index 478c233466727..632b41fe886b2 100644 --- a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/create.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/create.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from '../routes_test_utils'; +import { deprecationMock, setupConfig } from '../routes_test_utils'; type SetupServerReturn = Awaited>; @@ -58,7 +58,14 @@ describe('POST /api/saved_objects/{type} with allowApiAccess true', () => { const logger = loggerMock.create(); const config = setupConfig(true); const access = 'public'; - registerCreateRoute(router, { config, coreUsageData, logger, access }); + + registerCreateRoute(router, { + config, + coreUsageData, + logger, + access, + deprecationInfo: deprecationMock, + }); handlerContext.savedObjects.typeRegistry.getType.mockImplementation((typename: string) => { return testTypes diff --git a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/delete.test.ts b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/delete.test.ts index 83cb90ab4d8d7..a1f3ff0bc60ec 100644 --- a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/delete.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/delete.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from '../routes_test_utils'; +import { deprecationMock, setupConfig } from '../routes_test_utils'; type SetupServerReturn = Awaited>; @@ -55,7 +55,14 @@ describe('DELETE /api/saved_objects/{type}/{id} with allowApiAccess true', () => const logger = loggerMock.create(); const config = setupConfig(true); const access = 'public'; - registerDeleteRoute(router, { config, coreUsageData, logger, access }); + + registerDeleteRoute(router, { + config, + coreUsageData, + logger, + access, + deprecationInfo: deprecationMock, + }); await server.start(); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/find.test.ts b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/find.test.ts index 3f7e0b815662e..c87546ea4887a 100644 --- a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/find.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/find.test.ts @@ -21,7 +21,7 @@ import { registerFindRoute, type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; -import { setupConfig } from '../routes_test_utils'; +import { deprecationMock, setupConfig } from '../routes_test_utils'; type SetupServerReturn = Awaited>; @@ -72,7 +72,13 @@ describe('GET /api/saved_objects/_find with allowApiAccess true', () => { const config = setupConfig(true); const access = 'public'; - registerFindRoute(router, { config, coreUsageData, logger, access }); + registerFindRoute(router, { + config, + coreUsageData, + logger, + access, + deprecationInfo: deprecationMock, + }); await server.start(); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/get.test.ts b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/get.test.ts index c97ae350c0386..6220de6540685 100644 --- a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/get.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/get.test.ts @@ -25,7 +25,7 @@ import { } from '@kbn/core-saved-objects-server-internal'; import { createHiddenTypeVariants } from '@kbn/core-test-helpers-test-utils'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from '../routes_test_utils'; +import { deprecationMock, setupConfig } from '../routes_test_utils'; const coreId = Symbol('core'); const testTypes = [ @@ -80,7 +80,14 @@ describe('GET /api/saved_objects/{type}/{id} with allowApiAccess true', () => { const config = setupConfig(true); const access = 'public'; - registerGetRoute(router, { config, coreUsageData, logger, access }); + + registerGetRoute(router, { + config, + coreUsageData, + logger, + access, + deprecationInfo: deprecationMock, + }); await server.start(); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/resolve.test.ts b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/resolve.test.ts index bc00a418a13b2..f1f7fd1d6153e 100644 --- a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/resolve.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/resolve.test.ts @@ -25,7 +25,7 @@ import { } from '@kbn/core-saved-objects-server-internal'; import { createHiddenTypeVariants } from '@kbn/core-test-helpers-test-utils'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from '../routes_test_utils'; +import { deprecationMock, setupConfig } from '../routes_test_utils'; const coreId = Symbol('core'); @@ -81,7 +81,13 @@ describe('GET /api/saved_objects/resolve/{type}/{id} with allowApiAccess true', const config = setupConfig(true); const access = 'public'; - registerResolveRoute(router, { config, coreUsageData, logger, access }); + registerResolveRoute(router, { + config, + coreUsageData, + logger, + access, + deprecationInfo: deprecationMock, + }); await server.start(); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/update.test.ts b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/update.test.ts index 25da93b526285..2a086f29d75d1 100644 --- a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/update.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/update.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from '../routes_test_utils'; +import { deprecationMock, setupConfig } from '../routes_test_utils'; type SetupServerReturn = Awaited>; @@ -56,7 +56,14 @@ describe('PUT /api/saved_objects/{type}/{id?} with allowApiAccess true', () => { const config = setupConfig(true); const access = 'public'; - registerUpdateRoute(router, { config, coreUsageData, logger, access }); + + registerUpdateRoute(router, { + config, + coreUsageData, + logger, + access, + deprecationInfo: deprecationMock, + }); await server.start(); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/bulk_create.test.ts b/src/core/server/integration_tests/saved_objects/routes/bulk_create.test.ts index 91a29121a806f..83468760ed5fb 100644 --- a/src/core/server/integration_tests/saved_objects/routes/bulk_create.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/bulk_create.test.ts @@ -21,7 +21,7 @@ import { } from '@kbn/core-saved-objects-server-internal'; import { createHiddenTypeVariants, setupServer } from '@kbn/core-test-helpers-test-utils'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from './routes_test_utils'; +import { deprecationMock, setupConfig } from './routes_test_utils'; type SetupServerReturn = Awaited>; @@ -37,6 +37,7 @@ describe('POST /api/saved_objects/_bulk_create', () => { let savedObjectsClient: ReturnType; let coreUsageStatsClient: jest.Mocked; let loggerWarnSpy: jest.SpyInstance; + let registrationSpy: jest.SpyInstance; beforeEach(async () => { ({ server, httpSetup, handlerContext } = await setupServer()); @@ -57,11 +58,18 @@ describe('POST /api/saved_objects/_bulk_create', () => { const logger = loggerMock.create(); loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(); + registrationSpy = jest.spyOn(router, 'post'); const config = setupConfig(); const access = 'public'; - registerBulkCreateRoute(router, { config, coreUsageData, logger, access }); + registerBulkCreateRoute(router, { + config, + coreUsageData, + logger, + access, + deprecationInfo: deprecationMock, + }); await server.start(); }); @@ -190,4 +198,24 @@ describe('POST /api/saved_objects/_bulk_create', () => { .expect(200); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); }); + + it('passes deprecation config to the router arguments', async () => { + await supertest(httpSetup.server.listener) + .post('/api/saved_objects/_bulk_create') + .set('x-elastic-internal-origin', 'kibana') + .send([ + { + id: 'abc1234', + type: 'index-pattern', + attributes: { + title: 'foo', + }, + references: [], + }, + ]) + .expect(200); + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); + }); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/bulk_delete.test.ts b/src/core/server/integration_tests/saved_objects/routes/bulk_delete.test.ts index b6ea1f434a0e0..a52a1e04583ac 100644 --- a/src/core/server/integration_tests/saved_objects/routes/bulk_delete.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/bulk_delete.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from './routes_test_utils'; +import { deprecationMock, setupConfig } from './routes_test_utils'; type SetupServerReturn = Awaited>; @@ -36,6 +36,7 @@ describe('POST /api/saved_objects/_bulk_delete', () => { let savedObjectsClient: ReturnType; let coreUsageStatsClient: jest.Mocked; let loggerWarnSpy: jest.SpyInstance; + let registrationSpy: jest.SpyInstance; beforeEach(async () => { ({ server, httpSetup, handlerContext } = await setupServer()); @@ -59,11 +60,18 @@ describe('POST /api/saved_objects/_bulk_delete', () => { const logger = loggerMock.create(); loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(); + registrationSpy = jest.spyOn(router, 'post'); const config = setupConfig(); const access = 'public'; - registerBulkDeleteRoute(router, { config, coreUsageData, logger, access }); + registerBulkDeleteRoute(router, { + config, + coreUsageData, + logger, + access, + deprecationInfo: deprecationMock, + }); await server.start(); }); @@ -158,4 +166,21 @@ describe('POST /api/saved_objects/_bulk_delete', () => { .expect(400); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); }); + + it('passes deprecation configuration to the router arguments', async () => { + await supertest(httpSetup.server.listener) + .post('/api/saved_objects/_bulk_delete') + .set('x-elastic-internal-origin', 'kibana') + .send([ + { + id: 'hiddenID', + type: 'hidden-from-http', + }, + ]) + .expect(400); + + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); + }); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/bulk_get.test.ts b/src/core/server/integration_tests/saved_objects/routes/bulk_get.test.ts index 32a787af677a2..2f88519a6f905 100644 --- a/src/core/server/integration_tests/saved_objects/routes/bulk_get.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/bulk_get.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from './routes_test_utils'; +import { deprecationMock, setupConfig } from './routes_test_utils'; type SetupServerReturn = Awaited>; @@ -36,6 +36,7 @@ describe('POST /api/saved_objects/_bulk_get', () => { let savedObjectsClient: ReturnType; let coreUsageStatsClient: jest.Mocked; let loggerWarnSpy: jest.SpyInstance; + let registrationSpy: jest.SpyInstance; beforeEach(async () => { ({ server, httpSetup, handlerContext } = await setupServer()); @@ -57,11 +58,18 @@ describe('POST /api/saved_objects/_bulk_get', () => { const coreUsageData = coreUsageDataServiceMock.createSetupContract(coreUsageStatsClient); const logger = loggerMock.create(); loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(); + registrationSpy = jest.spyOn(router, 'post'); const config = setupConfig(); const access = 'public'; - registerBulkGetRoute(router, { config, coreUsageData, logger, access }); + registerBulkGetRoute(router, { + config, + coreUsageData, + logger, + access, + deprecationInfo: deprecationMock, + }); await server.start(); }); @@ -146,4 +154,20 @@ describe('POST /api/saved_objects/_bulk_get', () => { .expect(200); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); }); + + it('passes deprecation config to the router arguments', async () => { + await supertest(httpSetup.server.listener) + .post('/api/saved_objects/_bulk_get') + .set('x-elastic-internal-origin', 'kibana') + .send([ + { + id: 'abc123', + type: 'index-pattern', + }, + ]) + .expect(200); + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); + }); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/bulk_resolve.test.ts b/src/core/server/integration_tests/saved_objects/routes/bulk_resolve.test.ts index f9191dc0295de..76a967f856055 100644 --- a/src/core/server/integration_tests/saved_objects/routes/bulk_resolve.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/bulk_resolve.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from './routes_test_utils'; +import { deprecationMock, setupConfig } from './routes_test_utils'; type SetupServerReturn = Awaited>; @@ -36,6 +36,7 @@ describe('POST /api/saved_objects/_bulk_resolve', () => { let savedObjectsClient: ReturnType; let coreUsageStatsClient: jest.Mocked; let loggerWarnSpy: jest.SpyInstance; + let registrationSpy: jest.SpyInstance; beforeEach(async () => { ({ server, httpSetup, handlerContext } = await setupServer()); @@ -58,11 +59,17 @@ describe('POST /api/saved_objects/_bulk_resolve', () => { const coreUsageData = coreUsageDataServiceMock.createSetupContract(coreUsageStatsClient); const logger = loggerMock.create(); loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(); + registrationSpy = jest.spyOn(router, 'post'); const config = setupConfig(); const access = 'public'; - - registerBulkResolveRoute(router, { config, coreUsageData, logger, access }); + registerBulkResolveRoute(router, { + config, + coreUsageData, + logger, + access, + deprecationInfo: deprecationMock, + }); await server.start(); }); @@ -150,4 +157,20 @@ describe('POST /api/saved_objects/_bulk_resolve', () => { .expect(200); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); }); + + it('passes deprecation configuration to the router arguments', async () => { + await supertest(httpSetup.server.listener) + .post('/api/saved_objects/_bulk_resolve') + .set('x-elastic-internal-origin', 'kibana') + .send([ + { + id: 'abc123', + type: 'index-pattern', + }, + ]) + .expect(200); + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); + }); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/bulk_update.test.ts b/src/core/server/integration_tests/saved_objects/routes/bulk_update.test.ts index d71f43ddc6572..bccedce377571 100644 --- a/src/core/server/integration_tests/saved_objects/routes/bulk_update.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/bulk_update.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from './routes_test_utils'; +import { deprecationMock, setupConfig } from './routes_test_utils'; type SetupServerReturn = Awaited>; const testTypes = [ @@ -37,6 +37,7 @@ describe('PUT /api/saved_objects/_bulk_update', () => { let savedObjectsClient: ReturnType; let coreUsageStatsClient: jest.Mocked; let loggerWarnSpy: jest.SpyInstance; + let registrationSpy: jest.SpyInstance; beforeEach(async () => { ({ server, httpSetup, handlerContext } = await setupServer()); @@ -56,11 +57,18 @@ describe('PUT /api/saved_objects/_bulk_update', () => { const coreUsageData = coreUsageDataServiceMock.createSetupContract(coreUsageStatsClient); const logger = loggerMock.create(); loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(); + registrationSpy = jest.spyOn(router, 'put'); const config = setupConfig(); const access = 'public'; - registerBulkUpdateRoute(router, { config, coreUsageData, logger, access }); + registerBulkUpdateRoute(router, { + config, + coreUsageData, + logger, + access, + deprecationInfo: deprecationMock, + }); await server.start(); }); @@ -177,6 +185,7 @@ describe('PUT /api/saved_objects/_bulk_update', () => { }, ]) .expect(400); + expect(result.body.message).toContain('Unsupported saved object type(s):'); }); @@ -201,5 +210,35 @@ describe('PUT /api/saved_objects/_bulk_update', () => { ]) .expect(200); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); + }); + + it('passes deprecation configuration to the router arguments', async () => { + await supertest(httpSetup.server.listener) + .put('/api/saved_objects/_bulk_update') + .set('x-elastic-internal-origin', 'kibana') + .send([ + { + type: 'visualization', + id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab', + attributes: { + title: 'An existing visualization', + }, + }, + { + type: 'dashboard', + id: 'be3733a0-9efe-11e7-acb3-3dab96693fab', + attributes: { + title: 'An existing dashboard', + }, + }, + ]) + .expect(200); + + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); }); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/create.test.ts b/src/core/server/integration_tests/saved_objects/routes/create.test.ts index 736f8e0bf60f0..51cc878817d9e 100644 --- a/src/core/server/integration_tests/saved_objects/routes/create.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/create.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from './routes_test_utils'; +import { deprecationMock, setupConfig } from './routes_test_utils'; type SetupServerReturn = Awaited>; @@ -36,6 +36,7 @@ describe('POST /api/saved_objects/{type}', () => { let savedObjectsClient: ReturnType; let coreUsageStatsClient: jest.Mocked; let loggerWarnSpy: jest.SpyInstance; + let registrationSpy: jest.SpyInstance; const clientResponse = { id: 'logstash-*', @@ -58,10 +59,18 @@ describe('POST /api/saved_objects/{type}', () => { const coreUsageData = coreUsageDataServiceMock.createSetupContract(coreUsageStatsClient); const logger = loggerMock.create(); loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(); + registrationSpy = jest.spyOn(router, 'post'); + const config = setupConfig(); const access = 'public'; - registerCreateRoute(router, { config, coreUsageData, logger, access }); + registerCreateRoute(router, { + config, + coreUsageData, + logger, + access, + deprecationInfo: deprecationMock, + }); handlerContext.savedObjects.typeRegistry.getType.mockImplementation((typename: string) => { return testTypes @@ -172,4 +181,19 @@ describe('POST /api/saved_objects/{type}', () => { .expect(200); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); }); + + it('passes deprecation configuration to the router arguments', async () => { + await supertest(httpSetup.server.listener) + .post('/api/saved_objects/index-pattern') + .set('x-elastic-internal-origin', 'kibana') + .send({ + attributes: { + title: 'Logging test', + }, + }) + .expect(200); + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); + }); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/delete.test.ts b/src/core/server/integration_tests/saved_objects/routes/delete.test.ts index ba5c797469aa3..70d811cd97521 100644 --- a/src/core/server/integration_tests/saved_objects/routes/delete.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/delete.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from './routes_test_utils'; +import { deprecationMock, setupConfig } from './routes_test_utils'; type SetupServerReturn = Awaited>; @@ -37,6 +37,7 @@ describe('DELETE /api/saved_objects/{type}/{id}', () => { let savedObjectsClient: ReturnType; let coreUsageStatsClient: jest.Mocked; let loggerWarnSpy: jest.SpyInstance; + let registrationSpy: jest.SpyInstance; beforeEach(async () => { ({ server, httpSetup, handlerContext } = await setupServer()); @@ -55,9 +56,17 @@ describe('DELETE /api/saved_objects/{type}/{id}', () => { const coreUsageData = coreUsageDataServiceMock.createSetupContract(coreUsageStatsClient); const logger = loggerMock.create(); loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(); + registrationSpy = jest.spyOn(router, 'delete'); + const config = setupConfig(); const access = 'public'; - registerDeleteRoute(router, { config, coreUsageData, logger, access }); + registerDeleteRoute(router, { + config, + coreUsageData, + logger, + access, + deprecationInfo: deprecationMock, + }); await server.start(); }); @@ -120,4 +129,13 @@ describe('DELETE /api/saved_objects/{type}/{id}', () => { .expect(200); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); }); + + it('passes deprecation configuration to the router arguments', async () => { + await supertest(httpSetup.server.listener) + .delete('/api/saved_objects/index-pattern/logstash-*') + .expect(200); + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); + }); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/find.test.ts b/src/core/server/integration_tests/saved_objects/routes/find.test.ts index 4b5d7a4bfc795..6f9c235dc328b 100644 --- a/src/core/server/integration_tests/saved_objects/routes/find.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/find.test.ts @@ -22,7 +22,7 @@ import { registerFindRoute, type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; -import { setupConfig } from './routes_test_utils'; +import { deprecationMock, setupConfig } from './routes_test_utils'; type SetupServerReturn = Awaited>; @@ -42,6 +42,7 @@ describe('GET /api/saved_objects/_find', () => { let savedObjectsClient: ReturnType; let coreUsageStatsClient: jest.Mocked; let loggerWarnSpy: jest.SpyInstance; + let registrationSpy: jest.SpyInstance; const clientResponse = { total: 0, @@ -71,11 +72,18 @@ describe('GET /api/saved_objects/_find', () => { const logger = loggerMock.create(); loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(); + registrationSpy = jest.spyOn(router, 'get'); const config = setupConfig(); const access = 'public'; - registerFindRoute(router, { config, coreUsageData, logger, access }); + registerFindRoute(router, { + config, + coreUsageData, + logger, + access, + deprecationInfo: deprecationMock, + }); await server.start(); }); @@ -448,4 +456,14 @@ describe('GET /api/saved_objects/_find', () => { .expect(200); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); }); + + it('passes deprecation configuration to the router arguments', async () => { + await supertest(httpSetup.server.listener) + .get('/api/saved_objects/_find?type=foo&type=bar') + .set('x-elastic-internal-origin', 'kibana') + .expect(200); + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); + }); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/get.test.ts b/src/core/server/integration_tests/saved_objects/routes/get.test.ts index f4d8299b1b9c7..0c72a5b1cb292 100644 --- a/src/core/server/integration_tests/saved_objects/routes/get.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/get.test.ts @@ -25,7 +25,7 @@ import { } from '@kbn/core-saved-objects-server-internal'; import { createHiddenTypeVariants } from '@kbn/core-test-helpers-test-utils'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from './routes_test_utils'; +import { deprecationMock, setupConfig } from './routes_test_utils'; const coreId = Symbol('core'); const testTypes = [ @@ -41,6 +41,7 @@ describe('GET /api/saved_objects/{type}/{id}', () => { let savedObjectsClient: ReturnType; let coreUsageStatsClient: jest.Mocked; let loggerWarnSpy: jest.SpyInstance; + let registrationSpy: jest.SpyInstance; beforeEach(async () => { const coreContext = createCoreContext({ coreId }); @@ -80,10 +81,18 @@ describe('GET /api/saved_objects/{type}/{id}', () => { const logger = loggerMock.create(); loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(); + registrationSpy = jest.spyOn(router, 'get'); + const config = setupConfig(); const access = 'public'; - registerGetRoute(router, { config, coreUsageData, logger, access }); + registerGetRoute(router, { + config, + coreUsageData, + logger, + access, + deprecationInfo: deprecationMock, + }); await server.start(); }); @@ -140,4 +149,14 @@ describe('GET /api/saved_objects/{type}/{id}', () => { .expect(200); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); }); + + it('passes deprecation configuration to the router arguments', async () => { + await supertest(httpSetup.server.listener) + .get('/api/saved_objects/index-pattern/logstash-*') + .set('x-elastic-internal-origin', 'kibana') + .expect(200); + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); + }); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/legacy_import_export/export.test.ts b/src/core/server/integration_tests/saved_objects/routes/legacy_import_export/export.test.ts index 5481fbc807276..9defefd7fc6d3 100644 --- a/src/core/server/integration_tests/saved_objects/routes/legacy_import_export/export.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/legacy_import_export/export.test.ts @@ -41,6 +41,7 @@ import { registerLegacyExportRoute, type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; +import { legacyDeprecationMock } from '../routes_test_utils'; type SetupServerReturn = Awaited>; let coreUsageStatsClient: jest.Mocked; @@ -58,11 +59,13 @@ describe('POST /api/dashboards/export', () => { coreUsageStatsClient = coreUsageStatsClientMock.create(); coreUsageStatsClient.incrementLegacyDashboardsExport.mockRejectedValue(new Error('Oh no!')); // intentionally throw this error, which is swallowed, so we can assert that the operation does not fail const coreUsageData = coreUsageDataServiceMock.createSetupContract(coreUsageStatsClient); + registerLegacyExportRoute(router, { kibanaVersion: 'mockversion', coreUsageData, logger: loggerMock.create(), access: 'public', + legacyDeprecationInfo: legacyDeprecationMock, }); handlerContext.savedObjects.client.bulkGet diff --git a/src/core/server/integration_tests/saved_objects/routes/legacy_import_export/import.test.ts b/src/core/server/integration_tests/saved_objects/routes/legacy_import_export/import.test.ts index 8157c77e936a9..0c631a4247368 100644 --- a/src/core/server/integration_tests/saved_objects/routes/legacy_import_export/import.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/legacy_import_export/import.test.ts @@ -41,6 +41,7 @@ import { registerLegacyImportRoute, type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; +import { legacyDeprecationMock } from '../routes_test_utils'; type SetupServerReturn = Awaited>; let coreUsageStatsClient: jest.Mocked; @@ -58,11 +59,13 @@ describe('POST /api/dashboards/import', () => { coreUsageStatsClient = coreUsageStatsClientMock.create(); coreUsageStatsClient.incrementLegacyDashboardsImport.mockRejectedValue(new Error('Oh no!')); // intentionally throw this error, which is swallowed, so we can assert that the operation does not fail const coreUsageData = coreUsageDataServiceMock.createSetupContract(coreUsageStatsClient); + registerLegacyImportRoute(router, { maxImportPayloadBytes: 26214400, coreUsageData, logger: loggerMock.create(), access: 'public', + legacyDeprecationInfo: legacyDeprecationMock, }); handlerContext.savedObjects.client.bulkCreate.mockResolvedValueOnce({ diff --git a/src/core/server/integration_tests/saved_objects/routes/resolve.test.ts b/src/core/server/integration_tests/saved_objects/routes/resolve.test.ts index fcedbc9eea147..67dbacece30ab 100644 --- a/src/core/server/integration_tests/saved_objects/routes/resolve.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/resolve.test.ts @@ -25,7 +25,7 @@ import { } from '@kbn/core-saved-objects-server-internal'; import { createHiddenTypeVariants } from '@kbn/core-test-helpers-test-utils'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from './routes_test_utils'; +import { deprecationMock, setupConfig } from './routes_test_utils'; const coreId = Symbol('core'); @@ -42,6 +42,7 @@ describe('GET /api/saved_objects/resolve/{type}/{id}', () => { let savedObjectsClient: ReturnType; let coreUsageStatsClient: jest.Mocked; let loggerWarnSpy: jest.SpyInstance; + let registrationSpy: jest.SpyInstance; beforeEach(async () => { const coreContext = createCoreContext({ coreId }); @@ -79,10 +80,18 @@ describe('GET /api/saved_objects/resolve/{type}/{id}', () => { const coreUsageData = coreUsageDataServiceMock.createSetupContract(coreUsageStatsClient); const logger = loggerMock.create(); loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(); + registrationSpy = jest.spyOn(router, 'get'); + const config = setupConfig(); const access = 'public'; - registerResolveRoute(router, { config, coreUsageData, logger, access }); + registerResolveRoute(router, { + config, + coreUsageData, + logger, + access, + deprecationInfo: deprecationMock, + }); await server.start(); }); @@ -138,4 +147,14 @@ describe('GET /api/saved_objects/resolve/{type}/{id}', () => { .expect(200); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); }); + + it('passes deprecation configuration to the router arguments', async () => { + await supertest(httpSetup.server.listener) + .get('/api/saved_objects/resolve/index-pattern/logstash-*') + .set('x-elastic-internal-origin', 'kibana') + .expect(200); + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); + }); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/routes_test_utils.ts b/src/core/server/integration_tests/saved_objects/routes/routes_test_utils.ts index b27b2b72aba97..3c78b4e7f0e3b 100644 --- a/src/core/server/integration_tests/saved_objects/routes/routes_test_utils.ts +++ b/src/core/server/integration_tests/saved_objects/routes/routes_test_utils.ts @@ -15,3 +15,19 @@ export function setupConfig(allowAccess: boolean = false) { } as SavedObjectConfig; return config; } + +export const deprecationMock = { + documentationUrl: 'http://elastic.co', + severity: 'warning' as const, + reason: { + type: 'deprecate' as const, + }, +}; + +export const legacyDeprecationMock = { + documentationUrl: 'http://elastic.co', + severity: 'warning' as const, + reason: { + type: 'remove' as const, + }, +}; diff --git a/src/core/server/integration_tests/saved_objects/routes/update.test.ts b/src/core/server/integration_tests/saved_objects/routes/update.test.ts index 0dc249e863a44..4e25d22ade46c 100644 --- a/src/core/server/integration_tests/saved_objects/routes/update.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/update.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from './routes_test_utils'; +import { deprecationMock, setupConfig } from './routes_test_utils'; type SetupServerReturn = Awaited>; @@ -37,6 +37,7 @@ describe('PUT /api/saved_objects/{type}/{id?}', () => { let savedObjectsClient: ReturnType; let coreUsageStatsClient: jest.Mocked; let loggerWarnSpy: jest.SpyInstance; + let registrationSpy: jest.SpyInstance; beforeEach(async () => { const clientResponse = { @@ -66,10 +67,17 @@ describe('PUT /api/saved_objects/{type}/{id?}', () => { const coreUsageData = coreUsageDataServiceMock.createSetupContract(coreUsageStatsClient); const logger = loggerMock.create(); loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(); + registrationSpy = jest.spyOn(router, 'put'); const config = setupConfig(); const access = 'public'; - registerUpdateRoute(router, { config, coreUsageData, logger, access }); + registerUpdateRoute(router, { + config, + coreUsageData, + logger, + access, + deprecationInfo: deprecationMock, + }); await server.start(); }); @@ -141,4 +149,15 @@ describe('PUT /api/saved_objects/{type}/{id?}', () => { .expect(200); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); }); + + it('passes deprecation configuration to the router arguments', async () => { + await supertest(httpSetup.server.listener) + .put('/api/saved_objects/index-pattern/logstash-*') + .set('x-elastic-internal-origin', 'kibana') + .send({ attributes: { title: 'Logging test' }, version: 'log' }) + .expect(200); + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); + }); }); From b428f1f5949bcc50738c18188ca48ec2767d7a76 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 21 Nov 2024 12:47:31 +0000 Subject: [PATCH 2/2] [CI] Auto-commit changed files from 'make api-docs' --- oas_docs/output/kibana.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/oas_docs/output/kibana.yaml b/oas_docs/output/kibana.yaml index c51071bf70465..d20c9a53cac5c 100644 --- a/oas_docs/output/kibana.yaml +++ b/oas_docs/output/kibana.yaml @@ -112,7 +112,7 @@ tags: description: Kibana role management url: https://www.elastic.co/guide/en/kibana/8.x/kibana-role-management.html - description: | - Export sets of saved objects that you want to import into {kib}, resolve import errors, and rotate an encryption key for encrypted saved objects with the saved objects APIs. + Export sets of saved objects that you want to import into Kibana, resolve import errors, and rotate an encryption key for encrypted saved objects with the saved objects APIs. To manage a specific type of saved object, use the corresponding APIs. For example, use: @@ -17984,7 +17984,7 @@ paths: schema: type: object description: | - Indicates a successful call. NOTE: This HTTP response code indicates that the bulk operation succeeded. Errors pertaining to individual objects will be returned in the response body. + Indicates a successful call. NOTE: This HTTP response code indicates that the bulk operation succeeded. Errors pertaining to individual objects will be returned in the response body. '400': content: application/json; Elastic-Api-Version=2023-10-31: @@ -18016,7 +18016,7 @@ paths: schema: type: object description: | - Indicates a successful call. NOTE: This HTTP response code indicates that the bulk operation succeeded. Errors pertaining to individual objects will be returned in the response body. + Indicates a successful call. NOTE: This HTTP response code indicates that the bulk operation succeeded. Errors pertaining to individual objects will be returned in the response body. '400': content: application/json; Elastic-Api-Version=2023-10-31: