Skip to content

Commit

Permalink
Merge branch '7.x' into backport/7.x/pr-54306
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Feb 4, 2020
2 parents 2252bbc + 58536f8 commit c4111a4
Show file tree
Hide file tree
Showing 20 changed files with 186 additions and 3 deletions.
14 changes: 12 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,18 @@ module.exports = {
// '@typescript-eslint/unbound-method': 'error',
},
},
// {
// // will introduced after the other warns are fixed
// // typescript and javascript for front end react performance
// files: ['x-pack/legacy/plugins/siem/public/**/!(*.test).{js,ts,tsx}'],
// plugins: ['react-perf'],
// rules: {
// // 'react-perf/jsx-no-new-object-as-prop': 'error',
// // 'react-perf/jsx-no-new-array-as-prop': 'error',
// // 'react-perf/jsx-no-new-function-as-prop': 'error',
// // 'react/jsx-no-bind': 'error',
// },
// },
{
// typescript and javascript for front and back end
files: ['x-pack/legacy/plugins/siem/**/*.{js,ts,tsx}'],
Expand Down Expand Up @@ -751,8 +763,6 @@ module.exports = {
// will introduced after the other warns are fixed
// 'react/sort-comp': 'error',
'react/void-dom-elements-no-children': 'error',
// will introduced after the other warns are fixed
// 'react/jsx-no-bind': 'error',
'react/jsx-no-comment-textnodes': 'error',
'react/jsx-no-literals': 'error',
'react/jsx-no-target-blank': 'error',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [HttpServerInfo](./kibana-plugin-server.httpserverinfo.md) &gt; [host](./kibana-plugin-server.httpserverinfo.host.md)

## HttpServerInfo.host property

The hostname of the server

<b>Signature:</b>

```typescript
host: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [HttpServerInfo](./kibana-plugin-server.httpserverinfo.md)

## HttpServerInfo interface


<b>Signature:</b>

```typescript
export interface HttpServerInfo
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [host](./kibana-plugin-server.httpserverinfo.host.md) | <code>string</code> | The hostname of the server |
| [name](./kibana-plugin-server.httpserverinfo.name.md) | <code>string</code> | The name of the Kibana server |
| [port](./kibana-plugin-server.httpserverinfo.port.md) | <code>number</code> | The port the server is listening on |
| [protocol](./kibana-plugin-server.httpserverinfo.protocol.md) | <code>'http' &#124; 'https' &#124; 'socket'</code> | The protocol used by the server |

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [HttpServerInfo](./kibana-plugin-server.httpserverinfo.md) &gt; [name](./kibana-plugin-server.httpserverinfo.name.md)

## HttpServerInfo.name property

The name of the Kibana server

<b>Signature:</b>

```typescript
name: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [HttpServerInfo](./kibana-plugin-server.httpserverinfo.md) &gt; [port](./kibana-plugin-server.httpserverinfo.port.md)

## HttpServerInfo.port property

The port the server is listening on

<b>Signature:</b>

```typescript
port: number;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [HttpServerInfo](./kibana-plugin-server.httpserverinfo.md) &gt; [protocol](./kibana-plugin-server.httpserverinfo.protocol.md)

## HttpServerInfo.protocol property

The protocol used by the server

<b>Signature:</b>

```typescript
protocol: 'http' | 'https' | 'socket';
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) &gt; [getServerInfo](./kibana-plugin-server.httpservicesetup.getserverinfo.md)

## HttpServiceSetup.getServerInfo property

Provides common [information](./kibana-plugin-server.httpserverinfo.md) about the running http server.

<b>Signature:</b>

```typescript
getServerInfo: () => HttpServerInfo;
```
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ async (context, request, response) => {
| [createCookieSessionStorageFactory](./kibana-plugin-server.httpservicesetup.createcookiesessionstoragefactory.md) | <code>&lt;T&gt;(cookieOptions: SessionStorageCookieOptions&lt;T&gt;) =&gt; Promise&lt;SessionStorageFactory&lt;T&gt;&gt;</code> | Creates cookie based session storage factory [SessionStorageFactory](./kibana-plugin-server.sessionstoragefactory.md) |
| [createRouter](./kibana-plugin-server.httpservicesetup.createrouter.md) | <code>() =&gt; IRouter</code> | Provides ability to declare a handler function for a particular path and HTTP request method. |
| [csp](./kibana-plugin-server.httpservicesetup.csp.md) | <code>ICspConfig</code> | The CSP config used for Kibana. |
| [getServerInfo](./kibana-plugin-server.httpservicesetup.getserverinfo.md) | <code>() =&gt; HttpServerInfo</code> | Provides common [information](./kibana-plugin-server.httpserverinfo.md) about the running http server. |
| [isTlsEnabled](./kibana-plugin-server.httpservicesetup.istlsenabled.md) | <code>boolean</code> | Flag showing whether a server was configured to use TLS connection. |
| [registerAuth](./kibana-plugin-server.httpservicesetup.registerauth.md) | <code>(handler: AuthenticationHandler) =&gt; void</code> | To define custom authentication and/or authorization mechanism for incoming requests. |
| [registerOnPostAuth](./kibana-plugin-server.httpservicesetup.registeronpostauth.md) | <code>(handler: OnPostAuthHandler) =&gt; void</code> | To define custom logic to perform for incoming requests. |
Expand Down
1 change: 1 addition & 0 deletions docs/development/core/server/kibana-plugin-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [ErrorHttpResponseOptions](./kibana-plugin-server.errorhttpresponseoptions.md) | HTTP response parameters |
| [FakeRequest](./kibana-plugin-server.fakerequest.md) | Fake request object created manually by Kibana plugins. |
| [HttpResponseOptions](./kibana-plugin-server.httpresponseoptions.md) | HTTP response parameters |
| [HttpServerInfo](./kibana-plugin-server.httpserverinfo.md) | |
| [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) | Kibana HTTP Service provides own abstraction for work with HTTP stack. Plugins don't have direct access to <code>hapi</code> server and its primitives anymore. Moreover, plugins shouldn't rely on the fact that HTTP Service uses one or another library under the hood. This gives the platform flexibility to upgrade or changing our internal HTTP stack without breaking plugins. If the HTTP Service lacks functionality you need, we are happy to discuss and support your needs. |
| [HttpServiceStart](./kibana-plugin-server.httpservicestart.md) | |
| [IContextContainer](./kibana-plugin-server.icontextcontainer.md) | An object that handles registration of context providers and configuring handlers with context. |
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react": "^7.17.0",
"eslint-plugin-react-hooks": "^2.3.0",
"eslint-plugin-react-perf": "^3.2.3",
"exit-hook": "^2.2.0",
"faker": "1.1.0",
"fetch-mock": "^7.3.9",
Expand Down
34 changes: 34 additions & 0 deletions src/core/server/http/http_server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ beforeAll(() => {

beforeEach(() => {
config = {
name: 'kibana',
host: '127.0.0.1',
maxPayload: new ByteSizeValue(1024),
port: 10002,
Expand Down Expand Up @@ -1077,4 +1078,37 @@ describe('setup contract', () => {
expect(isTlsEnabled).toBe(false);
});
});

describe('#getServerInfo', () => {
it('returns correct information', async () => {
let { getServerInfo } = await server.setup(config);

expect(getServerInfo()).toEqual({
host: '127.0.0.1',
name: 'kibana',
port: 10002,
protocol: 'http',
});

({ getServerInfo } = await server.setup({
...config,
port: 12345,
name: 'custom-name',
host: 'localhost',
}));

expect(getServerInfo()).toEqual({
host: 'localhost',
name: 'custom-name',
port: 12345,
protocol: 'http',
});
});

it('returns correct protocol when ssl is enabled', async () => {
const { getServerInfo } = await server.setup(configWithSSL);

expect(getServerInfo().protocol).toEqual('https');
});
});
});
9 changes: 8 additions & 1 deletion src/core/server/http/http_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
import { IsAuthenticated, AuthStateStorage, GetAuthState } from './auth_state_storage';
import { AuthHeadersStorage, GetAuthHeaders } from './auth_headers_storage';
import { BasePath } from './base_path_service';
import { HttpServiceSetup } from './types';
import { HttpServiceSetup, HttpServerInfo } from './types';

/** @internal */
export interface HttpServerSetup {
Expand All @@ -58,6 +58,7 @@ export interface HttpServerSetup {
get: GetAuthState;
isAuthenticated: IsAuthenticated;
};
getServerInfo: () => HttpServerInfo;
}

/** @internal */
Expand Down Expand Up @@ -122,6 +123,12 @@ export class HttpServer {
isAuthenticated: this.authState.isAuthenticated,
},
getAuthHeaders: this.authRequestHeaders.get,
getServerInfo: () => ({
name: config.name,
host: config.host,
port: config.port,
protocol: this.server!.info.protocol,
}),
isTlsEnabled: config.ssl.enabled,
// Return server instance with the connection options so that we can properly
// bridge core and the "legacy" Kibana internally. Once this bridge isn't
Expand Down
7 changes: 7 additions & 0 deletions src/core/server/http/http_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,19 @@ const createSetupContractMock = () => {
auth: createAuthMock(),
getAuthHeaders: jest.fn(),
isTlsEnabled: false,
getServerInfo: jest.fn(),
};
setupContract.createCookieSessionStorageFactory.mockResolvedValue(
sessionStorageMock.createFactory()
);
setupContract.createRouter.mockImplementation(() => mockRouter.create());
setupContract.getAuthHeaders.mockReturnValue({ authorization: 'authorization-header' });
setupContract.getServerInfo.mockReturnValue({
host: 'localhost',
name: 'kibana',
port: 80,
protocol: 'http',
});
return setupContract;
};

Expand Down
17 changes: 17 additions & 0 deletions src/core/server/http/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ export interface HttpServiceSetup {
contextName: T,
provider: RequestHandlerContextProvider<T>
) => RequestHandlerContextContainer;

/**
* Provides common {@link HttpServerInfo | information} about the running http server.
*/
getServerInfo: () => HttpServerInfo;
}

/** @internal */
Expand All @@ -273,3 +278,15 @@ export interface HttpServiceStart {
/** Indicates if http server is listening on a given port */
isListening: (port: number) => boolean;
}

/** @public */
export interface HttpServerInfo {
/** The name of the Kibana server */
name: string;
/** The hostname of the server */
host: string;
/** The port the server is listening on */
port: number;
/** The protocol used by the server */
protocol: 'http' | 'https' | 'socket';
}
1 change: 1 addition & 0 deletions src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export {
GetAuthState,
HttpResponseOptions,
HttpResponsePayload,
HttpServerInfo,
HttpServiceSetup,
HttpServiceStart,
ErrorHttpResponseOptions,
Expand Down
1 change: 1 addition & 0 deletions src/core/server/legacy/legacy_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ export class LegacyService implements CoreService {
},
csp: setupDeps.core.http.csp,
isTlsEnabled: setupDeps.core.http.isTlsEnabled,
getServerInfo: setupDeps.core.http.getServerInfo,
},
savedObjects: {
setClientFactoryProvider: setupDeps.core.savedObjects.setClientFactoryProvider,
Expand Down
1 change: 1 addition & 0 deletions src/core/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function createCoreSetupMock() {
get: httpService.auth.get,
isAuthenticated: httpService.auth.isAuthenticated,
},
getServerInfo: httpService.getServerInfo,
};
httpMock.createRouter.mockImplementation(() => httpService.createRouter(''));

Expand Down
1 change: 1 addition & 0 deletions src/core/server/plugins/plugin_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export function createPluginSetupContext<TPlugin, TPluginDependencies>(
auth: { get: deps.http.auth.get, isAuthenticated: deps.http.auth.isAuthenticated },
csp: deps.http.csp,
isTlsEnabled: deps.http.isTlsEnabled,
getServerInfo: deps.http.getServerInfo,
},
savedObjects: {
setClientFactoryProvider: deps.savedObjects.setClientFactoryProvider,
Expand Down
9 changes: 9 additions & 0 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,14 @@ export interface HttpResponseOptions {
// @public
export type HttpResponsePayload = undefined | string | Record<string, any> | Buffer | Stream;

// @public (undocumented)
export interface HttpServerInfo {
host: string;
name: string;
port: number;
protocol: 'http' | 'https' | 'socket';
}

// @public
export interface HttpServiceSetup {
// (undocumented)
Expand All @@ -747,6 +755,7 @@ export interface HttpServiceSetup {
createCookieSessionStorageFactory: <T>(cookieOptions: SessionStorageCookieOptions<T>) => Promise<SessionStorageFactory<T>>;
createRouter: () => IRouter;
csp: ICspConfig;
getServerInfo: () => HttpServerInfo;
isTlsEnabled: boolean;
registerAuth: (handler: AuthenticationHandler) => void;
registerOnPostAuth: (handler: OnPostAuthHandler) => void;
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13277,6 +13277,11 @@ eslint-plugin-react-hooks@^2.3.0:
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-2.3.0.tgz#53e073961f1f5ccf8dd19558036c1fac8c29d99a"
integrity sha512-gLKCa52G4ee7uXzdLiorca7JIQZPPXRAQDXV83J4bUEeUuc5pIEyZYAZ45Xnxe5IuupxEqHS+hUhSLIimK1EMw==

eslint-plugin-react-perf@^3.2.3:
version "3.2.3"
resolved "https://registry.yarnpkg.com/eslint-plugin-react-perf/-/eslint-plugin-react-perf-3.2.3.tgz#e28d42d3a1f7ec3c8976a94735d8e17e7d652a45"
integrity sha512-bMiPt7uywwS1Ly25n752NE3Ei0XBZ3igplTkZ8GPJKyZVVUd3cHgzILGeQW2HIeAkzQ9zwk9HM6EcYDipdFk3Q==

eslint-plugin-react@^7.17.0:
version "7.17.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.17.0.tgz#a31b3e134b76046abe3cd278e7482bd35a1d12d7"
Expand Down

0 comments on commit c4111a4

Please sign in to comment.