Skip to content

Commit

Permalink
Remove LegacyRequest type from Core public API (#109243)
Browse files Browse the repository at this point in the history
* remove LegacyRequest from public API

* remove LegacyRequest from Security plugin API

* update docs

* remove an obsolete comment
  • Loading branch information
mshustov authored Aug 19, 2021
1 parent 7cc59d7 commit fe96d3c
Show file tree
Hide file tree
Showing 25 changed files with 49 additions and 233 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ returns `basePath` value, specific for an incoming request.
<b>Signature:</b>

```typescript
get: (request: KibanaRequest | LegacyRequest) => string;
get: (request: KibanaRequest) => string;
```
Original file line number Diff line number Diff line change
Expand Up @@ -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) | | <code>(request: KibanaRequest &#124; LegacyRequest) =&gt; string</code> | returns <code>basePath</code> value, specific for an incoming request. |
| [get](./kibana-plugin-core-server.basepath.get.md) | | <code>(request: KibanaRequest) =&gt; string</code> | returns <code>basePath</code> value, specific for an incoming request. |
| [prepend](./kibana-plugin-core-server.basepath.prepend.md) | | <code>(path: string) =&gt; string</code> | Prepends <code>path</code> with the basePath. |
| [publicBaseUrl](./kibana-plugin-core-server.basepath.publicbaseurl.md) | | <code>string</code> | 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) | | <code>(path: string) =&gt; string</code> | Removes the prepended basePath from the <code>path</code>. |
| [serverBasePath](./kibana-plugin-core-server.basepath.serverbasepath.md) | | <code>string</code> | returns the server's basePath<!-- -->See [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) | | <code>(request: KibanaRequest &#124; LegacyRequest, requestSpecificBasePath: string) =&gt; void</code> | sets <code>basePath</code> value, specific for an incoming request. |
| [set](./kibana-plugin-core-server.basepath.set.md) | | <code>(request: KibanaRequest, requestSpecificBasePath: string) =&gt; void</code> | sets <code>basePath</code> value, specific for an incoming request. |

Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ sets `basePath` value, specific for an incoming request.
<b>Signature:</b>

```typescript
set: (request: KibanaRequest | LegacyRequest, requestSpecificBasePath: string) => void;
set: (request: KibanaRequest, requestSpecificBasePath: string) => void;
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Get headers to authenticate a user against Elasticsearch.
<b>Signature:</b>

```typescript
export declare type GetAuthHeaders = (request: KibanaRequest | LegacyRequest) => AuthHeaders | undefined;
export declare type GetAuthHeaders = (request: KibanaRequest) => AuthHeaders | undefined;
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gets authentication state for a request. Returned by `auth` interceptor.
<b>Signature:</b>

```typescript
export declare type GetAuthState = <T = unknown>(request: KibanaRequest | LegacyRequest) => {
export declare type GetAuthState = <T = unknown>(request: KibanaRequest) => {
status: AuthStatus;
state: T;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Returns authentication status for a request.
<b>Signature:</b>

```typescript
export declare type IsAuthenticated = (request: KibanaRequest | LegacyRequest) => boolean;
export declare type IsAuthenticated = (request: KibanaRequest) => boolean;
```

This file was deleted.

3 changes: 1 addition & 2 deletions docs/development/core/server/kibana-plugin-core-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand All @@ -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 <code>PluginInitializer</code> for a <code>preboot</code> 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 <code>resolveCapabilities</code> 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. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ See [KibanaRequest](./kibana-plugin-core-server.kibanarequest.md)<!-- -->.
<b>Signature:</b>

```typescript
export declare type ScopeableRequest = KibanaRequest | LegacyRequest | FakeRequest;
export declare type ScopeableRequest = KibanaRequest | FakeRequest;
```
4 changes: 2 additions & 2 deletions src/core/server/elasticsearch/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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`.
Expand Down
24 changes: 3 additions & 21 deletions src/core/server/http/auth_headers_storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
2 changes: 1 addition & 1 deletion src/core/server/http/auth_headers_storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/http/auth_state_storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ export enum AuthStatus {
* @public
*/
export type GetAuthState = <T = unknown>(
request: KibanaRequest | LegacyRequest
request: KibanaRequest
) => { status: AuthStatus; state: T };

/**
* Returns authentication status for a request.
* @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 {
Expand Down
25 changes: 4 additions & 21 deletions src/core/server/http/base_path_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import { BasePath } from './base_path_service';
import { KibanaRequest } from './router';
import { httpServerMock } from './http_server.mocks';

describe('BasePath', () => {
Expand Down Expand Up @@ -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/');
Expand All @@ -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/');
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/http/base_path_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
};
Expand All @@ -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)) {
Expand Down
13 changes: 6 additions & 7 deletions src/core/server/http/cookie_session_storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -323,7 +322,7 @@ describe.skip('Cookie based SessionStorage', () => {
},
};

const mockRequest = httpServerMock.createRawRequest();
const mockRequest = httpServerMock.createKibanaRequest();

const factory = await createCookieSessionStorageFactory(
logger.get(),
Expand All @@ -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);
Expand All @@ -354,7 +353,7 @@ describe.skip('Cookie based SessionStorage', () => {
},
};

const mockRequest = httpServerMock.createRawRequest();
const mockRequest = httpServerMock.createKibanaRequest();

const factory = await createCookieSessionStorageFactory(
logger.get(),
Expand All @@ -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);
Expand All @@ -383,7 +382,7 @@ describe.skip('Cookie based SessionStorage', () => {
},
};

const mockRequest = httpServerMock.createRawRequest();
const mockRequest = httpServerMock.createKibanaRequest();

const factory = await createCookieSessionStorageFactory(
logger.get(),
Expand All @@ -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.']]);
Expand Down
1 change: 0 additions & 1 deletion src/core/server/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export type {
KibanaRequestRouteOptions,
IKibanaResponse,
KnownHeaders,
LegacyRequest,
LifecycleResponseFactory,
RedirectResponseOptions,
RequestHandler,
Expand Down
3 changes: 0 additions & 3 deletions src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ export type {
IKibanaResponse,
LifecycleResponseFactory,
KnownHeaders,
LegacyRequest,
OnPreAuthHandler,
OnPreAuthToolkit,
OnPreRoutingHandler,
Expand Down Expand Up @@ -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
*
Expand Down
Loading

0 comments on commit fe96d3c

Please sign in to comment.