Skip to content

Commit

Permalink
Make core responsible for reading and merging of config files. Simp…
Browse files Browse the repository at this point in the history
…lify legacy config adapter.
  • Loading branch information
azasypkin committed Aug 24, 2018
1 parent f1a4d6c commit 320b45b
Show file tree
Hide file tree
Showing 30 changed files with 642 additions and 710 deletions.
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"`;
Loading

0 comments on commit 320b45b

Please sign in to comment.