Skip to content

Commit

Permalink
[NP] Expose global config to the plugins (elastic#51478)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
afharo authored and timductive committed Dec 16, 2019
1 parent e2f6a48 commit 6621adb
Show file tree
Hide file tree
Showing 57 changed files with 491 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Search for objects
<b>Signature:</b>

```typescript
find: <T extends SavedObjectAttributes>(options: Pick<SavedObjectFindOptionsServer, "search" | "filter" | "type" | "fields" | "searchFields" | "defaultSearchOperator" | "hasReference" | "sortField" | "page" | "perPage">) => Promise<SavedObjectsFindResponsePublic<T>>;
find: <T extends SavedObjectAttributes>(options: Pick<SavedObjectFindOptionsServer, "search" | "filter" | "type" | "page" | "fields" | "searchFields" | "defaultSearchOperator" | "hasReference" | "sortField" | "perPage">) => Promise<SavedObjectsFindResponsePublic<T>>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export declare class SavedObjectsClient
| [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 |
| [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 |
| [delete](./kibana-plugin-public.savedobjectsclient.delete.md) | | <code>(type: string, id: string) =&gt; Promise&lt;{}&gt;</code> | Deletes an object |
| [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 |
| [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 |
| [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 |

## Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

```typescript
config: {
legacy: {
globalConfig$: Observable<SharedGlobalConfig>;
};
create: <T = ConfigSchema>() => Observable<T>;
createIfExists: <T = ConfigSchema>() => Observable<T | undefined>;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface PluginInitializerContext<ConfigSchema = unknown>

| Property | Type | Description |
| --- | --- | --- |
| [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> | |
| [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> | |
| [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> | |
| [logger](./kibana-plugin-server.plugininitializercontext.logger.md) | <code>LoggerFactory</code> | |
| [opaqueId](./kibana-plugin-server.plugininitializercontext.opaqueid.md) | <code>PluginOpaqueId</code> | |
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import _ from 'lodash';
import { pkg } from '../legacy/utils';
import { pkg } from '../core/server/utils';
import Command from './command';
import serveCommand from './serve/serve';

Expand Down
2 changes: 1 addition & 1 deletion src/cli/cluster/cluster_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export default class ClusterManager {

setupWatching(extraPaths, pluginInternalDirsIgnore) {
const chokidar = require('chokidar');
const { fromRoot } = require('../../legacy/utils');
const { fromRoot } = require('../../core/server/utils');

const watchPaths = [
fromRoot('src/core'),
Expand Down
3 changes: 2 additions & 1 deletion src/cli/cluster/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import _ from 'lodash';
import cluster from 'cluster';
import { EventEmitter } from 'events';

import { BinderFor, fromRoot } from '../../legacy/utils';
import { BinderFor } from '../../legacy/utils';
import { fromRoot } from '../../core/server/utils';

const cliPath = fromRoot('src/cli');
const baseArgs = _.difference(process.argv.slice(2), ['--no-watch']);
Expand Down
4 changes: 2 additions & 2 deletions src/cli/serve/read_keystore.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import path from 'path';
import { set } from 'lodash';

import { Keystore } from '../../legacy/server/keystore';
import { getData } from '../../legacy/server/path';
import { getDataPath } from '../../core/server/path';

export function readKeystore(dataPath = getData()) {
export function readKeystore(dataPath = getDataPath()) {
const keystore = new Keystore(path.join(dataPath, 'kibana.keystore'));
keystore.load();

Expand Down
7 changes: 4 additions & 3 deletions src/cli/serve/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import { statSync } from 'fs';
import { resolve } from 'path';
import url from 'url';

import { fromRoot, IS_KIBANA_DISTRIBUTABLE } from '../../legacy/utils';
import { getConfig } from '../../legacy/server/path';
import { IS_KIBANA_DISTRIBUTABLE } from '../../legacy/utils';
import { fromRoot } from '../../core/server/utils';
import { getConfigPath } from '../../core/server/path';
import { bootstrap } from '../../core/server';
import { readKeystore } from './read_keystore';

Expand Down Expand Up @@ -166,7 +167,7 @@ export default function (program) {
'-c, --config <path>',
'Path to the config file, use multiple --config args to include multiple config files',
configPathCollector,
[ getConfig() ]
[ getConfigPath() ]
)
.option('-p, --port <port>', 'The port to bind to', parseInt)
.option('-q, --quiet', 'Prevent all logging except errors')
Expand Down
6 changes: 3 additions & 3 deletions src/cli_keystore/cli_keystore.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

import { join } from 'path';

import { pkg } from '../legacy/utils';
import { pkg } from '../core/server/utils';
import Command from '../cli/command';
import { getData } from '../legacy/server/path';
import { getDataPath } from '../core/server/path';
import { Keystore } from '../legacy/server/keystore';

const path = join(getData(), 'kibana.keystore');
const path = join(getDataPath(), 'kibana.keystore');
const keystore = new Keystore(path);

import { createCli } from './create';
Expand Down
2 changes: 1 addition & 1 deletion src/cli_plugin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import _ from 'lodash';
import { pkg } from '../legacy/utils';
import { pkg } from '../core/server/utils';
import Command from '../cli/command';
import listCommand from './list';
import installCommand from './install';
Expand Down
6 changes: 3 additions & 3 deletions src/cli_plugin/install/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
* under the License.
*/

import { fromRoot, pkg } from '../../legacy/utils';
import { fromRoot, pkg } from '../../core/server/utils';
import install from './install';
import Logger from '../lib/logger';
import { getConfig } from '../../legacy/server/path';
import { getConfigPath } from '../../core/server/path';
import { parse, parseMilliseconds } from './settings';
import logWarnings from '../lib/log_warnings';
import { warnIfUsingPluginDirOption } from '../lib/warn_if_plugin_dir_option';
Expand Down Expand Up @@ -50,7 +50,7 @@ export default function pluginInstall(program) {
.option(
'-c, --config <path>',
'path to the config file',
getConfig()
getConfigPath()
)
.option(
'-t, --timeout <duration>',
Expand Down
2 changes: 1 addition & 1 deletion src/cli_plugin/install/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { fromRoot } from '../../legacy/utils';
import { fromRoot } from '../../core/server/utils';
import { resolve } from 'path';
import { parseMilliseconds, parse } from './settings';

Expand Down
2 changes: 1 addition & 1 deletion src/cli_plugin/list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { fromRoot } from '../../legacy/utils';
import { fromRoot } from '../../core/server/utils';
import list from './list';
import Logger from '../lib/logger';
import { parse } from './settings';
Expand Down
2 changes: 1 addition & 1 deletion src/cli_plugin/list/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { fromRoot } from '../../legacy/utils';
import { fromRoot } from '../../core/server/utils';
import { parse } from './settings';

describe('kibana cli', function () {
Expand Down
6 changes: 3 additions & 3 deletions src/cli_plugin/remove/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* under the License.
*/

import { fromRoot } from '../../legacy/utils';
import { fromRoot } from '../../core/server/utils';
import remove from './remove';
import Logger from '../lib/logger';
import { parse } from './settings';
import { getConfig } from '../../legacy/server/path';
import { getConfigPath } from '../../core/server/path';
import logWarnings from '../lib/log_warnings';
import { warnIfUsingPluginDirOption } from '../lib/warn_if_plugin_dir_option';

Expand Down Expand Up @@ -50,7 +50,7 @@ export default function pluginRemove(program) {
.option(
'-c, --config <path>',
'path to the config file',
getConfig()
getConfigPath()
)
.option(
'-d, --plugin-dir <path>',
Expand Down
2 changes: 1 addition & 1 deletion src/cli_plugin/remove/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { fromRoot } from '../../legacy/utils';
import { fromRoot } from '../../core/server/utils';
import { parse } from './settings';

describe('kibana cli', function () {
Expand Down
Loading

0 comments on commit 6621adb

Please sign in to comment.