From c530f7249ec862ad2500d668f00a3bb15db2101e Mon Sep 17 00:00:00 2001 From: restrry Date: Wed, 31 Jul 2019 11:44:36 +0200 Subject: [PATCH] revert PR 36804 --- .../kibana-plugin-server.coresetup.http.md | 1 - .../server/kibana-plugin-server.coresetup.md | 2 +- ...server.httpservicesetup.createnewserver.md | 11 ---- .../kibana-plugin-server.httpservicesetup.md | 11 +--- .../core/server/kibana-plugin-server.md | 2 +- src/core/server/http/http_service.mock.ts | 3 -- src/core/server/http/http_service.test.ts | 43 +--------------- src/core/server/http/http_service.ts | 50 ++----------------- src/core/server/index.ts | 1 - src/core/server/plugins/plugin_context.ts | 1 - src/core/server/server.api.md | 9 +--- 11 files changed, 10 insertions(+), 124 deletions(-) delete mode 100644 docs/development/core/server/kibana-plugin-server.httpservicesetup.createnewserver.md diff --git a/docs/development/core/server/kibana-plugin-server.coresetup.http.md b/docs/development/core/server/kibana-plugin-server.coresetup.http.md index c9206b7a7e711..e5347dd7c6625 100644 --- a/docs/development/core/server/kibana-plugin-server.coresetup.http.md +++ b/docs/development/core/server/kibana-plugin-server.coresetup.http.md @@ -13,7 +13,6 @@ http: { registerAuth: HttpServiceSetup['registerAuth']; registerOnPostAuth: HttpServiceSetup['registerOnPostAuth']; basePath: HttpServiceSetup['basePath']; - createNewServer: HttpServiceSetup['createNewServer']; isTlsEnabled: HttpServiceSetup['isTlsEnabled']; }; ``` diff --git a/docs/development/core/server/kibana-plugin-server.coresetup.md b/docs/development/core/server/kibana-plugin-server.coresetup.md index f4653d7f43579..38990f2797677 100644 --- a/docs/development/core/server/kibana-plugin-server.coresetup.md +++ b/docs/development/core/server/kibana-plugin-server.coresetup.md @@ -17,5 +17,5 @@ export interface CoreSetup | Property | Type | Description | | --- | --- | --- | | [elasticsearch](./kibana-plugin-server.coresetup.elasticsearch.md) | {
adminClient$: Observable<ClusterClient>;
dataClient$: Observable<ClusterClient>;
createClient: (type: string, clientConfig?: Partial<ElasticsearchClientConfig>) => ClusterClient;
} | | -| [http](./kibana-plugin-server.coresetup.http.md) | {
createCookieSessionStorageFactory: HttpServiceSetup['createCookieSessionStorageFactory'];
registerOnPreAuth: HttpServiceSetup['registerOnPreAuth'];
registerAuth: HttpServiceSetup['registerAuth'];
registerOnPostAuth: HttpServiceSetup['registerOnPostAuth'];
basePath: HttpServiceSetup['basePath'];
createNewServer: HttpServiceSetup['createNewServer'];
isTlsEnabled: HttpServiceSetup['isTlsEnabled'];
} | | +| [http](./kibana-plugin-server.coresetup.http.md) | {
createCookieSessionStorageFactory: HttpServiceSetup['createCookieSessionStorageFactory'];
registerOnPreAuth: HttpServiceSetup['registerOnPreAuth'];
registerAuth: HttpServiceSetup['registerAuth'];
registerOnPostAuth: HttpServiceSetup['registerOnPostAuth'];
basePath: HttpServiceSetup['basePath'];
isTlsEnabled: HttpServiceSetup['isTlsEnabled'];
} | | diff --git a/docs/development/core/server/kibana-plugin-server.httpservicesetup.createnewserver.md b/docs/development/core/server/kibana-plugin-server.httpservicesetup.createnewserver.md deleted file mode 100644 index e41684ea2b784..0000000000000 --- a/docs/development/core/server/kibana-plugin-server.httpservicesetup.createnewserver.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) > [createNewServer](./kibana-plugin-server.httpservicesetup.createnewserver.md) - -## HttpServiceSetup.createNewServer property - -Signature: - -```typescript -createNewServer: (cfg: Partial) => Promise; -``` diff --git a/docs/development/core/server/kibana-plugin-server.httpservicesetup.md b/docs/development/core/server/kibana-plugin-server.httpservicesetup.md index ec4a2537b8404..7e8f17510c8ee 100644 --- a/docs/development/core/server/kibana-plugin-server.httpservicesetup.md +++ b/docs/development/core/server/kibana-plugin-server.httpservicesetup.md @@ -2,18 +2,11 @@ [Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) -## HttpServiceSetup interface +## HttpServiceSetup type Signature: ```typescript -export interface HttpServiceSetup extends HttpServerSetup +export declare type HttpServiceSetup = HttpServerSetup; ``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [createNewServer](./kibana-plugin-server.httpservicesetup.createnewserver.md) | (cfg: Partial<HttpConfig>) => Promise<HttpServerSetup> | | - diff --git a/docs/development/core/server/kibana-plugin-server.md b/docs/development/core/server/kibana-plugin-server.md index bd4ef84723057..af98c207ba3c6 100644 --- a/docs/development/core/server/kibana-plugin-server.md +++ b/docs/development/core/server/kibana-plugin-server.md @@ -36,7 +36,6 @@ The plugin integrates with the core system via lifecycle events: `setup` | [ElasticsearchError](./kibana-plugin-server.elasticsearcherror.md) | | | [ElasticsearchServiceSetup](./kibana-plugin-server.elasticsearchservicesetup.md) | | | [FakeRequest](./kibana-plugin-server.fakerequest.md) | Fake request object created manually by Kibana plugins. | -| [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) | | | [HttpServiceStart](./kibana-plugin-server.httpservicestart.md) | | | [InternalCoreStart](./kibana-plugin-server.internalcorestart.md) | | | [KibanaRequestRoute](./kibana-plugin-server.kibanarequestroute.md) | Request specific route information exposed to a handler. | @@ -80,6 +79,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [ElasticsearchClientConfig](./kibana-plugin-server.elasticsearchclientconfig.md) | | | [GetAuthHeaders](./kibana-plugin-server.getauthheaders.md) | Get headers to authenticate a user against Elasticsearch. | | [Headers](./kibana-plugin-server.headers.md) | | +| [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) | | | [LegacyRequest](./kibana-plugin-server.legacyrequest.md) | Support Legacy platform request for the period of migration. | | [OnPostAuthHandler](./kibana-plugin-server.onpostauthhandler.md) | | | [OnPreAuthHandler](./kibana-plugin-server.onpreauthhandler.md) | | diff --git a/src/core/server/http/http_service.mock.ts b/src/core/server/http/http_service.mock.ts index 02103fc4acc84..b4e509c8a05a5 100644 --- a/src/core/server/http/http_service.mock.ts +++ b/src/core/server/http/http_service.mock.ts @@ -19,7 +19,6 @@ import { Server } from 'hapi'; import { HttpService } from './http_service'; -import { HttpServerSetup } from './http_server'; import { HttpServiceSetup } from './http_service'; import { OnPreAuthToolkit } from './lifecycle/on_pre_auth'; import { AuthToolkit } from './lifecycle/auth'; @@ -52,10 +51,8 @@ const createSetupContractMock = () => { isAuthenticated: jest.fn(), getAuthHeaders: jest.fn(), }, - createNewServer: jest.fn(), isTlsEnabled: false, }; - setupContract.createNewServer.mockResolvedValue({} as HttpServerSetup); setupContract.createCookieSessionStorageFactory.mockResolvedValue( sessionStorageMock.createFactory() ); diff --git a/src/core/server/http/http_service.test.ts b/src/core/server/http/http_service.test.ts index f003ba1314434..cde06dc31802f 100644 --- a/src/core/server/http/http_service.test.ts +++ b/src/core/server/http/http_service.test.ts @@ -133,46 +133,6 @@ test('spins up notReady server until started if configured with `autoListen:true expect(notReadyHapiServer.stop).toBeCalledTimes(1); }); -// this is an integration test! -test('creates and sets up second http server', async () => { - const configService = createConfigService({ - host: 'localhost', - port: 1234, - }); - const { HttpServer } = jest.requireActual('./http_server'); - - mockHttpServer.mockImplementation((...args) => new HttpServer(...args)); - - const service = new HttpService({ configService, env, logger }); - const serverSetup = await service.setup(); - const cfg = { port: 2345 }; - await serverSetup.createNewServer(cfg); - const server = await service.start(); - expect(server.isListening()).toBeTruthy(); - expect(server.isListening(cfg.port)).toBeTruthy(); - - try { - await serverSetup.createNewServer(cfg); - } catch (err) { - expect(err.message).toBe('port 2345 is already in use'); - } - - try { - await serverSetup.createNewServer({ port: 1234 }); - } catch (err) { - expect(err.message).toBe('port 1234 is already in use'); - } - - try { - await serverSetup.createNewServer({ host: 'example.org' }); - } catch (err) { - expect(err.message).toBe('port must be defined'); - } - await service.stop(); - expect(server.isListening()).toBeFalsy(); - expect(server.isListening(cfg.port)).toBeFalsy(); -}); - test('logs error if already set up', async () => { const configService = createConfigService(); @@ -273,8 +233,7 @@ test('returns http server contract on setup', async () => { })); const service = new HttpService({ configService, env, logger }); - const { createNewServer, ...setupHttpServer } = await service.setup(); - expect(createNewServer).toBeDefined(); + const setupHttpServer = await service.setup(); expect(setupHttpServer).toEqual(httpServer); }); diff --git a/src/core/server/http/http_service.ts b/src/core/server/http/http_service.ts index b06c690cf2621..cdfd2b09d75b1 100644 --- a/src/core/server/http/http_service.ts +++ b/src/core/server/http/http_service.ts @@ -25,14 +25,12 @@ import { LoggerFactory } from '../logging'; import { CoreService } from '../../types'; import { Logger } from '../logging'; import { CoreContext } from '../core_context'; -import { HttpConfig, HttpConfigType, config as httpConfig } from './http_config'; +import { HttpConfig, HttpConfigType } from './http_config'; import { HttpServer, HttpServerSetup } from './http_server'; import { HttpsRedirectServer } from './https_redirect_server'; /** @public */ -export interface HttpServiceSetup extends HttpServerSetup { - createNewServer: (cfg: Partial) => Promise; -} +export type HttpServiceSetup = HttpServerSetup; /** @public */ export interface HttpServiceStart { /** Indicates if http server is listening on a given port */ @@ -42,7 +40,6 @@ export interface HttpServiceStart { /** @internal */ export class HttpService implements CoreService { private readonly httpServer: HttpServer; - private readonly secondaryServers: Map = new Map(); private readonly httpsRedirectServer: HttpsRedirectServer; private readonly config$: Observable; private configSubscription?: Subscription; @@ -77,17 +74,11 @@ export class HttpService implements CoreService server.start())); } return { - isListening: (port: number = 0) => { - const server = this.secondaryServers.get(port); - if (server) return server.isListening(); - return this.httpServer.isListening(); - }, + isListening: () => this.httpServer.isListening(), }; } @@ -129,32 +115,6 @@ export class HttpService implements CoreService) { - const { port } = cfg; - const config = await this.config$.pipe(first()).toPromise(); - - if (!port) { - throw new Error('port must be defined'); - } - - // verify that main server and none of the secondary servers are already using this port - if (this.secondaryServers.has(port) || config.port === port) { - throw new Error(`port ${port} is already in use`); - } - - for (const [key, val] of Object.entries(cfg)) { - httpConfig.schema.validateKey(key, val); - } - - const baseConfig = await this.config$.pipe(first()).toPromise(); - const finalConfig = { ...baseConfig, ...cfg }; - - const httpServer = new HttpServer(this.logger, `secondary server:${port}`); - const httpSetup = await httpServer.setup(finalConfig); - this.secondaryServers.set(port, httpServer); - return httpSetup; - } - public async stop() { if (this.configSubscription === undefined) { return; @@ -168,8 +128,6 @@ export class HttpService implements CoreService s.stop())); - this.secondaryServers.clear(); } private async runNotReadyServer(config: HttpConfig) { diff --git a/src/core/server/index.ts b/src/core/server/index.ts index 2bbcaa58f6af5..2b215f0850038 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -135,7 +135,6 @@ export interface CoreSetup { registerAuth: HttpServiceSetup['registerAuth']; registerOnPostAuth: HttpServiceSetup['registerOnPostAuth']; basePath: HttpServiceSetup['basePath']; - createNewServer: HttpServiceSetup['createNewServer']; isTlsEnabled: HttpServiceSetup['isTlsEnabled']; }; } diff --git a/src/core/server/plugins/plugin_context.ts b/src/core/server/plugins/plugin_context.ts index fcc8a26f51b4b..8ebd3e6b3c8b2 100644 --- a/src/core/server/plugins/plugin_context.ts +++ b/src/core/server/plugins/plugin_context.ts @@ -123,7 +123,6 @@ export function createPluginSetupContext( registerAuth: deps.http.registerAuth, registerOnPostAuth: deps.http.registerOnPostAuth, basePath: deps.http.basePath, - createNewServer: deps.http.createNewServer, isTlsEnabled: deps.http.isTlsEnabled, }, }; diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 6ab535a66cb36..dbe5aff0043ea 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -5,7 +5,6 @@ ```ts import Boom from 'boom'; -import { ByteSizeValue } from '@kbn/config-schema'; import { CallCluster } from 'src/legacy/core_plugins/elasticsearch'; import { ConfigOptions } from 'elasticsearch'; import { Duration } from 'moment'; @@ -100,7 +99,6 @@ export interface CoreSetup { registerAuth: HttpServiceSetup['registerAuth']; registerOnPostAuth: HttpServiceSetup['registerOnPostAuth']; basePath: HttpServiceSetup['basePath']; - createNewServer: HttpServiceSetup['createNewServer']; isTlsEnabled: HttpServiceSetup['isTlsEnabled']; }; } @@ -170,12 +168,7 @@ export type Headers = Record; // Warning: (ae-forgotten-export) The symbol "HttpServerSetup" needs to be exported by the entry point index.d.ts // // @public (undocumented) -export interface HttpServiceSetup extends HttpServerSetup { - // Warning: (ae-forgotten-export) The symbol "HttpConfig" needs to be exported by the entry point index.d.ts - // - // (undocumented) - createNewServer: (cfg: Partial) => Promise; -} +export type HttpServiceSetup = HttpServerSetup; // @public (undocumented) export interface HttpServiceStart {