Skip to content

Commit

Permalink
Migrate Capabilities to new platform (elastic#51438)
Browse files Browse the repository at this point in the history
* create service skeleton

* move registerCapabilitiesModifier to capabilities service and rename to registerCapabilitiesSwitcher

* starts to move capabilities logic to CapabilitiesService

* move capabilities route to service

* add initial integration test for capabilities route

* capabilitiesMixin now delegates to capability service

* use server-side Capabilities import in server code

* update generated doc

* remove capabilities from injectedMetadatas

* use applications sent from client instead of server-registered navLinks

* disable authRequired for capabilities route

* (temp) exposes two endpoints for capabilities

* Add fetch-mock on capabilities call for karma tests

* adapt xpack Capabilities test - first attempt

* adapt x-pack ui_capabilities test

* add '/status' to the list of anonymous pages

* Add documentation on Capabilities APIs

* move Capabilities to core/types

* update generated docs

* add service tests

* protecting resolveCapabilities against added/removed capabilities

* update generated docs

* adapt mocks due to rebase

* add forgotten exports

* improve capabilities routes registering

* name capabilities registering methods

* resolve conflicts due to merge

* address review issues

* add comment about reason for exposing two routes

* extract createHttpServer test helper

* fix merge conflicts

* improve documentation

* remove `/status` anon registration as now done in NP status plugin

* fix merge conflicts
  • Loading branch information
pgayvallet committed Dec 3, 2019
1 parent 542b94a commit f8358fa
Show file tree
Hide file tree
Showing 79 changed files with 3,357 additions and 2,423 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ module.exports = {
'!src/core/server/index.ts',
'!src/core/server/mocks.ts',
'!src/core/server/types.ts',
'!src/core/server/test_utils.ts',
// for absolute imports until fixed in
// https://github.com/elastic/kibana/issues/36096
'!src/core/server/types',
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; [Capabilities](./kibana-plugin-server.capabilities.md) &gt; [catalogue](./kibana-plugin-server.capabilities.catalogue.md)

## Capabilities.catalogue property

Catalogue capabilities. Catalogue entries drive the visibility of the Kibana homepage options.

<b>Signature:</b>

```typescript
catalogue: Record<string, boolean>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +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; [Capabilities](./kibana-plugin-server.capabilities.md) &gt; [management](./kibana-plugin-server.capabilities.management.md)

## Capabilities.management property

Management section capabilities.

<b>Signature:</b>

```typescript
management: {
[sectionId: string]: Record<string, boolean>;
};
```
22 changes: 22 additions & 0 deletions docs/development/core/server/kibana-plugin-server.capabilities.md
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; [Capabilities](./kibana-plugin-server.capabilities.md)

## Capabilities interface

The read-only set of capabilities available for the current UI session. Capabilities are simple key-value pairs of (string, boolean), where the string denotes the capability ID, and the boolean is a flag indicating if the capability is enabled or disabled.

<b>Signature:</b>

```typescript
export interface Capabilities
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [catalogue](./kibana-plugin-server.capabilities.catalogue.md) | <code>Record&lt;string, boolean&gt;</code> | Catalogue capabilities. Catalogue entries drive the visibility of the Kibana homepage options. |
| [management](./kibana-plugin-server.capabilities.management.md) | <code>{</code><br/><code> [sectionId: string]: Record&lt;string, boolean&gt;;</code><br/><code> }</code> | Management section capabilities. |
| [navLinks](./kibana-plugin-server.capabilities.navlinks.md) | <code>Record&lt;string, boolean&gt;</code> | Navigation link capabilities. |

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; [Capabilities](./kibana-plugin-server.capabilities.md) &gt; [navLinks](./kibana-plugin-server.capabilities.navlinks.md)

## Capabilities.navLinks property

Navigation link capabilities.

<b>Signature:</b>

```typescript
navLinks: Record<string, 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-server](./kibana-plugin-server.md) &gt; [CapabilitiesProvider](./kibana-plugin-server.capabilitiesprovider.md)

## CapabilitiesProvider type

See [CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md)

<b>Signature:</b>

```typescript
export declare type CapabilitiesProvider = () => Partial<Capabilities>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

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

## CapabilitiesSetup interface

APIs to manage the [Capabilities](./kibana-plugin-server.capabilities.md) that will be used by the application.

Plugins relying on capabilities to toggle some of their features should register them during the setup phase using the `registerProvider` method.

Plugins having the responsibility to restrict capabilities depending on a given context should register their capabilities switcher using the `registerSwitcher` method.

Refers to the methods documentation for complete description and examples.

<b>Signature:</b>

```typescript
export interface CapabilitiesSetup
```

## Methods

| Method | Description |
| --- | --- |
| [registerProvider(provider)](./kibana-plugin-server.capabilitiessetup.registerprovider.md) | Register a [CapabilitiesProvider](./kibana-plugin-server.capabilitiesprovider.md) to be used to provide [Capabilities](./kibana-plugin-server.capabilities.md) when resolving them. |
| [registerSwitcher(switcher)](./kibana-plugin-server.capabilitiessetup.registerswitcher.md) | Register a [CapabilitiesSwitcher](./kibana-plugin-server.capabilitiesswitcher.md) to be used to change the default state of the [Capabilities](./kibana-plugin-server.capabilities.md) entries when resolving them.<!-- -->A capabilities switcher can only change the state of existing capabilities. Capabilities added or removed when invoking the switcher will be ignored. |

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

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md) &gt; [registerProvider](./kibana-plugin-server.capabilitiessetup.registerprovider.md)

## CapabilitiesSetup.registerProvider() method

Register a [CapabilitiesProvider](./kibana-plugin-server.capabilitiesprovider.md) to be used to provide [Capabilities](./kibana-plugin-server.capabilities.md) when resolving them.

<b>Signature:</b>

```typescript
registerProvider(provider: CapabilitiesProvider): void;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| provider | <code>CapabilitiesProvider</code> | |

<b>Returns:</b>

`void`

## Example

How to register a plugin's capabilities during setup

```ts
// my-plugin/server/plugin.ts
public setup(core: CoreSetup, deps: {}) {
core.capabilities.registerProvider(() => {
return {
catalogue: {
myPlugin: true,
},
myPlugin: {
someFeature: true,
featureDisabledByDefault: false,
},
}
});
}

```

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

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md) &gt; [registerSwitcher](./kibana-plugin-server.capabilitiessetup.registerswitcher.md)

## CapabilitiesSetup.registerSwitcher() method

Register a [CapabilitiesSwitcher](./kibana-plugin-server.capabilitiesswitcher.md) to be used to change the default state of the [Capabilities](./kibana-plugin-server.capabilities.md) entries when resolving them.

A capabilities switcher can only change the state of existing capabilities. Capabilities added or removed when invoking the switcher will be ignored.

<b>Signature:</b>

```typescript
registerSwitcher(switcher: CapabilitiesSwitcher): void;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| switcher | <code>CapabilitiesSwitcher</code> | |

<b>Returns:</b>

`void`

## Example

How to restrict some capabilities

```ts
// my-plugin/server/plugin.ts
public setup(core: CoreSetup, deps: {}) {
core.capabilities.registerSwitcher((request, capabilities) => {
if(myPluginApi.shouldRestrictSomePluginBecauseOf(request)) {
return {
somePlugin: {
featureEnabledByDefault: false // `featureEnabledByDefault` will be disabled. All other capabilities will remain unchanged.
}
}
}
return {}; // All capabilities will remain unchanged.
});
}

```

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-server](./kibana-plugin-server.md) &gt; [CapabilitiesStart](./kibana-plugin-server.capabilitiesstart.md)

## CapabilitiesStart interface

APIs to access the application [Capabilities](./kibana-plugin-server.capabilities.md)<!-- -->.

<b>Signature:</b>

```typescript
export interface CapabilitiesStart
```

## Methods

| Method | Description |
| --- | --- |
| [resolveCapabilities(request)](./kibana-plugin-server.capabilitiesstart.resolvecapabilities.md) | Resolve the [Capabilities](./kibana-plugin-server.capabilities.md) to be used for given request |

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

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [CapabilitiesStart](./kibana-plugin-server.capabilitiesstart.md) &gt; [resolveCapabilities](./kibana-plugin-server.capabilitiesstart.resolvecapabilities.md)

## CapabilitiesStart.resolveCapabilities() method

Resolve the [Capabilities](./kibana-plugin-server.capabilities.md) to be used for given request

<b>Signature:</b>

```typescript
resolveCapabilities(request: KibanaRequest): Promise<Capabilities>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| request | <code>KibanaRequest</code> | |

<b>Returns:</b>

`Promise<Capabilities>`

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; [CapabilitiesSwitcher](./kibana-plugin-server.capabilitiesswitcher.md)

## CapabilitiesSwitcher type

See [CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md)

<b>Signature:</b>

```typescript
export declare type CapabilitiesSwitcher = (request: KibanaRequest, uiCapabilities: Capabilities) => Partial<Capabilities> | Promise<Partial<Capabilities>>;
```
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; [CoreSetup](./kibana-plugin-server.coresetup.md) &gt; [capabilities](./kibana-plugin-server.coresetup.capabilities.md)

## CoreSetup.capabilities property

[CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md)

<b>Signature:</b>

```typescript
capabilities: CapabilitiesSetup;
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface CoreSetup

| Property | Type | Description |
| --- | --- | --- |
| [capabilities](./kibana-plugin-server.coresetup.capabilities.md) | <code>CapabilitiesSetup</code> | [CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md) |
| [context](./kibana-plugin-server.coresetup.context.md) | <code>ContextSetup</code> | [ContextSetup](./kibana-plugin-server.contextsetup.md) |
| [elasticsearch](./kibana-plugin-server.coresetup.elasticsearch.md) | <code>ElasticsearchServiceSetup</code> | [ElasticsearchServiceSetup](./kibana-plugin-server.elasticsearchservicesetup.md) |
| [http](./kibana-plugin-server.coresetup.http.md) | <code>HttpServiceSetup</code> | [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) |
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; [CoreStart](./kibana-plugin-server.corestart.md) &gt; [capabilities](./kibana-plugin-server.corestart.capabilities.md)

## CoreStart.capabilities property

[CapabilitiesStart](./kibana-plugin-server.capabilitiesstart.md)

<b>Signature:</b>

```typescript
capabilities: CapabilitiesStart;
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ export interface CoreStart

| Property | Type | Description |
| --- | --- | --- |
| [capabilities](./kibana-plugin-server.corestart.capabilities.md) | <code>CapabilitiesStart</code> | [CapabilitiesStart](./kibana-plugin-server.capabilitiesstart.md) |
| [savedObjects](./kibana-plugin-server.corestart.savedobjects.md) | <code>SavedObjectsServiceStart</code> | [SavedObjectsServiceStart](./kibana-plugin-server.savedobjectsservicestart.md) |

5 changes: 5 additions & 0 deletions docs/development/core/server/kibana-plugin-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [AuthResultParams](./kibana-plugin-server.authresultparams.md) | Result of an incoming request authentication. |
| [AuthToolkit](./kibana-plugin-server.authtoolkit.md) | A tool set defining an outcome of Auth interceptor for incoming request. |
| [CallAPIOptions](./kibana-plugin-server.callapioptions.md) | The set of options that defines how API call should be made and result be processed. |
| [Capabilities](./kibana-plugin-server.capabilities.md) | The read-only set of capabilities available for the current UI session. Capabilities are simple key-value pairs of (string, boolean), where the string denotes the capability ID, and the boolean is a flag indicating if the capability is enabled or disabled. |
| [CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md) | APIs to manage the [Capabilities](./kibana-plugin-server.capabilities.md) that will be used by the application.<!-- -->Plugins relying on capabilities to toggle some of their features should register them during the setup phase using the <code>registerProvider</code> method.<!-- -->Plugins having the responsibility to restrict capabilities depending on a given context should register their capabilities switcher using the <code>registerSwitcher</code> method.<!-- -->Refers to the methods documentation for complete description and examples. |
| [CapabilitiesStart](./kibana-plugin-server.capabilitiesstart.md) | APIs to access the application [Capabilities](./kibana-plugin-server.capabilities.md)<!-- -->. |
| [ContextSetup](./kibana-plugin-server.contextsetup.md) | An object that handles registration of context providers and configuring handlers with context. |
| [CoreSetup](./kibana-plugin-server.coresetup.md) | Context passed to the plugins <code>setup</code> method. |
| [CoreStart](./kibana-plugin-server.corestart.md) | Context passed to the plugins <code>start</code> method. |
Expand Down Expand Up @@ -144,6 +147,8 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [AuthenticationHandler](./kibana-plugin-server.authenticationhandler.md) | See [AuthToolkit](./kibana-plugin-server.authtoolkit.md)<!-- -->. |
| [AuthHeaders](./kibana-plugin-server.authheaders.md) | Auth Headers map |
| [AuthResult](./kibana-plugin-server.authresult.md) | |
| [CapabilitiesProvider](./kibana-plugin-server.capabilitiesprovider.md) | See [CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md) |
| [CapabilitiesSwitcher](./kibana-plugin-server.capabilitiesswitcher.md) | See [CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md) |
| [ConfigPath](./kibana-plugin-server.configpath.md) | |
| [ElasticsearchClientConfig](./kibana-plugin-server.elasticsearchclientconfig.md) | |
| [GetAuthHeaders](./kibana-plugin-server.getauthheaders.md) | Get headers to authenticate a user against Elasticsearch. |
Expand Down
4 changes: 2 additions & 2 deletions src/core/public/application/application_service.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('#start()', () => {
expect(MockCapabilitiesService.start).toHaveBeenCalledWith({
apps: new Map([['app1', { id: 'app1' }]]),
legacyApps: new Map(),
injectedMetadata,
http,
});
});

Expand All @@ -153,7 +153,7 @@ describe('#start()', () => {
expect(MockCapabilitiesService.start).toHaveBeenCalledWith({
apps: new Map(),
legacyApps: new Map([['legacyApp1', { id: 'legacyApp1' }]]),
injectedMetadata,
http,
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/core/public/application/application_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ export class ApplicationService {
const legacyMode = injectedMetadata.getLegacyMode();
const currentAppId$ = new BehaviorSubject<string | undefined>(undefined);
const { availableApps, availableLegacyApps, capabilities } = await this.capabilities.start({
http,
apps: new Map([...this.apps$.value].map(([id, { app }]) => [id, app])),
legacyApps: this.legacyApps$.value,
injectedMetadata,
});

// Only setup history if we're not in legacy mode
Expand Down
Loading

0 comments on commit f8358fa

Please sign in to comment.