Skip to content

Commit

Permalink
[kbn-es] Support for passing regex value to ES (#42651)
Browse files Browse the repository at this point in the history
We test each value to determine if it's a file, in which case we move it to the
config directory. This is required to support things like SSL certificates which
are required to be within the ES directory. path.isAbsolute evalues to true for
a regular expression. In order to resolve this, we also verify that the file
exists.

Signed-off-by: Tyler Smalley <[email protected]>
  • Loading branch information
Tyler Smalley authored Aug 9, 2019
1 parent 6d4191c commit 35d33b7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/kbn-es/src/utils/extract_config_files.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ exports.extractConfigFiles = function extractConfigFiles(config, dest, options =
};

function isFile(dest = '') {
return path.isAbsolute(dest) && path.extname(dest).length > 0;
return path.isAbsolute(dest) && path.extname(dest).length > 0 && fs.existsSync(dest);
}

function copyFileSync(src, dest) {
Expand Down
16 changes: 16 additions & 0 deletions packages/kbn-es/src/utils/extract_config_files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,29 @@ test('copies file', () => {
expect(fs.writeFileSync.mock.calls[0][0]).toEqual('/es/config/foo.yml');
});

test('ignores file which does not exist', () => {
fs.existsSync = () => false;
extractConfigFiles(['path=/data/foo.yml'], '/es');

expect(fs.readFileSync).not.toHaveBeenCalled();
expect(fs.writeFileSync).not.toHaveBeenCalled();
});

test('ignores non-paths', () => {
const config = extractConfigFiles(['foo=bar', 'foo.bar=baz'], '/es');

expect(config).toEqual(['foo=bar', 'foo.bar=baz']);
});

test('keeps regular expressions intact', () => {
fs.existsSync = () => false;
const config = extractConfigFiles(['foo=bar', 'foo.bar=/https?://127.0.0.1(:[0-9]+)?/'], '/es');

expect(config).toEqual(['foo=bar', 'foo.bar=/https?://127.0.0.1(:[0-9]+)?/']);
});

test('ignores directories', () => {
fs.existsSync = () => true;
const config = extractConfigFiles(['path=/data/foo.yml', 'foo.bar=/data/bar'], '/es');

expect(config).toEqual(['path=foo.yml', 'foo.bar=/data/bar']);
Expand Down

0 comments on commit 35d33b7

Please sign in to comment.