mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
parent
42597aadeb
commit
c90f663309
11 changed files with 10 additions and 124 deletions
|
@ -13,7 +13,6 @@ http: {
|
|||
registerAuth: HttpServiceSetup['registerAuth'];
|
||||
registerOnPostAuth: HttpServiceSetup['registerOnPostAuth'];
|
||||
basePath: HttpServiceSetup['basePath'];
|
||||
createNewServer: HttpServiceSetup['createNewServer'];
|
||||
isTlsEnabled: HttpServiceSetup['isTlsEnabled'];
|
||||
};
|
||||
```
|
||||
|
|
|
@ -17,5 +17,5 @@ export interface CoreSetup
|
|||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [elasticsearch](./kibana-plugin-server.coresetup.elasticsearch.md) | <code>{</code><br/><code> adminClient$: Observable<ClusterClient>;</code><br/><code> dataClient$: Observable<ClusterClient>;</code><br/><code> createClient: (type: string, clientConfig?: Partial<ElasticsearchClientConfig>) => ClusterClient;</code><br/><code> }</code> | |
|
||||
| [http](./kibana-plugin-server.coresetup.http.md) | <code>{</code><br/><code> createCookieSessionStorageFactory: HttpServiceSetup['createCookieSessionStorageFactory'];</code><br/><code> registerOnPreAuth: HttpServiceSetup['registerOnPreAuth'];</code><br/><code> registerAuth: HttpServiceSetup['registerAuth'];</code><br/><code> registerOnPostAuth: HttpServiceSetup['registerOnPostAuth'];</code><br/><code> basePath: HttpServiceSetup['basePath'];</code><br/><code> createNewServer: HttpServiceSetup['createNewServer'];</code><br/><code> isTlsEnabled: HttpServiceSetup['isTlsEnabled'];</code><br/><code> }</code> | |
|
||||
| [http](./kibana-plugin-server.coresetup.http.md) | <code>{</code><br/><code> createCookieSessionStorageFactory: HttpServiceSetup['createCookieSessionStorageFactory'];</code><br/><code> registerOnPreAuth: HttpServiceSetup['registerOnPreAuth'];</code><br/><code> registerAuth: HttpServiceSetup['registerAuth'];</code><br/><code> registerOnPostAuth: HttpServiceSetup['registerOnPostAuth'];</code><br/><code> basePath: HttpServiceSetup['basePath'];</code><br/><code> isTlsEnabled: HttpServiceSetup['isTlsEnabled'];</code><br/><code> }</code> | |
|
||||
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[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
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
createNewServer: (cfg: Partial<HttpConfig>) => Promise<HttpServerSetup>;
|
||||
```
|
|
@ -2,18 +2,11 @@
|
|||
|
||||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md)
|
||||
|
||||
## HttpServiceSetup interface
|
||||
## HttpServiceSetup type
|
||||
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export interface HttpServiceSetup extends HttpServerSetup
|
||||
export declare type HttpServiceSetup = HttpServerSetup;
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [createNewServer](./kibana-plugin-server.httpservicesetup.createnewserver.md) | <code>(cfg: Partial<HttpConfig>) => Promise<HttpServerSetup></code> | |
|
||||
|
||||
|
|
|
@ -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. |
|
||||
|
@ -91,6 +90,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) | |
|
||||
|
|
|
@ -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()
|
||||
);
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
||||
|
|
|
@ -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<HttpConfig>) => Promise<HttpServerSetup>;
|
||||
}
|
||||
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<HttpServiceSetup, HttpServiceStart> {
|
||||
private readonly httpServer: HttpServer;
|
||||
private readonly secondaryServers: Map<number, HttpServer> = new Map();
|
||||
private readonly httpsRedirectServer: HttpsRedirectServer;
|
||||
private readonly config$: Observable<HttpConfig>;
|
||||
private configSubscription?: Subscription;
|
||||
|
@ -77,17 +74,11 @@ export class HttpService implements CoreService<HttpServiceSetup, HttpServiceSta
|
|||
|
||||
const config = await this.config$.pipe(first()).toPromise();
|
||||
|
||||
const httpSetup = (this.httpServer.setup(config) || {}) as HttpServiceSetup;
|
||||
const setup = {
|
||||
...httpSetup,
|
||||
createNewServer: this.createServer.bind(this),
|
||||
};
|
||||
|
||||
if (this.shouldListen(config)) {
|
||||
await this.runNotReadyServer(config);
|
||||
}
|
||||
|
||||
return setup;
|
||||
return this.httpServer.setup(config);
|
||||
}
|
||||
|
||||
public async start() {
|
||||
|
@ -105,15 +96,10 @@ export class HttpService implements CoreService<HttpServiceSetup, HttpServiceSta
|
|||
}
|
||||
|
||||
await this.httpServer.start();
|
||||
await Promise.all([...this.secondaryServers.values()].map(server => 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<HttpServiceSetup, HttpServiceSta
|
|||
return !this.coreContext.env.isDevClusterMaster && config.autoListen;
|
||||
}
|
||||
|
||||
private async createServer(cfg: Partial<HttpConfig>) {
|
||||
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<HttpServiceSetup, HttpServiceSta
|
|||
}
|
||||
await this.httpServer.stop();
|
||||
await this.httpsRedirectServer.stop();
|
||||
await Promise.all([...this.secondaryServers.values()].map(s => s.stop()));
|
||||
this.secondaryServers.clear();
|
||||
}
|
||||
|
||||
private async runNotReadyServer(config: HttpConfig) {
|
||||
|
|
|
@ -146,7 +146,6 @@ export interface CoreSetup {
|
|||
registerAuth: HttpServiceSetup['registerAuth'];
|
||||
registerOnPostAuth: HttpServiceSetup['registerOnPostAuth'];
|
||||
basePath: HttpServiceSetup['basePath'];
|
||||
createNewServer: HttpServiceSetup['createNewServer'];
|
||||
isTlsEnabled: HttpServiceSetup['isTlsEnabled'];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -123,7 +123,6 @@ export function createPluginSetupContext<TPlugin, TPluginDependencies>(
|
|||
registerAuth: deps.http.registerAuth,
|
||||
registerOnPostAuth: deps.http.registerOnPostAuth,
|
||||
basePath: deps.http.basePath,
|
||||
createNewServer: deps.http.createNewServer,
|
||||
isTlsEnabled: deps.http.isTlsEnabled,
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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';
|
||||
|
@ -101,7 +100,6 @@ export interface CoreSetup {
|
|||
registerAuth: HttpServiceSetup['registerAuth'];
|
||||
registerOnPostAuth: HttpServiceSetup['registerOnPostAuth'];
|
||||
basePath: HttpServiceSetup['basePath'];
|
||||
createNewServer: HttpServiceSetup['createNewServer'];
|
||||
isTlsEnabled: HttpServiceSetup['isTlsEnabled'];
|
||||
};
|
||||
}
|
||||
|
@ -171,12 +169,7 @@ export type Headers = Record<string, string | string[] | undefined>;
|
|||
// 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<HttpConfig>) => Promise<HttpServerSetup>;
|
||||
}
|
||||
export type HttpServiceSetup = HttpServerSetup;
|
||||
|
||||
// @public (undocumented)
|
||||
export interface HttpServiceStart {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue