Skip to content

Commit

Permalink
Introduce preboot lifecycle stage (#103636)
Browse files Browse the repository at this point in the history
  • Loading branch information
azasypkin authored Jul 20, 2021
1 parent a34a15e commit 237256a
Show file tree
Hide file tree
Showing 194 changed files with 5,848 additions and 1,192 deletions.
10 changes: 6 additions & 4 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,14 @@
#CC# /x-pack/plugins/translations/ @elastic/kibana-localization @elastic/kibana-core

# Security
/src/core/server/csp/ @elastic/kibana-security @elastic/kibana-core
/src/core/server/csp/ @elastic/kibana-security @elastic/kibana-core
/src/plugins/security_oss/ @elastic/kibana-security
/src/plugins/spaces_oss/ @elastic/kibana-security
/src/plugins/user_setup/ @elastic/kibana-security
/test/security_functional/ @elastic/kibana-security
/x-pack/plugins/spaces/ @elastic/kibana-security
/x-pack/plugins/encrypted_saved_objects/ @elastic/kibana-security
/x-pack/plugins/security/ @elastic/kibana-security
/x-pack/plugins/spaces/ @elastic/kibana-security
/x-pack/plugins/encrypted_saved_objects/ @elastic/kibana-security
/x-pack/plugins/security/ @elastic/kibana-security
/x-pack/test/api_integration/apis/security/ @elastic/kibana-security
/x-pack/test/ui_capabilities/ @elastic/kibana-security
/x-pack/test/encrypted_saved_objects_api_integration/ @elastic/kibana-security
Expand All @@ -265,6 +265,8 @@
/x-pack/test/security_functional/ @elastic/kibana-security
/x-pack/test/spaces_api_integration/ @elastic/kibana-security
/x-pack/test/saved_object_api_integration/ @elastic/kibana-security
/src/core/server/csp/ @elastic/kibana-security @elastic/kibana-core
/examples/preboot_example/ @elastic/kibana-security @elastic/kibana-core
#CC# /x-pack/plugins/security/ @elastic/kibana-security

# Kibana Alerting Services
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-core-server](./kibana-plugin-core-server.md) &gt; [CorePreboot](./kibana-plugin-core-server.corepreboot.md) &gt; [elasticsearch](./kibana-plugin-core-server.corepreboot.elasticsearch.md)

## CorePreboot.elasticsearch property

[ElasticsearchServicePreboot](./kibana-plugin-core-server.elasticsearchservicepreboot.md)

<b>Signature:</b>

```typescript
elasticsearch: ElasticsearchServicePreboot;
```
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-core-server](./kibana-plugin-core-server.md) &gt; [CorePreboot](./kibana-plugin-core-server.corepreboot.md) &gt; [http](./kibana-plugin-core-server.corepreboot.http.md)

## CorePreboot.http property

[HttpServicePreboot](./kibana-plugin-core-server.httpservicepreboot.md)

<b>Signature:</b>

```typescript
http: HttpServicePreboot;
```
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-core-server](./kibana-plugin-core-server.md) &gt; [CorePreboot](./kibana-plugin-core-server.corepreboot.md)

## CorePreboot interface

Context passed to the `setup` method of `preboot` plugins.

<b>Signature:</b>

```typescript
export interface CorePreboot
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [elasticsearch](./kibana-plugin-core-server.corepreboot.elasticsearch.md) | <code>ElasticsearchServicePreboot</code> | [ElasticsearchServicePreboot](./kibana-plugin-core-server.elasticsearchservicepreboot.md) |
| [http](./kibana-plugin-core-server.corepreboot.http.md) | <code>HttpServicePreboot</code> | [HttpServicePreboot](./kibana-plugin-core-server.httpservicepreboot.md) |
| [preboot](./kibana-plugin-core-server.corepreboot.preboot.md) | <code>PrebootServicePreboot</code> | [PrebootServicePreboot](./kibana-plugin-core-server.prebootservicepreboot.md) |

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-core-server](./kibana-plugin-core-server.md) &gt; [CorePreboot](./kibana-plugin-core-server.corepreboot.md) &gt; [preboot](./kibana-plugin-core-server.corepreboot.preboot.md)

## CorePreboot.preboot property

[PrebootServicePreboot](./kibana-plugin-core-server.prebootservicepreboot.md)

<b>Signature:</b>

```typescript
preboot: PrebootServicePreboot;
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## CoreSetup interface

Context passed to the plugins `setup` method.
Context passed to the `setup` method of `standard` plugins.

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export interface DiscoveredPlugin
| [optionalPlugins](./kibana-plugin-core-server.discoveredplugin.optionalplugins.md) | <code>readonly PluginName[]</code> | An optional list of the other plugins that if installed and enabled \*\*may be\*\* leveraged by this plugin for some additional functionality but otherwise are not required for this plugin to work properly. |
| [requiredBundles](./kibana-plugin-core-server.discoveredplugin.requiredbundles.md) | <code>readonly PluginName[]</code> | List of plugin ids that this plugin's UI code imports modules from that are not in <code>requiredPlugins</code>. |
| [requiredPlugins](./kibana-plugin-core-server.discoveredplugin.requiredplugins.md) | <code>readonly PluginName[]</code> | An optional list of the other plugins that \*\*must be\*\* installed and enabled for this plugin to function properly. |
| [type](./kibana-plugin-core-server.discoveredplugin.type.md) | <code>PluginType</code> | Type of the plugin, defaults to <code>standard</code>. |

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-core-server](./kibana-plugin-core-server.md) &gt; [DiscoveredPlugin](./kibana-plugin-core-server.discoveredplugin.md) &gt; [type](./kibana-plugin-core-server.discoveredplugin.type.md)

## DiscoveredPlugin.type property

Type of the plugin, defaults to `standard`<!-- -->.

<b>Signature:</b>

```typescript
readonly type: PluginType;
```
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-core-server](./kibana-plugin-core-server.md) &gt; [ElasticsearchConfigPreboot](./kibana-plugin-core-server.elasticsearchconfigpreboot.md) &gt; [credentialsSpecified](./kibana-plugin-core-server.elasticsearchconfigpreboot.credentialsspecified.md)

## ElasticsearchConfigPreboot.credentialsSpecified property

Indicates whether Elasticsearch configuration includes credentials (`username`<!-- -->, `password` or `serviceAccountToken`<!-- -->).

<b>Signature:</b>

```typescript
readonly credentialsSpecified: boolean;
```
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-core-server](./kibana-plugin-core-server.md) &gt; [ElasticsearchConfigPreboot](./kibana-plugin-core-server.elasticsearchconfigpreboot.md) &gt; [hosts](./kibana-plugin-core-server.elasticsearchconfigpreboot.hosts.md)

## ElasticsearchConfigPreboot.hosts property

Hosts that the client will connect to. If sniffing is enabled, this list will be used as seeds to discover the rest of your cluster.

<b>Signature:</b>

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

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [ElasticsearchConfigPreboot](./kibana-plugin-core-server.elasticsearchconfigpreboot.md)

## ElasticsearchConfigPreboot interface

A limited set of Elasticsearch configuration entries exposed to the `preboot` plugins at `setup`<!-- -->.

<b>Signature:</b>

```typescript
export interface ElasticsearchConfigPreboot
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [credentialsSpecified](./kibana-plugin-core-server.elasticsearchconfigpreboot.credentialsspecified.md) | <code>boolean</code> | Indicates whether Elasticsearch configuration includes credentials (<code>username</code>, <code>password</code> or <code>serviceAccountToken</code>). |
| [hosts](./kibana-plugin-core-server.elasticsearchconfigpreboot.hosts.md) | <code>string[]</code> | Hosts that the client will connect to. If sniffing is enabled, this list will be used as seeds to discover the rest of your cluster. |

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-core-server](./kibana-plugin-core-server.md) &gt; [ElasticsearchServicePreboot](./kibana-plugin-core-server.elasticsearchservicepreboot.md) &gt; [config](./kibana-plugin-core-server.elasticsearchservicepreboot.config.md)

## ElasticsearchServicePreboot.config property

A limited set of Elasticsearch configuration entries.

<b>Signature:</b>

```typescript
readonly config: Readonly<ElasticsearchConfigPreboot>;
```

## Example


```js
const { hosts, credentialsSpecified } = core.elasticsearch.config;

```

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

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [ElasticsearchServicePreboot](./kibana-plugin-core-server.elasticsearchservicepreboot.md) &gt; [createClient](./kibana-plugin-core-server.elasticsearchservicepreboot.createclient.md)

## ElasticsearchServicePreboot.createClient property

Create application specific Elasticsearch cluster API client with customized config. See [IClusterClient](./kibana-plugin-core-server.iclusterclient.md)<!-- -->.

<b>Signature:</b>

```typescript
readonly createClient: (type: string, clientConfig?: Partial<ElasticsearchClientConfig>) => ICustomClusterClient;
```

## Example


```js
const client = elasticsearch.createClient('my-app-name', config);
const data = await client.asInternalUser.search();

```

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

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [ElasticsearchServicePreboot](./kibana-plugin-core-server.elasticsearchservicepreboot.md)

## ElasticsearchServicePreboot interface


<b>Signature:</b>

```typescript
export interface ElasticsearchServicePreboot
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [config](./kibana-plugin-core-server.elasticsearchservicepreboot.config.md) | <code>Readonly&lt;ElasticsearchConfigPreboot&gt;</code> | A limited set of Elasticsearch configuration entries. |
| [createClient](./kibana-plugin-core-server.elasticsearchservicepreboot.createclient.md) | <code>(type: string, clientConfig?: Partial&lt;ElasticsearchClientConfig&gt;) =&gt; ICustomClusterClient</code> | Create application specific Elasticsearch cluster API client with customized config. See [IClusterClient](./kibana-plugin-core-server.iclusterclient.md)<!-- -->. |

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-core-server](./kibana-plugin-core-server.md) &gt; [HttpServicePreboot](./kibana-plugin-core-server.httpservicepreboot.md) &gt; [basePath](./kibana-plugin-core-server.httpservicepreboot.basepath.md)

## HttpServicePreboot.basePath property

Access or manipulate the Kibana base path See [IBasePath](./kibana-plugin-core-server.ibasepath.md)<!-- -->.

<b>Signature:</b>

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

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [HttpServicePreboot](./kibana-plugin-core-server.httpservicepreboot.md)

## HttpServicePreboot interface

Kibana HTTP Service provides an abstraction to work with the HTTP stack at the `preboot` stage. This functionality allows Kibana to serve user requests even before Kibana becomes fully operational. Only Core and `preboot` plugins can define HTTP routes at this stage.

<b>Signature:</b>

```typescript
export interface HttpServicePreboot
```

## Example

To handle an incoming request in your preboot plugin you should: - Use `@kbn/config-schema` package to create a schema to validate the request `params`<!-- -->, `query`<!-- -->, and `body`<!-- -->. Every incoming request will be validated against the created schema. If validation failed, the request is rejected with `400` status and `Bad request` error without calling the route's handler. To opt out of validating the request, specify `false`<!-- -->.

```ts
import { schema, TypeOf } from '@kbn/config-schema';
const validate = {
params: schema.object({
id: schema.string(),
}),
};

```
- Declare a function to respond to incoming request. The function will receive `request` object containing request details: url, headers, matched route, as well as validated `params`<!-- -->, `query`<!-- -->, `body`<!-- -->. And `response` object instructing HTTP server to create HTTP response with information sent back to the client as the response body, headers, and HTTP status. Any exception raised during the handler call will generate `500 Server error` response and log error details for further investigation. See below for returning custom error responses.

```ts
const handler = async (context: RequestHandlerContext, request: KibanaRequest, response: ResponseFactory) => {
const data = await findObject(request.params.id);
// creates a command to respond with 'not found' error
if (!data) {
return response.notFound();
}
// creates a command to send found data to the client and set response headers
return response.ok({
body: data,
headers: { 'content-type': 'application/json' }
});
}

```
\* - Acquire `preboot` [IRouter](./kibana-plugin-core-server.irouter.md) instance and register route handler for GET request to 'path/<!-- -->{<!-- -->id<!-- -->}<!-- -->' path.

```ts
import { schema, TypeOf } from '@kbn/config-schema';

const validate = {
params: schema.object({
id: schema.string(),
}),
};

httpPreboot.registerRoutes('my-plugin', (router) => {
router.get({ path: 'path/{id}', validate }, async (context, request, response) => {
const data = await findObject(request.params.id);
if (!data) {
return response.notFound();
}
return response.ok({
body: data,
headers: { 'content-type': 'application/json' }
});
});
});

```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [basePath](./kibana-plugin-core-server.httpservicepreboot.basepath.md) | <code>IBasePath</code> | Access or manipulate the Kibana base path See [IBasePath](./kibana-plugin-core-server.ibasepath.md)<!-- -->. |

## Methods

| Method | Description |
| --- | --- |
| [registerRoutes(path, callback)](./kibana-plugin-core-server.httpservicepreboot.registerroutes.md) | Provides ability to acquire <code>preboot</code> [IRouter](./kibana-plugin-core-server.irouter.md) instance for a particular top-level path and register handler functions for any number of nested routes. |

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

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [HttpServicePreboot](./kibana-plugin-core-server.httpservicepreboot.md) &gt; [registerRoutes](./kibana-plugin-core-server.httpservicepreboot.registerroutes.md)

## HttpServicePreboot.registerRoutes() method

Provides ability to acquire `preboot` [IRouter](./kibana-plugin-core-server.irouter.md) instance for a particular top-level path and register handler functions for any number of nested routes.

<b>Signature:</b>

```typescript
registerRoutes(path: string, callback: (router: IRouter) => void): void;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| path | <code>string</code> | |
| callback | <code>(router: IRouter) =&gt; void</code> | |

<b>Returns:</b>

`void`

## Remarks

Each route can have only one handler function, which is executed when the route is matched. See the [IRouter](./kibana-plugin-core-server.irouter.md) documentation for more information.

## Example


```ts
registerRoutes('my-plugin', (router) => {
// handler is called when '/my-plugin/path' resource is requested with `GET` method
router.get({ path: '/path', validate: false }, (context, req, res) => res.ok({ content: 'ok' }));
});

```

Loading

0 comments on commit 237256a

Please sign in to comment.