-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose whitelisted config values to client-side plugin #50641
Merged
pgayvallet
merged 20 commits into
elastic:master
from
pgayvallet:kbn-41990-client-config-values
Nov 21, 2019
Merged
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
fb2b28c
introduce PluginConfigDescriptor type
pgayvallet daf09e3
inject client plugin configs in injectedMetadata
pgayvallet ac9d19b
expose client config in PluginInitializerContext
pgayvallet 99790dd
add example implementation in testbed
pgayvallet 0df8a6f
update generated doc
pgayvallet db25021
Merge remote-tracking branch 'upstream/master' into kbn-41990-client-…
pgayvallet 9b93964
only generates ui config entry for plugins exposing properties to client
pgayvallet a87b7b0
separate plugin configs from plugins
pgayvallet b6d9a83
restructure plugin services tests
pgayvallet 95f5fc4
fix test/mocks due to plugin configs api changes
pgayvallet e083125
add unit tests
pgayvallet c3c926a
update migration guide
pgayvallet 93ba773
update tsdoc
pgayvallet bd1e3bc
fix typecheck
pgayvallet 1fe445f
use sync getter for config on client side instead of observable
pgayvallet 5e34e91
change type of exposeToBrowser prop
pgayvallet ebfc428
Merge remote-tracking branch 'upstream/master' into kbn-41990-client-…
pgayvallet b147018
updates generated doc
pgayvallet cfa27e8
fix doc and address nits
pgayvallet 24575b3
Merge remote-tracking branch 'upstream/master' into kbn-41990-client-…
pgayvallet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
...development/core/public/kibana-plugin-public.plugininitializercontext.config.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) > [kibana-plugin-public](./kibana-plugin-public.md) > [PluginInitializerContext](./kibana-plugin-public.plugininitializercontext.md) > [config](./kibana-plugin-public.plugininitializercontext.config.md) | ||
|
||
## PluginInitializerContext.config property | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
readonly config: { | ||
create: <T = ConfigSchema>() => Observable<T>; | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...ment/core/server/kibana-plugin-server.pluginconfigdescriptor.exposetobrowser.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) > [kibana-plugin-server](./kibana-plugin-server.md) > [PluginConfigDescriptor](./kibana-plugin-server.pluginconfigdescriptor.md) > [exposeToBrowser](./kibana-plugin-server.pluginconfigdescriptor.exposetobrowser.md) | ||
|
||
## PluginConfigDescriptor.exposeToBrowser property | ||
|
||
List of configuration properties that will be available on the client-side plugin. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
exposeToBrowser?: Array<keyof T>; | ||
``` |
43 changes: 43 additions & 0 deletions
43
docs/development/core/server/kibana-plugin-server.pluginconfigdescriptor.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [PluginConfigDescriptor](./kibana-plugin-server.pluginconfigdescriptor.md) | ||
|
||
## PluginConfigDescriptor interface | ||
|
||
Describes a plugin configuration schema and capabilities. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export interface PluginConfigDescriptor<T = any> | ||
``` | ||
|
||
## Properties | ||
|
||
| Property | Type | Description | | ||
| --- | --- | --- | | ||
| [exposeToBrowser](./kibana-plugin-server.pluginconfigdescriptor.exposetobrowser.md) | <code>Array<keyof T></code> | List of configuration properties that will be available on the client-side plugin. | | ||
| [schema](./kibana-plugin-server.pluginconfigdescriptor.schema.md) | <code>PluginConfigSchema<T></code> | Schema to use to validate the plugin configuration.[PluginConfigSchema](./kibana-plugin-server.pluginconfigschema.md) | | ||
|
||
## Example | ||
|
||
|
||
```typescript | ||
// my_plugin/server/index.ts | ||
import { schema, TypeOf } from '@kbn/config-schema'; | ||
import { PluginConfigDescriptor } from 'kibana/server'; | ||
|
||
const configSchema = schema.object({ | ||
secret: schema.string({ defaultValue: 'Only on server' }), | ||
uiProp: schema.string({ defaultValue: 'Accessible from client' }), | ||
}); | ||
|
||
type ConfigType = TypeOf<typeof configSchema>; | ||
|
||
export const config: PluginConfigDescriptor<ConfigType> = { | ||
exposeToBrowser: ['uiProp'], | ||
schema: configSchema, | ||
}; | ||
|
||
``` | ||
|
15 changes: 15 additions & 0 deletions
15
docs/development/core/server/kibana-plugin-server.pluginconfigdescriptor.schema.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) > [kibana-plugin-server](./kibana-plugin-server.md) > [PluginConfigDescriptor](./kibana-plugin-server.pluginconfigdescriptor.md) > [schema](./kibana-plugin-server.pluginconfigdescriptor.schema.md) | ||
|
||
## PluginConfigDescriptor.schema property | ||
|
||
Schema to use to validate the plugin configuration. | ||
|
||
[PluginConfigSchema](./kibana-plugin-server.pluginconfigschema.md) | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
schema: PluginConfigSchema<T>; | ||
``` |
13 changes: 13 additions & 0 deletions
13
docs/development/core/server/kibana-plugin-server.pluginconfigschema.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) > [kibana-plugin-server](./kibana-plugin-server.md) > [PluginConfigSchema](./kibana-plugin-server.pluginconfigschema.md) | ||
|
||
## PluginConfigSchema type | ||
|
||
Dedicated type for plugin configuration schema. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export declare type PluginConfigSchema<T = unknown> = Type<T>; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...lopment/core/server/kibana-plugin-server.pluginsservicesetup.uipluginconfigs.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [PluginsServiceSetup](./kibana-plugin-server.pluginsservicesetup.md) > [uiPluginConfigs](./kibana-plugin-server.pluginsservicesetup.uipluginconfigs.md) | ||
|
||
## PluginsServiceSetup.uiPluginConfigs property | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
uiPluginConfigs: Map<PluginName, Observable<unknown>>; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ | |
*/ | ||
|
||
import { omit } from 'lodash'; | ||
|
||
import { DiscoveredPlugin } from '../../server'; | ||
import { PluginOpaqueId, PackageInfo, EnvironmentMode } from '../../server/types'; | ||
import { CoreContext } from '../core_system'; | ||
|
@@ -31,7 +30,7 @@ import { CoreSetup, CoreStart } from '../'; | |
* | ||
* @public | ||
*/ | ||
export interface PluginInitializerContext { | ||
export interface PluginInitializerContext<ConfigSchema = unknown> { | ||
/** | ||
* A symbol used to identify this plugin in the system. Needed when registering handlers or context providers. | ||
*/ | ||
|
@@ -40,24 +39,37 @@ export interface PluginInitializerContext { | |
mode: Readonly<EnvironmentMode>; | ||
packageInfo: Readonly<PackageInfo>; | ||
}; | ||
readonly config: { | ||
get: <T = ConfigSchema>() => T; | ||
}; | ||
} | ||
|
||
/** | ||
* Provides a plugin-specific context passed to the plugin's construtor. This is currently | ||
* empty but should provide static services in the future, such as config and logging. | ||
* | ||
* @param coreContext | ||
* @param pluginManinfest | ||
* @param opaqueId | ||
* @param pluginManifest | ||
* @param pluginConfig | ||
* @internal | ||
*/ | ||
export function createPluginInitializerContext( | ||
coreContext: CoreContext, | ||
opaqueId: PluginOpaqueId, | ||
pluginManifest: DiscoveredPlugin | ||
pluginManifest: DiscoveredPlugin, | ||
pluginConfig: { | ||
[key: string]: unknown; | ||
} | ||
): PluginInitializerContext { | ||
return { | ||
opaqueId, | ||
env: coreContext.env, | ||
config: { | ||
get<T>() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return (pluginConfig as unknown) as T; | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
outdated docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, outdated tsdoc, thanks