Skip to content
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

Make core responsible for reading and merging of config files. Simplify legacy config adapter. #21956

Merged
merged 8 commits into from
Aug 28, 2018
1 change: 0 additions & 1 deletion src/cli/serve/__fixtures__/invalid_en_var_ref_config.yml

This file was deleted.

2 changes: 0 additions & 2 deletions src/cli/serve/__fixtures__/one.yml

This file was deleted.

2 changes: 0 additions & 2 deletions src/cli/serve/__fixtures__/two.yml

This file was deleted.

4 changes: 2 additions & 2 deletions src/cli/serve/integration_tests/reload_logging_config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { relative, resolve } from 'path';
import { safeDump } from 'js-yaml';
import es from 'event-stream';
import stripAnsi from 'strip-ansi';
import { readYamlConfig } from '../read_yaml_config';
import { getConfigFromFiles } from '../../../core/server/config';

const testConfigFile = follow('__fixtures__/reload_logging_config/kibana.test.yml');
const kibanaPath = follow('../../../../scripts/kibana.js');
Expand All @@ -33,7 +33,7 @@ function follow(file) {
}

function setLoggingJson(enabled) {
const conf = readYamlConfig(testConfigFile);
const conf = getConfigFromFiles([testConfigFile]);
conf.logging = conf.logging || {};
conf.logging.json = enabled;

Expand Down
63 changes: 0 additions & 63 deletions src/cli/serve/read_yaml_config.js

This file was deleted.

98 changes: 0 additions & 98 deletions src/cli/serve/read_yaml_config.test.js

This file was deleted.

6 changes: 3 additions & 3 deletions src/cli/serve/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { resolve } from 'path';
import { fromRoot } from '../../utils';
import { getConfig } from '../../server/path';
import { Config } from '../../server/config/config';
import { readYamlConfig } from './read_yaml_config';
import { getConfigFromFiles } from '../../core/server/config';
import { readKeystore } from './read_keystore';
import { transformDeprecations } from '../../server/config/transform_deprecations';

Expand Down Expand Up @@ -80,7 +80,7 @@ const pluginDirCollector = pathCollector();
const pluginPathCollector = pathCollector();

function readServerSettings(opts, extraCliOptions) {
const settings = readYamlConfig(opts.config);
const settings = getConfigFromFiles([].concat(opts.config || []));
const set = _.partial(_.set, settings);
const get = _.partial(_.get, settings);
const has = _.partial(_.has, settings);
Expand Down Expand Up @@ -256,7 +256,7 @@ export default function (program) {

// If new platform config subscription is active, let's notify it with the updated config.
if (kbnServer.newPlatform) {
kbnServer.newPlatform.updateConfig(config);
kbnServer.newPlatform.updateConfig(config.get());
}
});

Expand Down
7 changes: 7 additions & 0 deletions src/core/server/config/__tests__/__fixtures__/one.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
foo: 1
bar: true
xyz: ['1', '2']
abc:
def: test
qwe: 1
pom.bom: 3
7 changes: 7 additions & 0 deletions src/core/server/config/__tests__/__fixtures__/two.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
foo: 2
baz: bonkers
xyz: ['3', '4']
abc:
ghi: test2
qwe: 2
pom.mob: 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`different cwd() resolves relative files based on the cwd 1`] = `
Object {
"abc": Object {
"def": "test",
"qwe": 1,
},
"bar": true,
"foo": 1,
"pom": Object {
"bom": 3,
},
"xyz": Array [
"1",
"2",
],
}
`;

exports[`reads and merges multiple yaml files from file system and parses to json 1`] = `
Object {
"abc": Object {
"def": "test",
"ghi": "test2",
"qwe": 2,
},
"bar": true,
"baz": "bonkers",
"foo": 2,
"pom": Object {
"bom": 3,
"mob": 4,
},
"xyz": Array [
"3",
"4",
],
}
`;

exports[`reads single yaml from file system and parses to json 1`] = `
Object {
"pid": Object {
"enabled": true,
"file": "/var/run/kibana.pid",
},
}
`;

exports[`returns a deep object 1`] = `
Object {
"pid": Object {
"enabled": true,
"file": "/var/run/kibana.pid",
},
}
`;

exports[`should inject an environment variable value when setting a value with \${ENV_VAR} 1`] = `
Object {
"bar": "pre-val1-mid-val2-post",
"elasticsearch": Object {
"requestHeadersWhitelist": Array [
"val1",
"val2",
],
},
"foo": 1,
}
`;

exports[`should throw an exception when referenced environment variable in a config value does not exist 1`] = `"Unknown environment variable referenced in config : KBN_ENV_VAR1"`;
10 changes: 5 additions & 5 deletions src/core/server/config/__tests__/apply_argv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
* under the License.
*/

import { ObjectToRawConfigAdapter, RawConfig } from '..';
import { Config, ObjectToConfigAdapter } from '..';

/**
* Overrides some config values with ones from argv.
*
* @param config `RawConfig` instance to update config values for.
* @param argv Argv object with key/value pairs.
*/
export function overrideConfigWithArgv(config: RawConfig, argv: { [key: string]: any }) {
export function overrideConfigWithArgv(config: Config, argv: { [key: string]: any }) {
if (argv.port != null) {
config.set(['server', 'port'], argv.port);
}
Expand All @@ -42,7 +42,7 @@ test('port', () => {
port: 123,
};

const config = new ObjectToRawConfigAdapter({
const config = new ObjectToConfigAdapter({
server: { port: 456 },
});

Expand All @@ -56,7 +56,7 @@ test('host', () => {
host: 'example.org',
};

const config = new ObjectToRawConfigAdapter({
const config = new ObjectToConfigAdapter({
server: { host: 'org.example' },
});

Expand All @@ -70,7 +70,7 @@ test('ignores unknown', () => {
unknown: 'some value',
};

const config = new ObjectToRawConfigAdapter({});
const config = new ObjectToConfigAdapter({});
jest.spyOn(config, 'set');

overrideConfigWithArgv(config, argv);
Expand Down
Loading