[HTTP] Expose versioned on IRouter (#156404)

## Summary

Adds the `VersionedRouter` to the public http contract.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Jean-Louis Leysens 2023-05-04 14:07:31 +02:00 committed by GitHub
parent 56fa5b90a1
commit 7438175a11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 24 additions and 20 deletions

View file

@ -23,7 +23,6 @@ import type {
IRouter,
RequestHandler,
VersionedRouter,
IRouterWithVersion,
} from '@kbn/core-http-server';
import { validBodyOutput } from '@kbn/core-http-server';
import { RouteValidator } from './validator';
@ -131,7 +130,7 @@ interface RouterOptions {
* @internal
*/
export class Router<Context extends RequestHandlerContextBase = RequestHandlerContextBase>
implements IRouterWithVersion<Context>
implements IRouter<Context>
{
public routes: Array<Readonly<RouterRoute>> = [];
public get: IRouter<Context>['get'];

View file

@ -18,5 +18,6 @@ export function createRouter(): jest.Mocked<IRouter> {
handleLegacyErrors: jest.fn(),
patch: jest.fn(),
routerPath: '',
versioned: {} as any,
};
}

View file

@ -12,7 +12,7 @@ import { stringify } from 'query-string';
import { hapiMocks } from '@kbn/hapi-mocks';
import { schema } from '@kbn/config-schema';
import type {
IRouterWithVersion,
IRouter,
KibanaRequest,
RouteMethod,
RouteValidationSpec,
@ -23,7 +23,7 @@ import type {
import { CoreKibanaRequest } from '@kbn/core-http-router-server-internal';
import { createVersionedRouterMock } from './versioned_router.mock';
export type RouterMock = jest.Mocked<IRouterWithVersion<any>>;
export type RouterMock = jest.Mocked<IRouter<any>>;
function createRouterMock({ routerPath = '' }: { routerPath?: string } = {}): RouterMock {
return {

View file

@ -13,7 +13,7 @@ const createMockVersionedRoute = (): VersionedRoute => {
return api;
};
export const createVersionedRouterMock = (): jest.Mocked<VersionedRouter> => ({
export const createVersionedRouterMock = (): jest.Mocked<VersionedRouter<any>> => ({
delete: jest.fn((_) => createMockVersionedRoute()),
get: jest.fn((_) => createMockVersionedRoute()),
patch: jest.fn((_) => createMockVersionedRoute()),

View file

@ -17,9 +17,9 @@ import type { PluginOpaqueId } from '@kbn/core-base-common';
import type { InternalExecutionContextSetup } from '@kbn/core-execution-context-server-internal';
import type {
RequestHandlerContextBase,
IRouter,
IContextContainer,
IContextProvider,
IRouter,
} from '@kbn/core-http-server';
import type {
InternalContextSetup,

View file

@ -9,7 +9,6 @@
import type { PluginOpaqueId } from '@kbn/core-base-common';
import type {
IRouter,
IRouterWithVersion,
RequestHandlerContextBase,
IContextProvider,
IAuthHeadersStorage,
@ -50,7 +49,7 @@ export interface InternalHttpServiceSetup
createRouter: <Context extends RequestHandlerContextBase = RequestHandlerContextBase>(
path: string,
plugin?: PluginOpaqueId
) => IRouterWithVersion<Context>;
) => IRouter<Context>;
registerRouterAfterListening: (router: IRouter) => void;
registerStaticDir: (path: string, dirPath: string) => void;
authRequestHeaders: IAuthHeadersStorage;

View file

@ -90,7 +90,6 @@ export type {
RouteValidatorFullConfig,
RouteValidatorOptions,
IRouter,
IRouterWithVersion,
RouteRegistrar,
RouterRoute,
IKibanaSocket,

View file

@ -61,7 +61,7 @@ export type {
RouteValidatorOptions,
} from './route_validator';
export { RouteValidationError } from './route_validator';
export type { IRouter, IRouterWithVersion, RouteRegistrar, RouterRoute } from './router';
export type { IRouter, RouteRegistrar, RouterRoute } from './router';
export type { IKibanaSocket } from './socket';
export type {
KibanaErrorResponseFactory,

View file

@ -86,11 +86,7 @@ export interface IRouter<Context extends RequestHandlerContextBase = RequestHand
* @internal
*/
getRoutes: () => RouterRoute[];
}
export interface IRouterWithVersion<
Context extends RequestHandlerContextBase = RequestHandlerContextBase
> extends IRouter<Context> {
/**
* An instance very similar to {@link IRouter} that can be used for versioning HTTP routes
* following the Elastic versioning specification.

View file

@ -10,7 +10,7 @@ import { shareReplay } from 'rxjs/operators';
import type { CoreContext } from '@kbn/core-base-server-internal';
import type { PluginOpaqueId } from '@kbn/core-base-common';
import type { NodeInfo } from '@kbn/core-node-server';
import type { IContextProvider, IRouterWithVersion } from '@kbn/core-http-server';
import type { IContextProvider, IRouter } from '@kbn/core-http-server';
import { PluginInitializerContext, PluginManifest } from '@kbn/core-plugins-server';
import { CorePreboot, CoreSetup, CoreStart } from '@kbn/core-lifecycle-server';
import type { RequestHandlerContext } from '@kbn/core-http-request-handler-context-server';
@ -220,7 +220,7 @@ export function createPluginSetupContext<TPlugin, TPluginDependencies>(
provider: IContextProvider<Context, ContextName>
) => deps.http.registerRouteHandlerContext(plugin.opaqueId, contextName, provider),
createRouter: <Context extends RequestHandlerContext = RequestHandlerContext>() =>
router as IRouterWithVersion<Context>,
router as IRouter<Context>,
resources: deps.httpResources.createRegistrar(router),
registerOnPreRouting: deps.http.registerOnPreRouting,
registerOnPreAuth: deps.http.registerOnPreAuth,

View file

@ -36,11 +36,11 @@ import type {
ExecutionContextStart,
} from '@kbn/core-execution-context-server';
import type {
IRouter,
RequestHandler,
KibanaResponseFactory,
RouteMethod,
HttpServiceSetup,
IRouter,
} from '@kbn/core-http-server';
import { configSchema as elasticsearchConfigSchema } from '@kbn/core-elasticsearch-server-internal';
import type { CapabilitiesSetup, CapabilitiesStart } from '@kbn/core-capabilities-server';

View file

@ -14,14 +14,14 @@ import { executionContextServiceMock } from '@kbn/core-execution-context-server-
import { contextServiceMock } from '@kbn/core-http-context-server-mocks';
import { createHttpServer } from '@kbn/core-http-server-mocks';
import type { HttpService } from '@kbn/core-http-server-internal';
import type { IRouterWithVersion } from '@kbn/core-http-server';
import type { IRouter } from '@kbn/core-http-server';
import type { CliArgs } from '@kbn/config';
let server: HttpService;
let logger: ReturnType<typeof loggingSystemMock.create>;
describe('Routing versioned requests', () => {
let router: IRouterWithVersion;
let router: IRouter;
let supertest: Supertest.SuperTest<Supertest.Test>;
async function setupServer(cliArgs: Partial<CliArgs> = {}) {

View file

@ -8,7 +8,7 @@
import { coreMock } from '@kbn/core/server/mocks';
import { ContentManagementPlugin } from './plugin';
import { IRouter } from '@kbn/core/server';
import type { IRouter } from '@kbn/core-http-server';
import type { ProcedureName } from '../common';
import { procedureNames } from '../common/rpc';
import { MSearchService } from './core/msearch';

View file

@ -15,6 +15,7 @@
"@kbn/core-saved-objects-api-server-mocks",
"@kbn/core-saved-objects-api-server",
"@kbn/saved-objects-settings",
"@kbn/core-http-server",
],
"exclude": [
"target/**/*",

View file

@ -89,6 +89,7 @@ export function makeRouterWithFleetAuthz<TContext extends FleetRequestHandlerCon
handleLegacyErrors: (handler) => router.handleLegacyErrors(handler),
getRoutes: () => router.getRoutes(),
routerPath: router.routerPath,
versioned: router.versioned,
};
return fleetAuthzRouter;

View file

@ -6,6 +6,7 @@
*/
import type { IRouter } from '@kbn/core/server';
import { createVersionedRouterMock } from '@kbn/core-http-router-server-mocks';
import { get } from 'lodash';
import { elasticsearchServiceMock } from '@kbn/core/server/mocks';
@ -104,4 +105,6 @@ export class RouterMock implements IRouter {
return handler(this.contextMock, mockRequest, responseMock);
}
versioned = createVersionedRouterMock();
}

View file

@ -31,6 +31,7 @@
"@kbn/core-execution-context-browser-mocks",
"@kbn/config-schema",
"@kbn/shared-ux-router",
"@kbn/core-http-router-server-mocks",
],
"exclude": [
"target/**/*",

View file

@ -9,6 +9,7 @@ import type { IRouter } from '@kbn/core/server';
import { get } from 'lodash';
import { elasticsearchServiceMock } from '@kbn/core/server/mocks';
import { createVersionedRouterMock } from '@kbn/core-http-router-server-mocks';
type RequestHandler = (...params: any[]) => any;
@ -104,4 +105,6 @@ export class RouterMock implements IRouter {
return handler(this.contextMock, mockRequest, responseMock);
}
versioned = createVersionedRouterMock();
}

View file

@ -30,6 +30,7 @@
"@kbn/analytics",
"@kbn/config-schema",
"@kbn/shared-ux-router",
"@kbn/core-http-router-server-mocks",
],
"exclude": [
"target/**/*",