From e7f12de27cd8463eb3ce29578bb6880b2d715e64 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 19 Aug 2021 13:34:32 -0400 Subject: [PATCH] Remove LegacyRequest type from Core public API (#109243) (#109268) * remove LegacyRequest from public API * remove LegacyRequest from Security plugin API * update docs * remove an obsolete comment Co-authored-by: Mikhail Shustov --- .../kibana-plugin-core-server.basepath.get.md | 2 +- .../kibana-plugin-core-server.basepath.md | 4 +- .../kibana-plugin-core-server.basepath.set.md | 2 +- ...ibana-plugin-core-server.getauthheaders.md | 2 +- .../kibana-plugin-core-server.getauthstate.md | 2 +- ...bana-plugin-core-server.isauthenticated.md | 2 +- ...kibana-plugin-core-server.legacyrequest.md | 16 --- .../core/server/kibana-plugin-core-server.md | 3 +- ...lugin-core-server.requesthandlercontext.md | 2 +- ...ana-plugin-core-server.scopeablerequest.md | 2 +- src/core/server/elasticsearch/types.ts | 4 +- .../server/http/auth_headers_storage.test.ts | 24 +---- src/core/server/http/auth_headers_storage.ts | 2 +- src/core/server/http/auth_state_storage.ts | 4 +- .../server/http/base_path_service.test.ts | 25 +---- src/core/server/http/base_path_service.ts | 4 +- .../http/cookie_session_storage.test.ts | 13 ++- src/core/server/http/index.ts | 1 - src/core/server/index.ts | 3 - .../rendering_service.test.ts.snap | 102 ------------------ .../rendering/rendering_service.test.ts | 11 +- .../server/rendering/rendering_service.tsx | 4 +- src/core/server/rendering/types.ts | 11 +- src/core/server/server.api.md | 18 ++-- .../security/server/saved_objects/index.ts | 19 ++-- 25 files changed, 49 insertions(+), 233 deletions(-) delete mode 100644 docs/development/core/server/kibana-plugin-core-server.legacyrequest.md diff --git a/docs/development/core/server/kibana-plugin-core-server.basepath.get.md b/docs/development/core/server/kibana-plugin-core-server.basepath.get.md index f1e71616d4d17..b35c6e657b01f 100644 --- a/docs/development/core/server/kibana-plugin-core-server.basepath.get.md +++ b/docs/development/core/server/kibana-plugin-core-server.basepath.get.md @@ -9,5 +9,5 @@ returns `basePath` value, specific for an incoming request. Signature: ```typescript -get: (request: KibanaRequest | LegacyRequest) => string; +get: (request: KibanaRequest) => string; ``` diff --git a/docs/development/core/server/kibana-plugin-core-server.basepath.md b/docs/development/core/server/kibana-plugin-core-server.basepath.md index 54ab029d987a7..f4bac88cd85f5 100644 --- a/docs/development/core/server/kibana-plugin-core-server.basepath.md +++ b/docs/development/core/server/kibana-plugin-core-server.basepath.md @@ -20,10 +20,10 @@ The constructor for this class is marked as internal. Third-party code should no | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [get](./kibana-plugin-core-server.basepath.get.md) | | (request: KibanaRequest | LegacyRequest) => string | returns basePath value, specific for an incoming request. | +| [get](./kibana-plugin-core-server.basepath.get.md) | | (request: KibanaRequest) => string | returns basePath value, specific for an incoming request. | | [prepend](./kibana-plugin-core-server.basepath.prepend.md) | | (path: string) => string | Prepends path with the basePath. | | [publicBaseUrl](./kibana-plugin-core-server.basepath.publicbaseurl.md) | | string | The server's publicly exposed base URL, if configured. Includes protocol, host, port (optional) and the [BasePath.serverBasePath](./kibana-plugin-core-server.basepath.serverbasepath.md). | | [remove](./kibana-plugin-core-server.basepath.remove.md) | | (path: string) => string | Removes the prepended basePath from the path. | | [serverBasePath](./kibana-plugin-core-server.basepath.serverbasepath.md) | | string | returns the server's basePathSee [BasePath.get](./kibana-plugin-core-server.basepath.get.md) for getting the basePath value for a specific request | -| [set](./kibana-plugin-core-server.basepath.set.md) | | (request: KibanaRequest | LegacyRequest, requestSpecificBasePath: string) => void | sets basePath value, specific for an incoming request. | +| [set](./kibana-plugin-core-server.basepath.set.md) | | (request: KibanaRequest, requestSpecificBasePath: string) => void | sets basePath value, specific for an incoming request. | diff --git a/docs/development/core/server/kibana-plugin-core-server.basepath.set.md b/docs/development/core/server/kibana-plugin-core-server.basepath.set.md index eb355f134d562..b90767022d594 100644 --- a/docs/development/core/server/kibana-plugin-core-server.basepath.set.md +++ b/docs/development/core/server/kibana-plugin-core-server.basepath.set.md @@ -9,5 +9,5 @@ sets `basePath` value, specific for an incoming request. Signature: ```typescript -set: (request: KibanaRequest | LegacyRequest, requestSpecificBasePath: string) => void; +set: (request: KibanaRequest, requestSpecificBasePath: string) => void; ``` diff --git a/docs/development/core/server/kibana-plugin-core-server.getauthheaders.md b/docs/development/core/server/kibana-plugin-core-server.getauthheaders.md index c66aead4dfa9c..2f1502a5ea0ea 100644 --- a/docs/development/core/server/kibana-plugin-core-server.getauthheaders.md +++ b/docs/development/core/server/kibana-plugin-core-server.getauthheaders.md @@ -9,5 +9,5 @@ Get headers to authenticate a user against Elasticsearch. Signature: ```typescript -export declare type GetAuthHeaders = (request: KibanaRequest | LegacyRequest) => AuthHeaders | undefined; +export declare type GetAuthHeaders = (request: KibanaRequest) => AuthHeaders | undefined; ``` diff --git a/docs/development/core/server/kibana-plugin-core-server.getauthstate.md b/docs/development/core/server/kibana-plugin-core-server.getauthstate.md index 0fa8d745d3a44..979a6b5b5792b 100644 --- a/docs/development/core/server/kibana-plugin-core-server.getauthstate.md +++ b/docs/development/core/server/kibana-plugin-core-server.getauthstate.md @@ -9,7 +9,7 @@ Gets authentication state for a request. Returned by `auth` interceptor. Signature: ```typescript -export declare type GetAuthState = (request: KibanaRequest | LegacyRequest) => { +export declare type GetAuthState = (request: KibanaRequest) => { status: AuthStatus; state: T; }; diff --git a/docs/development/core/server/kibana-plugin-core-server.isauthenticated.md b/docs/development/core/server/kibana-plugin-core-server.isauthenticated.md index de839619f3ac7..0c2d7fab8b579 100644 --- a/docs/development/core/server/kibana-plugin-core-server.isauthenticated.md +++ b/docs/development/core/server/kibana-plugin-core-server.isauthenticated.md @@ -9,5 +9,5 @@ Returns authentication status for a request. Signature: ```typescript -export declare type IsAuthenticated = (request: KibanaRequest | LegacyRequest) => boolean; +export declare type IsAuthenticated = (request: KibanaRequest) => boolean; ``` diff --git a/docs/development/core/server/kibana-plugin-core-server.legacyrequest.md b/docs/development/core/server/kibana-plugin-core-server.legacyrequest.md deleted file mode 100644 index 59d4fda87dc18..0000000000000 --- a/docs/development/core/server/kibana-plugin-core-server.legacyrequest.md +++ /dev/null @@ -1,16 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [LegacyRequest](./kibana-plugin-core-server.legacyrequest.md) - -## LegacyRequest interface - -> Warning: This API is now obsolete. -> -> `hapi` request object, supported during migration process only for backward compatibility. -> - -Signature: - -```typescript -export interface LegacyRequest extends Request -``` diff --git a/docs/development/core/server/kibana-plugin-core-server.md b/docs/development/core/server/kibana-plugin-core-server.md index ba4f528352566..96bb82c8968df 100644 --- a/docs/development/core/server/kibana-plugin-core-server.md +++ b/docs/development/core/server/kibana-plugin-core-server.md @@ -104,7 +104,6 @@ The plugin integrates with the core system via lifecycle events: `setup` | [IUiSettingsClient](./kibana-plugin-core-server.iuisettingsclient.md) | Server-side client that provides access to the advanced settings stored in elasticsearch. The settings provide control over the behavior of the Kibana application. For example, a user can specify how to display numeric or date fields. Users can adjust the settings via Management UI. | | [KibanaRequestEvents](./kibana-plugin-core-server.kibanarequestevents.md) | Request events. | | [KibanaRequestRoute](./kibana-plugin-core-server.kibanarequestroute.md) | Request specific route information exposed to a handler. | -| [LegacyRequest](./kibana-plugin-core-server.legacyrequest.md) | | | [LoggerContextConfigInput](./kibana-plugin-core-server.loggercontextconfiginput.md) | | | [LoggingServiceSetup](./kibana-plugin-core-server.loggingservicesetup.md) | Provides APIs to plugins for customizing the plugin's logger. | | [MetricsServiceSetup](./kibana-plugin-core-server.metricsservicesetup.md) | APIs to retrieves metrics gathered and exposed by the core platform. | @@ -127,7 +126,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [PrebootPlugin](./kibana-plugin-core-server.prebootplugin.md) | The interface that should be returned by a PluginInitializer for a preboot plugin. | | [PrebootServicePreboot](./kibana-plugin-core-server.prebootservicepreboot.md) | Kibana Preboot Service allows to control the boot flow of Kibana. Preboot plugins can use it to hold the boot until certain condition is met. | | [RegisterDeprecationsConfig](./kibana-plugin-core-server.registerdeprecationsconfig.md) | | -| [RequestHandlerContext](./kibana-plugin-core-server.requesthandlercontext.md) | Plugin specific context passed to a route handler.Provides the following clients and services: - [savedObjects.client](./kibana-plugin-core-server.savedobjectsclient.md) - Saved Objects client which uses the credentials of the incoming request - [savedObjects.typeRegistry](./kibana-plugin-core-server.isavedobjecttyperegistry.md) - Type registry containing all the registered types. - [elasticsearch.client](./kibana-plugin-core-server.iscopedclusterclient.md) - Elasticsearch data client which uses the credentials of the incoming request - - The legacy Elasticsearch data client which uses the credentials of the incoming request - [uiSettings.client](./kibana-plugin-core-server.iuisettingsclient.md) - uiSettings client which uses the credentials of the incoming request | +| [RequestHandlerContext](./kibana-plugin-core-server.requesthandlercontext.md) | Plugin specific context passed to a route handler.Provides the following clients and services: - [savedObjects.client](./kibana-plugin-core-server.savedobjectsclient.md) - Saved Objects client which uses the credentials of the incoming request - [savedObjects.typeRegistry](./kibana-plugin-core-server.isavedobjecttyperegistry.md) - Type registry containing all the registered types. - [elasticsearch.client](./kibana-plugin-core-server.iscopedclusterclient.md) - Elasticsearch data client which uses the credentials of the incoming request - [uiSettings.client](./kibana-plugin-core-server.iuisettingsclient.md) - uiSettings client which uses the credentials of the incoming request | | [ResolveCapabilitiesOptions](./kibana-plugin-core-server.resolvecapabilitiesoptions.md) | Defines a set of additional options for the resolveCapabilities method of [CapabilitiesStart](./kibana-plugin-core-server.capabilitiesstart.md). | | [RouteConfig](./kibana-plugin-core-server.routeconfig.md) | Route specific configuration. | | [RouteConfigOptions](./kibana-plugin-core-server.routeconfigoptions.md) | Additional route options. | diff --git a/docs/development/core/server/kibana-plugin-core-server.requesthandlercontext.md b/docs/development/core/server/kibana-plugin-core-server.requesthandlercontext.md index b6d78f8890b37..15a2e235fff29 100644 --- a/docs/development/core/server/kibana-plugin-core-server.requesthandlercontext.md +++ b/docs/development/core/server/kibana-plugin-core-server.requesthandlercontext.md @@ -6,7 +6,7 @@ Plugin specific context passed to a route handler. -Provides the following clients and services: - [savedObjects.client](./kibana-plugin-core-server.savedobjectsclient.md) - Saved Objects client which uses the credentials of the incoming request - [savedObjects.typeRegistry](./kibana-plugin-core-server.isavedobjecttyperegistry.md) - Type registry containing all the registered types. - [elasticsearch.client](./kibana-plugin-core-server.iscopedclusterclient.md) - Elasticsearch data client which uses the credentials of the incoming request - - The legacy Elasticsearch data client which uses the credentials of the incoming request - [uiSettings.client](./kibana-plugin-core-server.iuisettingsclient.md) - uiSettings client which uses the credentials of the incoming request +Provides the following clients and services: - [savedObjects.client](./kibana-plugin-core-server.savedobjectsclient.md) - Saved Objects client which uses the credentials of the incoming request - [savedObjects.typeRegistry](./kibana-plugin-core-server.isavedobjecttyperegistry.md) - Type registry containing all the registered types. - [elasticsearch.client](./kibana-plugin-core-server.iscopedclusterclient.md) - Elasticsearch data client which uses the credentials of the incoming request - [uiSettings.client](./kibana-plugin-core-server.iuisettingsclient.md) - uiSettings client which uses the credentials of the incoming request Signature: diff --git a/docs/development/core/server/kibana-plugin-core-server.scopeablerequest.md b/docs/development/core/server/kibana-plugin-core-server.scopeablerequest.md index 67abc483e1f65..f8f05823ae81f 100644 --- a/docs/development/core/server/kibana-plugin-core-server.scopeablerequest.md +++ b/docs/development/core/server/kibana-plugin-core-server.scopeablerequest.md @@ -11,5 +11,5 @@ See [KibanaRequest](./kibana-plugin-core-server.kibanarequest.md). Signature: ```typescript -export declare type ScopeableRequest = KibanaRequest | LegacyRequest | FakeRequest; +export declare type ScopeableRequest = KibanaRequest | FakeRequest; ``` diff --git a/src/core/server/elasticsearch/types.ts b/src/core/server/elasticsearch/types.ts index 89a7d752f7912..1b149cebfa957 100644 --- a/src/core/server/elasticsearch/types.ts +++ b/src/core/server/elasticsearch/types.ts @@ -8,7 +8,7 @@ import { Observable } from 'rxjs'; import { Headers } from '../http/router'; -import { LegacyRequest, KibanaRequest } from '../http'; +import { KibanaRequest } from '../http'; import { ElasticsearchConfig } from './elasticsearch_config'; import { IClusterClient, ICustomClusterClient, ElasticsearchClientConfig } from './client'; import { NodesVersionCompatibility } from './version_check/ensure_es_version'; @@ -156,7 +156,7 @@ export interface FakeRequest { * @public * See {@link KibanaRequest}. */ -export type ScopeableRequest = KibanaRequest | LegacyRequest | FakeRequest; +export type ScopeableRequest = KibanaRequest | FakeRequest; /** * A limited set of Elasticsearch configuration entries exposed to the `preboot` plugins at `setup`. diff --git a/src/core/server/http/auth_headers_storage.test.ts b/src/core/server/http/auth_headers_storage.test.ts index b4269a4401f50..6fb2281c81750 100644 --- a/src/core/server/http/auth_headers_storage.test.ts +++ b/src/core/server/http/auth_headers_storage.test.ts @@ -7,33 +7,15 @@ */ import { AuthHeadersStorage } from './auth_headers_storage'; -import { KibanaRequest } from './router'; import { httpServerMock } from './http_server.mocks'; describe('AuthHeadersStorage', () => { describe('stores authorization headers', () => { it('retrieves a copy of headers associated with Kibana request', () => { const headers = { authorization: 'token' }; const storage = new AuthHeadersStorage(); - const rawRequest = httpServerMock.createRawRequest(); - storage.set(KibanaRequest.from(rawRequest), headers); - expect(storage.get(KibanaRequest.from(rawRequest))).toEqual(headers); - }); - - it('retrieves a copy of headers associated with Legacy.Request', () => { - const headers = { authorization: 'token' }; - const storage = new AuthHeadersStorage(); - const rawRequest = httpServerMock.createRawRequest(); - storage.set(rawRequest, headers); - expect(storage.get(rawRequest)).toEqual(headers); - }); - - it('retrieves a copy of headers associated with both KibanaRequest & Legacy.Request', () => { - const headers = { authorization: 'token' }; - const storage = new AuthHeadersStorage(); - const rawRequest = httpServerMock.createRawRequest(); - - storage.set(KibanaRequest.from(rawRequest), headers); - expect(storage.get(rawRequest)).toEqual(headers); + const request = httpServerMock.createKibanaRequest(); + storage.set(request, headers); + expect(storage.get(request)).toEqual(headers); }); }); }); diff --git a/src/core/server/http/auth_headers_storage.ts b/src/core/server/http/auth_headers_storage.ts index 34799ed753689..cddf84bfa8caf 100644 --- a/src/core/server/http/auth_headers_storage.ts +++ b/src/core/server/http/auth_headers_storage.ts @@ -15,7 +15,7 @@ import { AuthHeaders } from './lifecycle/auth'; * @return authentication headers {@link AuthHeaders} for - an incoming request. * @public * */ -export type GetAuthHeaders = (request: KibanaRequest | LegacyRequest) => AuthHeaders | undefined; +export type GetAuthHeaders = (request: KibanaRequest) => AuthHeaders | undefined; /** @internal */ export class AuthHeadersStorage { diff --git a/src/core/server/http/auth_state_storage.ts b/src/core/server/http/auth_state_storage.ts index e29742bccbaae..2dd49f8fb99cc 100644 --- a/src/core/server/http/auth_state_storage.ts +++ b/src/core/server/http/auth_state_storage.ts @@ -33,7 +33,7 @@ export enum AuthStatus { * @public */ export type GetAuthState = ( - request: KibanaRequest | LegacyRequest + request: KibanaRequest ) => { status: AuthStatus; state: T }; /** @@ -41,7 +41,7 @@ export type GetAuthState = ( * @param request {@link KibanaRequest} - an incoming request. * @public */ -export type IsAuthenticated = (request: KibanaRequest | LegacyRequest) => boolean; +export type IsAuthenticated = (request: KibanaRequest) => boolean; /** @internal */ export class AuthStateStorage { diff --git a/src/core/server/http/base_path_service.test.ts b/src/core/server/http/base_path_service.test.ts index 751f4bc820e82..2d26000b4672b 100644 --- a/src/core/server/http/base_path_service.test.ts +++ b/src/core/server/http/base_path_service.test.ts @@ -7,7 +7,6 @@ */ import { BasePath } from './base_path_service'; -import { KibanaRequest } from './router'; import { httpServerMock } from './http_server.mocks'; describe('BasePath', () => { @@ -36,32 +35,16 @@ describe('BasePath', () => { }); describe('#get()', () => { - it('returns base path associated with an incoming Legacy.Request request', () => { - const request = httpServerMock.createRawRequest(); - - const basePath = new BasePath(); - basePath.set(request, '/baz/'); - expect(basePath.get(request)).toBe('/baz/'); - }); - it('returns base path associated with an incoming KibanaRequest', () => { - const request = httpServerMock.createRawRequest(); - const basePath = new BasePath(); - - basePath.set(KibanaRequest.from(request, undefined), '/baz/'); - expect(basePath.get(KibanaRequest.from(request, undefined))).toBe('/baz/'); - }); - - it('operates with both Legacy.Request/KibanaRequest requests', () => { - const request = httpServerMock.createRawRequest(); + const request = httpServerMock.createKibanaRequest(); const basePath = new BasePath(); basePath.set(request, '/baz/'); - expect(basePath.get(KibanaRequest.from(request, undefined))).toBe('/baz/'); + expect(basePath.get(request)).toBe('/baz/'); }); it('is based on server base path', () => { - const request = httpServerMock.createRawRequest(); + const request = httpServerMock.createKibanaRequest(); const basePath = new BasePath('/foo/bar'); basePath.set(request, '/baz/'); @@ -71,7 +54,7 @@ describe('BasePath', () => { describe('#set()', () => { it('#set() cannot be set twice for one request', () => { - const request = httpServerMock.createRawRequest(); + const request = httpServerMock.createKibanaRequest(); const basePath = new BasePath('/foo/bar'); const setPath = () => basePath.set(request, 'baz/'); diff --git a/src/core/server/http/base_path_service.ts b/src/core/server/http/base_path_service.ts index fbcf8ab59e45b..7de943a479810 100644 --- a/src/core/server/http/base_path_service.ts +++ b/src/core/server/http/base_path_service.ts @@ -42,7 +42,7 @@ export class BasePath { /** * returns `basePath` value, specific for an incoming request. */ - public get = (request: KibanaRequest | LegacyRequest) => { + public get = (request: KibanaRequest) => { const requestScopePath = this.basePathCache.get(ensureRawRequest(request)) || ''; return `${this.serverBasePath}${requestScopePath}`; }; @@ -52,7 +52,7 @@ export class BasePath { * * @privateRemarks should work only for KibanaRequest as soon as spaces migrate to NP */ - public set = (request: KibanaRequest | LegacyRequest, requestSpecificBasePath: string) => { + public set = (request: KibanaRequest, requestSpecificBasePath: string) => { const rawRequest = ensureRawRequest(request); if (this.basePathCache.has(rawRequest)) { diff --git a/src/core/server/http/cookie_session_storage.test.ts b/src/core/server/http/cookie_session_storage.test.ts index b09b200620fbf..22d747ff577ae 100644 --- a/src/core/server/http/cookie_session_storage.test.ts +++ b/src/core/server/http/cookie_session_storage.test.ts @@ -14,7 +14,6 @@ import { BehaviorSubject } from 'rxjs'; import { CoreContext } from '../core_context'; import { HttpService } from './http_service'; -import { KibanaRequest } from './router'; import { Env } from '../config'; import { contextServiceMock } from '../context/context_service.mock'; @@ -323,7 +322,7 @@ describe.skip('Cookie based SessionStorage', () => { }, }; - const mockRequest = httpServerMock.createRawRequest(); + const mockRequest = httpServerMock.createKibanaRequest(); const factory = await createCookieSessionStorageFactory( logger.get(), @@ -334,7 +333,7 @@ describe.skip('Cookie based SessionStorage', () => { expect(mockServer.register).toBeCalledTimes(1); expect(mockServer.auth.strategy).toBeCalledTimes(1); - const session = await factory.asScoped(KibanaRequest.from(mockRequest)).get(); + const session = await factory.asScoped(mockRequest).get(); expect(session).toBe(null); expect(mockServer.auth.test).toBeCalledTimes(1); @@ -354,7 +353,7 @@ describe.skip('Cookie based SessionStorage', () => { }, }; - const mockRequest = httpServerMock.createRawRequest(); + const mockRequest = httpServerMock.createKibanaRequest(); const factory = await createCookieSessionStorageFactory( logger.get(), @@ -365,7 +364,7 @@ describe.skip('Cookie based SessionStorage', () => { expect(mockServer.register).toBeCalledTimes(1); expect(mockServer.auth.strategy).toBeCalledTimes(1); - const session = await factory.asScoped(KibanaRequest.from(mockRequest)).get(); + const session = await factory.asScoped(mockRequest).get(); expect(session).toBe('foo'); expect(mockServer.auth.test).toBeCalledTimes(1); @@ -383,7 +382,7 @@ describe.skip('Cookie based SessionStorage', () => { }, }; - const mockRequest = httpServerMock.createRawRequest(); + const mockRequest = httpServerMock.createKibanaRequest(); const factory = await createCookieSessionStorageFactory( logger.get(), @@ -394,7 +393,7 @@ describe.skip('Cookie based SessionStorage', () => { expect(mockServer.register).toBeCalledTimes(1); expect(mockServer.auth.strategy).toBeCalledTimes(1); - const session = await factory.asScoped(KibanaRequest.from(mockRequest)).get(); + const session = await factory.asScoped(mockRequest).get(); expect(session).toBe(null); expect(loggingSystemMock.collect(logger).debug).toEqual([['Error: Invalid cookie.']]); diff --git a/src/core/server/http/index.ts b/src/core/server/http/index.ts index cad5a50dbc505..a56071ed1d980 100644 --- a/src/core/server/http/index.ts +++ b/src/core/server/http/index.ts @@ -30,7 +30,6 @@ export type { KibanaRequestRouteOptions, IKibanaResponse, KnownHeaders, - LegacyRequest, LifecycleResponseFactory, RedirectResponseOptions, RequestHandler, diff --git a/src/core/server/index.ts b/src/core/server/index.ts index 19f7daff13ccc..1c3a0850d3b79 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -172,7 +172,6 @@ export type { IKibanaResponse, LifecycleResponseFactory, KnownHeaders, - LegacyRequest, OnPreAuthHandler, OnPreAuthToolkit, OnPreRoutingHandler, @@ -423,8 +422,6 @@ export type { CoreUsageDataStart } from './core_usage_data'; * all the registered types. * - {@link IScopedClusterClient | elasticsearch.client} - Elasticsearch * data client which uses the credentials of the incoming request - * - {@link LegacyScopedClusterClient | elasticsearch.legacy.client} - The legacy Elasticsearch - * data client which uses the credentials of the incoming request * - {@link IUiSettingsClient | uiSettings.client} - uiSettings client * which uses the credentials of the incoming request * diff --git a/src/core/server/rendering/__snapshots__/rendering_service.test.ts.snap b/src/core/server/rendering/__snapshots__/rendering_service.test.ts.snap index 495a38a1af5bf..5ea65cd8d0c73 100644 --- a/src/core/server/rendering/__snapshots__/rendering_service.test.ts.snap +++ b/src/core/server/rendering/__snapshots__/rendering_service.test.ts.snap @@ -1,56 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`RenderingService preboot() render() renders "core" from legacy request 1`] = ` -Object { - "anonymousStatusPage": false, - "basePath": "/mock-server-basepath", - "branch": Any, - "buildNumber": Any, - "csp": Object { - "warnLegacyBrowsers": true, - }, - "env": Object { - "mode": Object { - "dev": Any, - "name": Any, - "prod": Any, - }, - "packageInfo": Object { - "branch": Any, - "buildNum": Any, - "buildSha": Any, - "dist": Any, - "version": Any, - }, - }, - "externalUrl": Object { - "policy": Array [ - Object { - "allow": true, - }, - ], - }, - "i18n": Object { - "translationsUrl": "/mock-server-basepath/translations/en.json", - }, - "legacyMetadata": Object { - "uiSettings": Object { - "defaults": Object { - "registered": Object { - "name": "title", - }, - }, - "user": Object {}, - }, - }, - "publicBaseUrl": "http://myhost.com/mock-server-basepath", - "serverBasePath": "/mock-server-basepath", - "uiPlugins": Array [], - "vars": Object {}, - "version": Any, -} -`; - exports[`RenderingService preboot() render() renders "core" page 1`] = ` Object { "anonymousStatusPage": false, @@ -259,57 +208,6 @@ Object { } `; -exports[`RenderingService setup() render() renders "core" from legacy request 1`] = ` -Object { - "anonymousStatusPage": false, - "basePath": "/mock-server-basepath", - "branch": Any, - "buildNumber": Any, - "csp": Object { - "warnLegacyBrowsers": true, - }, - "env": Object { - "mode": Object { - "dev": Any, - "name": Any, - "prod": Any, - }, - "packageInfo": Object { - "branch": Any, - "buildNum": Any, - "buildSha": Any, - "dist": Any, - "version": Any, - }, - }, - "externalUrl": Object { - "policy": Array [ - Object { - "allow": true, - }, - ], - }, - "i18n": Object { - "translationsUrl": "/mock-server-basepath/translations/en.json", - }, - "legacyMetadata": Object { - "uiSettings": Object { - "defaults": Object { - "registered": Object { - "name": "title", - }, - }, - "user": Object {}, - }, - }, - "publicBaseUrl": "http://myhost.com/mock-server-basepath", - "serverBasePath": "/mock-server-basepath", - "uiPlugins": Array [], - "vars": Object {}, - "version": Any, -} -`; - exports[`RenderingService setup() render() renders "core" page 1`] = ` Object { "anonymousStatusPage": false, diff --git a/src/core/server/rendering/rendering_service.test.ts b/src/core/server/rendering/rendering_service.test.ts index de7d21add6c6c..f75d405fe8bf9 100644 --- a/src/core/server/rendering/rendering_service.test.ts +++ b/src/core/server/rendering/rendering_service.test.ts @@ -46,7 +46,7 @@ const INJECTED_METADATA = { }, }; -const { createKibanaRequest, createRawRequest } = httpServerMock; +const { createKibanaRequest } = httpServerMock; function renderTestCases( getRender: () => Promise< @@ -107,15 +107,6 @@ function renderTestCases( expect(data).toMatchSnapshot(INJECTED_METADATA); }); - it('renders "core" from legacy request', async () => { - const [render] = await getRender(); - const content = await render(createRawRequest(), uiSettings); - const dom = load(content); - const data = JSON.parse(dom('kbn-injected-metadata').attr('data') ?? '""'); - - expect(data).toMatchSnapshot(INJECTED_METADATA); - }); - it('calls `getStylesheetPaths` with the correct parameters', async () => { getSettingValueMock.mockImplementation((settingName: string) => { if (settingName === 'theme:darkMode') { diff --git a/src/core/server/rendering/rendering_service.tsx b/src/core/server/rendering/rendering_service.tsx index 2d95822d92219..f8b99686ff557 100644 --- a/src/core/server/rendering/rendering_service.tsx +++ b/src/core/server/rendering/rendering_service.tsx @@ -24,7 +24,7 @@ import { } from './types'; import { registerBootstrapRoute, bootstrapRendererFactory } from './bootstrap'; import { getSettingValue, getStylesheetPaths } from './render_utils'; -import { KibanaRequest, LegacyRequest } from '../http'; +import { KibanaRequest } from '../http'; import { IUiSettingsClient } from '../ui_settings'; type RenderOptions = (RenderingPrebootDeps & { status?: never }) | RenderingSetupDeps; @@ -76,7 +76,7 @@ export class RenderingService { private async render( { http, uiPlugins, status }: RenderOptions, - request: KibanaRequest | LegacyRequest, + request: KibanaRequest, uiSettings: IUiSettingsClient, { includeUserSettings = true, vars }: IRenderOptions = {} ) { diff --git a/src/core/server/rendering/types.ts b/src/core/server/rendering/types.ts index 8dec4bc69d9ea..8089878ccefd0 100644 --- a/src/core/server/rendering/types.ts +++ b/src/core/server/rendering/types.ts @@ -10,12 +10,7 @@ import { i18n } from '@kbn/i18n'; import { EnvironmentMode, PackageInfo } from '../config'; import { ICspConfig } from '../csp'; -import { - InternalHttpServicePreboot, - InternalHttpServiceSetup, - KibanaRequest, - LegacyRequest, -} from '../http'; +import { InternalHttpServicePreboot, InternalHttpServiceSetup, KibanaRequest } from '../http'; import { UiPlugins, DiscoveredPlugin } from '../plugins'; import { IUiSettingsClient, UserProvidedValues } from '../ui_settings'; import type { InternalStatusServiceSetup } from '../status'; @@ -103,8 +98,8 @@ export interface InternalRenderingServiceSetup { * const html = await rendering.render(request, uiSettings); * ``` */ - render( - request: R, + render( + request: KibanaRequest, uiSettings: IUiSettingsClient, options?: IRenderOptions ): Promise; diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index cbe5f4e0cf1b6..47455e0c14316 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -159,12 +159,12 @@ export interface AuthToolkit { export class BasePath { // @internal constructor(serverBasePath?: string, publicBaseUrl?: string); - get: (request: KibanaRequest | LegacyRequest) => string; + get: (request: KibanaRequest) => string; prepend: (path: string) => string; readonly publicBaseUrl?: string; remove: (path: string) => string; readonly serverBasePath: string; - set: (request: KibanaRequest | LegacyRequest, requestSpecificBasePath: string) => void; + set: (request: KibanaRequest, requestSpecificBasePath: string) => void; } // Warning: (ae-forgotten-export) The symbol "BootstrapArgs" needs to be exported by the entry point index.d.ts @@ -896,10 +896,10 @@ export interface FakeRequest { } // @public -export type GetAuthHeaders = (request: KibanaRequest | LegacyRequest) => AuthHeaders | undefined; +export type GetAuthHeaders = (request: KibanaRequest) => AuthHeaders | undefined; // @public -export type GetAuthState = (request: KibanaRequest | LegacyRequest) => { +export type GetAuthState = (request: KibanaRequest) => { status: AuthStatus; state: T; }; @@ -1137,7 +1137,7 @@ export interface IRouter boolean; +export type IsAuthenticated = (request: KibanaRequest) => boolean; // @public (undocumented) export type ISavedObjectsExporter = PublicMethodsOf; @@ -1263,10 +1263,6 @@ export const kibanaResponseFactory: { // @public export type KnownHeaders = KnownKeys; -// @public @deprecated (undocumented) -export interface LegacyRequest extends Request { -} - // Warning: (ae-forgotten-export) The symbol "lifecycleResponseFactory" needs to be exported by the entry point index.d.ts // // @public @@ -1607,8 +1603,6 @@ export interface RegisterDeprecationsConfig { // @public export type RequestHandler

= (context: Context, request: KibanaRequest, response: ResponseFactory) => IKibanaResponse | Promise>; -// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "kibana" does not have an export "LegacyScopedClusterClient" -// // @public export interface RequestHandlerContext { // (undocumented) @@ -2719,7 +2713,7 @@ export class SavedObjectTypeRegistry { export type SavedObjectUnsanitizedDoc = SavedObjectDoc & Partial; // @public -export type ScopeableRequest = KibanaRequest | LegacyRequest | FakeRequest; +export type ScopeableRequest = KibanaRequest | FakeRequest; // @public (undocumented) export interface SearchResponse { diff --git a/x-pack/plugins/security/server/saved_objects/index.ts b/x-pack/plugins/security/server/saved_objects/index.ts index b291fa86bbf56..ad04ab706c2d4 100644 --- a/x-pack/plugins/security/server/saved_objects/index.ts +++ b/x-pack/plugins/security/server/saved_objects/index.ts @@ -5,9 +5,9 @@ * 2.0. */ -import type { CoreSetup, LegacyRequest } from 'src/core/server'; +import type { CoreSetup } from 'src/core/server'; -import { KibanaRequest, SavedObjectsClient } from '../../../../../src/core/server'; +import { SavedObjectsClient } from '../../../../../src/core/server'; import type { AuditServiceSetup, SecurityAuditLogger } from '../audit'; import type { AuthorizationServiceSetupInternal } from '../authorization'; import type { SpacesService } from '../plugin'; @@ -44,30 +44,25 @@ export function setupSavedObjects({ savedObjects, getSpacesService, }: SetupSavedObjectsParams) { - const getKibanaRequest = (request: KibanaRequest | LegacyRequest) => - request instanceof KibanaRequest ? request : KibanaRequest.from(request); - savedObjects.setClientFactoryProvider( (repositoryFactory) => ({ request, includedHiddenTypes }) => { - const kibanaRequest = getKibanaRequest(request); return new SavedObjectsClient( - authz.mode.useRbacForRequest(kibanaRequest) + authz.mode.useRbacForRequest(request) ? repositoryFactory.createInternalRepository(includedHiddenTypes) - : repositoryFactory.createScopedRepository(kibanaRequest, includedHiddenTypes) + : repositoryFactory.createScopedRepository(request, includedHiddenTypes) ); } ); savedObjects.addClientWrapper(Number.MAX_SAFE_INTEGER - 1, 'security', ({ client, request }) => { - const kibanaRequest = getKibanaRequest(request); - return authz.mode.useRbacForRequest(kibanaRequest) + return authz.mode.useRbacForRequest(request) ? new SecureSavedObjectsClientWrapper({ actions: authz.actions, legacyAuditLogger, - auditLogger: audit.asScoped(kibanaRequest), + auditLogger: audit.asScoped(request), baseClient: client, checkSavedObjectsPrivilegesAsCurrentUser: authz.checkSavedObjectsPrivilegesWithRequest( - kibanaRequest + request ), errors: SavedObjectsClient.errors, getSpacesService,