Skip to content

Commit bd3857a

Browse files
authored
[NP] Expose global config to the plugins (#51478)
* [NP] Expose global config to the plugins * globalConfig in Plugin context: expose read-only methods only * SharedGlobalConfig rework + Moving pkg, fromRoot & path utils from legacy to NP * Updated API docs * Fix test references to the moved utils * Replace zip with combineLatest * Change tests to describe/it + remove "(deprecated)" from the test description * Moving path files to a folder + exposing the config path in the contract * deepFreeze the globalConfig in the pluginContext * Fix types in tests with new path.config * Move fromRoot and package_json utils to core/server/utils * Rename globalConfig to legacy.globalConfig$ * path.config renamed to path.configDir (not renaming path.data because it might be a breaking change) * Change configDir in mocker as well * Fix test after config renamed to configDir * Fix API docs conflicts * Rename the path properties when exposing them * path.configDir removed from the path config-schema * Remove path.configDir. It is already in env.configs * Add Migration documentation and examples * Fix 'kibana/server' imports in the MIGRATION docs
1 parent f21d5ad commit bd3857a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+491
-145
lines changed

docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ Search for objects
99
<b>Signature:</b>
1010

1111
```typescript
12-
find: <T extends SavedObjectAttributes>(options: Pick<SavedObjectFindOptionsServer, "search" | "filter" | "type" | "fields" | "searchFields" | "defaultSearchOperator" | "hasReference" | "sortField" | "page" | "perPage">) => Promise<SavedObjectsFindResponsePublic<T>>;
12+
find: <T extends SavedObjectAttributes>(options: Pick<SavedObjectFindOptionsServer, "search" | "filter" | "type" | "page" | "fields" | "searchFields" | "defaultSearchOperator" | "hasReference" | "sortField" | "perPage">) => Promise<SavedObjectsFindResponsePublic<T>>;
1313
```

docs/development/core/public/kibana-plugin-public.savedobjectsclient.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export declare class SavedObjectsClient
2020
| [bulkGet](./kibana-plugin-public.savedobjectsclient.bulkget.md) | | <code>(objects?: {</code><br/><code> id: string;</code><br/><code> type: string;</code><br/><code> }[]) =&gt; Promise&lt;SavedObjectsBatchResponse&lt;SavedObjectAttributes&gt;&gt;</code> | Returns an array of objects by id |
2121
| [create](./kibana-plugin-public.savedobjectsclient.create.md) | | <code>&lt;T extends SavedObjectAttributes&gt;(type: string, attributes: T, options?: SavedObjectsCreateOptions) =&gt; Promise&lt;SimpleSavedObject&lt;T&gt;&gt;</code> | Persists an object |
2222
| [delete](./kibana-plugin-public.savedobjectsclient.delete.md) | | <code>(type: string, id: string) =&gt; Promise&lt;{}&gt;</code> | Deletes an object |
23-
| [find](./kibana-plugin-public.savedobjectsclient.find.md) | | <code>&lt;T extends SavedObjectAttributes&gt;(options: Pick&lt;SavedObjectFindOptionsServer, &quot;search&quot; &#124; &quot;filter&quot; &#124; &quot;type&quot; &#124; &quot;fields&quot; &#124; &quot;searchFields&quot; &#124; &quot;defaultSearchOperator&quot; &#124; &quot;hasReference&quot; &#124; &quot;sortField&quot; &#124; &quot;page&quot; &#124; &quot;perPage&quot;&gt;) =&gt; Promise&lt;SavedObjectsFindResponsePublic&lt;T&gt;&gt;</code> | Search for objects |
23+
| [find](./kibana-plugin-public.savedobjectsclient.find.md) | | <code>&lt;T extends SavedObjectAttributes&gt;(options: Pick&lt;SavedObjectFindOptionsServer, &quot;search&quot; &#124; &quot;filter&quot; &#124; &quot;type&quot; &#124; &quot;page&quot; &#124; &quot;fields&quot; &#124; &quot;searchFields&quot; &#124; &quot;defaultSearchOperator&quot; &#124; &quot;hasReference&quot; &#124; &quot;sortField&quot; &#124; &quot;perPage&quot;&gt;) =&gt; Promise&lt;SavedObjectsFindResponsePublic&lt;T&gt;&gt;</code> | Search for objects |
2424
| [get](./kibana-plugin-public.savedobjectsclient.get.md) | | <code>&lt;T extends SavedObjectAttributes&gt;(type: string, id: string) =&gt; Promise&lt;SimpleSavedObject&lt;T&gt;&gt;</code> | Fetches a single object |
2525

2626
## Methods

docs/development/core/server/kibana-plugin-server.plugininitializercontext.config.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
```typescript
1010
config: {
11+
legacy: {
12+
globalConfig$: Observable<SharedGlobalConfig>;
13+
};
1114
create: <T = ConfigSchema>() => Observable<T>;
1215
createIfExists: <T = ConfigSchema>() => Observable<T | undefined>;
1316
};

docs/development/core/server/kibana-plugin-server.plugininitializercontext.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface PluginInitializerContext<ConfigSchema = unknown>
1616

1717
| Property | Type | Description |
1818
| --- | --- | --- |
19-
| [config](./kibana-plugin-server.plugininitializercontext.config.md) | <code>{</code><br/><code> create: &lt;T = ConfigSchema&gt;() =&gt; Observable&lt;T&gt;;</code><br/><code> createIfExists: &lt;T = ConfigSchema&gt;() =&gt; Observable&lt;T &#124; undefined&gt;;</code><br/><code> }</code> | |
19+
| [config](./kibana-plugin-server.plugininitializercontext.config.md) | <code>{</code><br/><code> legacy: {</code><br/><code> globalConfig$: Observable&lt;SharedGlobalConfig&gt;;</code><br/><code> };</code><br/><code> create: &lt;T = ConfigSchema&gt;() =&gt; Observable&lt;T&gt;;</code><br/><code> createIfExists: &lt;T = ConfigSchema&gt;() =&gt; Observable&lt;T &#124; undefined&gt;;</code><br/><code> }</code> | |
2020
| [env](./kibana-plugin-server.plugininitializercontext.env.md) | <code>{</code><br/><code> mode: EnvironmentMode;</code><br/><code> packageInfo: Readonly&lt;PackageInfo&gt;;</code><br/><code> }</code> | |
2121
| [logger](./kibana-plugin-server.plugininitializercontext.logger.md) | <code>LoggerFactory</code> | |
2222
| [opaqueId](./kibana-plugin-server.plugininitializercontext.opaqueid.md) | <code>PluginOpaqueId</code> | |

src/cli/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
import _ from 'lodash';
21-
import { pkg } from '../legacy/utils';
21+
import { pkg } from '../core/server/utils';
2222
import Command from './command';
2323
import serveCommand from './serve/serve';
2424

src/cli/cluster/cluster_manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export default class ClusterManager {
167167

168168
setupWatching(extraPaths, pluginInternalDirsIgnore) {
169169
const chokidar = require('chokidar');
170-
const { fromRoot } = require('../../legacy/utils');
170+
const { fromRoot } = require('../../core/server/utils');
171171

172172
const watchPaths = [
173173
fromRoot('src/core'),

src/cli/cluster/worker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import _ from 'lodash';
2121
import cluster from 'cluster';
2222
import { EventEmitter } from 'events';
2323

24-
import { BinderFor, fromRoot } from '../../legacy/utils';
24+
import { BinderFor } from '../../legacy/utils';
25+
import { fromRoot } from '../../core/server/utils';
2526

2627
const cliPath = fromRoot('src/cli');
2728
const baseArgs = _.difference(process.argv.slice(2), ['--no-watch']);

src/cli/serve/read_keystore.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import path from 'path';
2121
import { set } from 'lodash';
2222

2323
import { Keystore } from '../../legacy/server/keystore';
24-
import { getData } from '../../legacy/server/path';
24+
import { getDataPath } from '../../core/server/path';
2525

26-
export function readKeystore(dataPath = getData()) {
26+
export function readKeystore(dataPath = getDataPath()) {
2727
const keystore = new Keystore(path.join(dataPath, 'kibana.keystore'));
2828
keystore.load();
2929

src/cli/serve/serve.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ import { statSync } from 'fs';
2222
import { resolve } from 'path';
2323
import url from 'url';
2424

25-
import { fromRoot, IS_KIBANA_DISTRIBUTABLE } from '../../legacy/utils';
26-
import { getConfig } from '../../legacy/server/path';
25+
import { IS_KIBANA_DISTRIBUTABLE } from '../../legacy/utils';
26+
import { fromRoot } from '../../core/server/utils';
27+
import { getConfigPath } from '../../core/server/path';
2728
import { bootstrap } from '../../core/server';
2829
import { readKeystore } from './read_keystore';
2930

@@ -166,7 +167,7 @@ export default function (program) {
166167
'-c, --config <path>',
167168
'Path to the config file, use multiple --config args to include multiple config files',
168169
configPathCollector,
169-
[ getConfig() ]
170+
[ getConfigPath() ]
170171
)
171172
.option('-p, --port <port>', 'The port to bind to', parseInt)
172173
.option('-q, --quiet', 'Prevent all logging except errors')

src/cli_keystore/cli_keystore.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
import { join } from 'path';
2121

22-
import { pkg } from '../legacy/utils';
22+
import { pkg } from '../core/server/utils';
2323
import Command from '../cli/command';
24-
import { getData } from '../legacy/server/path';
24+
import { getDataPath } from '../core/server/path';
2525
import { Keystore } from '../legacy/server/keystore';
2626

27-
const path = join(getData(), 'kibana.keystore');
27+
const path = join(getDataPath(), 'kibana.keystore');
2828
const keystore = new Keystore(path);
2929

3030
import { createCli } from './create';

0 commit comments

Comments
 (0)