Skip to content

Commit

Permalink
Run SO migration after plugins setup phase. (#55012) (#55664)
Browse files Browse the repository at this point in the history
* change setClientFactory api to setClientFactoryProvider

* cleanup and add test for service

* change the signatures of SO start/setup

* fix registerCoreContext by accessing stored start contract reference

* move migration inside `start`

* adapt and add service tests

* add doc and export new types

* adapt plugins code

* update generated doc

* better core access

* address some review comments

* remove parametrized type from SavedObjectsClientFactory, use KibanaRequest instead

* add logs when starting and ending so migration

* fix KibanaRequest imports

* NITs and review comments

* fix alerting FTR test

* review comments
  • Loading branch information
pgayvallet authored Jan 23, 2020
1 parent 4bdb59a commit 76ae43f
Show file tree
Hide file tree
Showing 48 changed files with 913 additions and 661 deletions.
450 changes: 226 additions & 224 deletions docs/development/core/server/kibana-plugin-server.md

Large diffs are not rendered by default.

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

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

## SavedObjectsClientFactory type

Describes the factory used to create instances of the Saved Objects Client.

<b>Signature:</b>

```typescript
export declare type SavedObjectsClientFactory<Request = unknown> = ({ request, }: {
request: Request;
}) => SavedObjectsClientContract;
```
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

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

## SavedObjectsClientFactory type

Describes the factory used to create instances of the Saved Objects Client.

<b>Signature:</b>

```typescript
export declare type SavedObjectsClientFactory = ({ request, }: {
request: KibanaRequest;
}) => SavedObjectsClientContract;
```
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; [SavedObjectsClientFactoryProvider](./kibana-plugin-server.savedobjectsclientfactoryprovider.md)

## SavedObjectsClientFactoryProvider type

Provider to invoke to retrieve a [SavedObjectsClientFactory](./kibana-plugin-server.savedobjectsclientfactory.md)<!-- -->.

<b>Signature:</b>

```typescript
export declare type SavedObjectsClientFactoryProvider = (repositoryFactory: SavedObjectsRepositoryFactory) => SavedObjectsClientFactory;
```
Original file line number Diff line number Diff line change
@@ -1,13 +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; [SavedObjectsClientWrapperFactory](./kibana-plugin-server.savedobjectsclientwrapperfactory.md)

## SavedObjectsClientWrapperFactory type

Describes the factory used to create instances of Saved Objects Client Wrappers.

<b>Signature:</b>

```typescript
export declare type SavedObjectsClientWrapperFactory<Request = unknown> = (options: SavedObjectsClientWrapperOptions<Request>) => SavedObjectsClientContract;
```
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

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

## SavedObjectsClientWrapperFactory type

Describes the factory used to create instances of Saved Objects Client Wrappers.

<b>Signature:</b>

```typescript
export declare type SavedObjectsClientWrapperFactory = (options: SavedObjectsClientWrapperOptions) => SavedObjectsClientContract;
```
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

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

## SavedObjectsClientWrapperOptions interface

Options passed to each SavedObjectsClientWrapperFactory to aid in creating the wrapper instance.

<b>Signature:</b>

```typescript
export interface SavedObjectsClientWrapperOptions<Request = unknown>
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [client](./kibana-plugin-server.savedobjectsclientwrapperoptions.client.md) | <code>SavedObjectsClientContract</code> | |
| [request](./kibana-plugin-server.savedobjectsclientwrapperoptions.request.md) | <code>Request</code> | |

<!-- Do not edit this file. It is automatically generated by API Documenter. -->

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

## SavedObjectsClientWrapperOptions interface

Options passed to each SavedObjectsClientWrapperFactory to aid in creating the wrapper instance.

<b>Signature:</b>

```typescript
export interface SavedObjectsClientWrapperOptions
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [client](./kibana-plugin-server.savedobjectsclientwrapperoptions.client.md) | <code>SavedObjectsClientContract</code> | |
| [request](./kibana-plugin-server.savedobjectsclientwrapperoptions.request.md) | <code>KibanaRequest</code> | |

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

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [SavedObjectsClientWrapperOptions](./kibana-plugin-server.savedobjectsclientwrapperoptions.md) &gt; [request](./kibana-plugin-server.savedobjectsclientwrapperoptions.request.md)

## SavedObjectsClientWrapperOptions.request property

<b>Signature:</b>

```typescript
request: Request;
```
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [SavedObjectsClientWrapperOptions](./kibana-plugin-server.savedobjectsclientwrapperoptions.md) &gt; [request](./kibana-plugin-server.savedobjectsclientwrapperoptions.request.md)

## SavedObjectsClientWrapperOptions.request property

<b>Signature:</b>

```typescript
request: KibanaRequest;
```
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; [SavedObjectsRepositoryFactory](./kibana-plugin-server.savedobjectsrepositoryfactory.md) &gt; [createInternalRepository](./kibana-plugin-server.savedobjectsrepositoryfactory.createinternalrepository.md)

## SavedObjectsRepositoryFactory.createInternalRepository property

Creates a [Saved Objects repository](./kibana-plugin-server.isavedobjectsrepository.md) that uses the internal Kibana user for authenticating with Elasticsearch.

<b>Signature:</b>

```typescript
createInternalRepository: (extraTypes?: string[]) => ISavedObjectsRepository;
```
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; [SavedObjectsRepositoryFactory](./kibana-plugin-server.savedobjectsrepositoryfactory.md) &gt; [createScopedRepository](./kibana-plugin-server.savedobjectsrepositoryfactory.createscopedrepository.md)

## SavedObjectsRepositoryFactory.createScopedRepository property

Creates a [Saved Objects repository](./kibana-plugin-server.isavedobjectsrepository.md) that uses the credentials from the passed in request to authenticate with Elasticsearch.

<b>Signature:</b>

```typescript
createScopedRepository: (req: KibanaRequest, extraTypes?: string[]) => ISavedObjectsRepository;
```
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-server](./kibana-plugin-server.md) &gt; [SavedObjectsRepositoryFactory](./kibana-plugin-server.savedobjectsrepositoryfactory.md)

## SavedObjectsRepositoryFactory interface

Factory provided when invoking a [client factory provider](./kibana-plugin-server.savedobjectsclientfactoryprovider.md) See [SavedObjectsServiceSetup.setClientFactoryProvider](./kibana-plugin-server.savedobjectsservicesetup.setclientfactoryprovider.md)

<b>Signature:</b>

```typescript
export interface SavedObjectsRepositoryFactory
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [createInternalRepository](./kibana-plugin-server.savedobjectsrepositoryfactory.createinternalrepository.md) | <code>(extraTypes?: string[]) =&gt; ISavedObjectsRepository</code> | Creates a [Saved Objects repository](./kibana-plugin-server.isavedobjectsrepository.md) that uses the internal Kibana user for authenticating with Elasticsearch. |
| [createScopedRepository](./kibana-plugin-server.savedobjectsrepositoryfactory.createscopedrepository.md) | <code>(req: KibanaRequest, extraTypes?: string[]) =&gt; ISavedObjectsRepository</code> | Creates a [Saved Objects repository](./kibana-plugin-server.isavedobjectsrepository.md) that uses the credentials from the passed in request to authenticate with Elasticsearch. |

Original file line number Diff line number Diff line change
@@ -1,13 +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; [SavedObjectsServiceSetup](./kibana-plugin-server.savedobjectsservicesetup.md) &gt; [addClientWrapper](./kibana-plugin-server.savedobjectsservicesetup.addclientwrapper.md)

## SavedObjectsServiceSetup.addClientWrapper property

Add a client wrapper with the given priority.

<b>Signature:</b>

```typescript
addClientWrapper: (priority: number, id: string, factory: SavedObjectsClientWrapperFactory<KibanaRequest>) => void;
```
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [SavedObjectsServiceSetup](./kibana-plugin-server.savedobjectsservicesetup.md) &gt; [addClientWrapper](./kibana-plugin-server.savedobjectsservicesetup.addclientwrapper.md)

## SavedObjectsServiceSetup.addClientWrapper property

Add a [client wrapper factory](./kibana-plugin-server.savedobjectsclientwrapperfactory.md) with the given priority.

<b>Signature:</b>

```typescript
addClientWrapper: (priority: number, id: string, factory: SavedObjectsClientWrapperFactory) => void;
```

This file was deleted.

This file was deleted.

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

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

## SavedObjectsServiceSetup interface

Saved Objects is Kibana's data persisentence mechanism allowing plugins to use Elasticsearch for storing and querying state. The SavedObjectsServiceSetup API exposes methods for creating and registering Saved Object client wrappers.

<b>Signature:</b>

```typescript
export interface SavedObjectsServiceSetup
```

## Remarks

Note: The Saved Object setup API's should only be used for creating and registering client wrappers. Constructing a Saved Objects client or repository for use within your own plugin won't have any of the registered wrappers applied and is considered an anti-pattern. Use the Saved Objects client from the [SavedObjectsServiceStart\#getScopedClient](./kibana-plugin-server.savedobjectsservicestart.md) method or the [route handler context](./kibana-plugin-server.requesthandlercontext.md) instead.

When plugins access the Saved Objects client, a new client is created using the factory provided to `setClientFactory` and wrapped by all wrappers registered through `addClientWrapper`<!-- -->. To create a factory or wrapper, plugins will have to construct a Saved Objects client. First create a repository by calling `scopedRepository` or `internalRepository` and then use this repository as the argument to the [SavedObjectsClient](./kibana-plugin-server.savedobjectsclient.md) constructor.

## Example

import {<!-- -->SavedObjectsClient, CoreSetup<!-- -->} from 'src/core/server';

export class Plugin() { setup: (core: CoreSetup) =<!-- -->&gt; { core.savedObjects.setClientFactory((<!-- -->{<!-- -->request: KibanaRequest<!-- -->}<!-- -->) =<!-- -->&gt; { return new SavedObjectsClient(core.savedObjects.scopedRepository(request)); }<!-- -->) } }

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [addClientWrapper](./kibana-plugin-server.savedobjectsservicesetup.addclientwrapper.md) | <code>(priority: number, id: string, factory: SavedObjectsClientWrapperFactory&lt;KibanaRequest&gt;) =&gt; void</code> | Add a client wrapper with the given priority. |
| [createInternalRepository](./kibana-plugin-server.savedobjectsservicesetup.createinternalrepository.md) | <code>(extraTypes?: string[]) =&gt; ISavedObjectsRepository</code> | Creates a [Saved Objects repository](./kibana-plugin-server.isavedobjectsrepository.md) that uses the internal Kibana user for authenticating with Elasticsearch. |
| [createScopedRepository](./kibana-plugin-server.savedobjectsservicesetup.createscopedrepository.md) | <code>(req: KibanaRequest, extraTypes?: string[]) =&gt; ISavedObjectsRepository</code> | Creates a [Saved Objects repository](./kibana-plugin-server.isavedobjectsrepository.md) that uses the credentials from the passed in request to authenticate with Elasticsearch. |
| [setClientFactory](./kibana-plugin-server.savedobjectsservicesetup.setclientfactory.md) | <code>(customClientFactory: SavedObjectsClientFactory&lt;KibanaRequest&gt;) =&gt; void</code> | Set a default factory for creating Saved Objects clients. Only one client factory can be set, subsequent calls to this method will fail. |

<!-- Do not edit this file. It is automatically generated by API Documenter. -->

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

## SavedObjectsServiceSetup interface

Saved Objects is Kibana's data persistence mechanism allowing plugins to use Elasticsearch for storing and querying state. The SavedObjectsServiceSetup API exposes methods for creating and registering Saved Object client wrappers.

<b>Signature:</b>

```typescript
export interface SavedObjectsServiceSetup
```

## Remarks

Note: The Saved Object setup API's should only be used for creating and registering client wrappers. Constructing a Saved Objects client or repository for use within your own plugin won't have any of the registered wrappers applied and is considered an anti-pattern. Use the Saved Objects client from the [SavedObjectsServiceStart\#getScopedClient](./kibana-plugin-server.savedobjectsservicestart.md) method or the [route handler context](./kibana-plugin-server.requesthandlercontext.md) instead.

When plugins access the Saved Objects client, a new client is created using the factory provided to `setClientFactory` and wrapped by all wrappers registered through `addClientWrapper`<!-- -->. To create a factory or wrapper, plugins will have to construct a Saved Objects client. First create a repository by calling `scopedRepository` or `internalRepository` and then use this repository as the argument to the [SavedObjectsClient](./kibana-plugin-server.savedobjectsclient.md) constructor.

## Example

import { SavedObjectsClient, CoreSetup } from 'src/core/server';

export class Plugin() { setup: (core: CoreSetup) =<!-- -->&gt; { core.savedObjects.setClientFactory((<!-- -->{ request: KibanaRequest }<!-- -->) =<!-- -->&gt; { return new SavedObjectsClient(core.savedObjects.scopedRepository(request)); }<!-- -->) } }

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [addClientWrapper](./kibana-plugin-server.savedobjectsservicesetup.addclientwrapper.md) | <code>(priority: number, id: string, factory: SavedObjectsClientWrapperFactory) =&gt; void</code> | Add a [client wrapper factory](./kibana-plugin-server.savedobjectsclientwrapperfactory.md) with the given priority. |
| [setClientFactoryProvider](./kibana-plugin-server.savedobjectsservicesetup.setclientfactoryprovider.md) | <code>(clientFactoryProvider: SavedObjectsClientFactoryProvider) =&gt; void</code> | Set the default [factory provider](./kibana-plugin-server.savedobjectsclientfactoryprovider.md) for creating Saved Objects clients. Only one provider can be set, subsequent calls to this method will fail. |

This file was deleted.

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; [SavedObjectsServiceSetup](./kibana-plugin-server.savedobjectsservicesetup.md) &gt; [setClientFactoryProvider](./kibana-plugin-server.savedobjectsservicesetup.setclientfactoryprovider.md)

## SavedObjectsServiceSetup.setClientFactoryProvider property

Set the default [factory provider](./kibana-plugin-server.savedobjectsclientfactoryprovider.md) for creating Saved Objects clients. Only one provider can be set, subsequent calls to this method will fail.

<b>Signature:</b>

```typescript
setClientFactoryProvider: (clientFactoryProvider: SavedObjectsClientFactoryProvider) => void;
```
Loading

0 comments on commit 76ae43f

Please sign in to comment.