Skip to content

Commit

Permalink
Merge branch 'master' into index_pattern_class_refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Sep 2, 2020
2 parents 584fb2e + 6f94bf7 commit 1981fb6
Show file tree
Hide file tree
Showing 316 changed files with 6,444 additions and 3,446 deletions.
4 changes: 2 additions & 2 deletions docs/settings/alert-action-settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ You can configure the following settings in the `kibana.yml` file.
[cols="2*<"]
|===

| `xpack.actions.whitelistedHosts`
| `xpack.actions.whitelistedHosts` {ess-icon}
| A list of hostnames that {kib} is allowed to connect to when built-in actions are triggered. It defaults to `[*]`, allowing any host, but keep in mind the potential for SSRF attacks when hosts are not explicitly whitelisted. An empty list `[]` can be used to block built-in actions from making any external connections. +
+
Note that hosts associated with built-in actions, such as Slack and PagerDuty, are not automatically whitelisted. If you are not using the default `[*]` setting, you must ensure that the corresponding endpoints are whitelisted as well.

| `xpack.actions.enabledActionTypes`
| `xpack.actions.enabledActionTypes` {ess-icon}
| A list of action types that are enabled. It defaults to `[*]`, enabling all types. The names for built-in {kib} action types are prefixed with a `.` and include: `.server-log`, `.slack`, `.email`, `.index`, `.pagerduty`, and `.webhook`. An empty list `[]` will disable all action types. +
+
Disabled action types will not appear as an option when creating new connectors, but existing connectors and actions of that type will remain in {kib} and will not function.
Expand Down
74 changes: 74 additions & 0 deletions packages/kbn-es-archiver/src/lib/streams/concat_stream.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { createListStream, createPromiseFromStreams, createConcatStream } from './';

describe('concatStream', () => {
test('accepts an initial value', async () => {
const output = await createPromiseFromStreams([
createListStream([1, 2, 3]),
createConcatStream([0]),
]);

expect(output).toEqual([0, 1, 2, 3]);
});

describe(`combines using the previous value's concat method`, () => {
test('works with strings', async () => {
const output = await createPromiseFromStreams([
createListStream(['a', 'b', 'c']),
createConcatStream(),
]);
expect(output).toEqual('abc');
});

test('works with arrays', async () => {
const output = await createPromiseFromStreams([
createListStream([[1], [2, 3, 4], [10]]),
createConcatStream(),
]);
expect(output).toEqual([1, 2, 3, 4, 10]);
});

test('works with a mixture, starting with array', async () => {
const output = await createPromiseFromStreams([
createListStream([[], 1, 2, 3, 4, [5, 6, 7]]),
createConcatStream(),
]);
expect(output).toEqual([1, 2, 3, 4, 5, 6, 7]);
});

test('fails when the value does not have a concat method', async () => {
let promise;
try {
promise = createPromiseFromStreams([createListStream([1, '1']), createConcatStream()]);
} catch (err) {
throw new Error('createPromiseFromStreams() should not fail synchronously');
}

try {
await promise;
throw new Error('Promise should have rejected');
} catch (err) {
expect(err).toBeInstanceOf(Error);
expect(err.message).toContain('concat');
}
});
});
});
41 changes: 41 additions & 0 deletions packages/kbn-es-archiver/src/lib/streams/concat_stream.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { createReduceStream } from './reduce_stream';

/**
* Creates a Transform stream that consumes all provided
* values and concatenates them using each values `concat`
* method.
*
* Concatenate strings:
* createListStream(['f', 'o', 'o'])
* .pipe(createConcatStream())
* .on('data', console.log)
* // logs "foo"
*
* Concatenate values into an array:
* createListStream([1,2,3])
* .pipe(createConcatStream([]))
* .on('data', console.log)
* // logs "[1,2,3]"
*/
export function createConcatStream(initial: any) {
return createReduceStream((acc, chunk) => acc.concat(chunk), initial);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { Readable } from 'stream';

import { concatStreamProviders } from './concat_stream_providers';
import { createListStream } from './list_stream';
import { createConcatStream } from './concat_stream';
import { createPromiseFromStreams } from './promise_from_streams';

describe('concatStreamProviders() helper', () => {
test('writes the data from an array of stream providers into a destination stream in order', async () => {
const results = await createPromiseFromStreams([
concatStreamProviders([
() => createListStream(['foo', 'bar']),
() => createListStream(['baz']),
() => createListStream(['bug']),
]),
createConcatStream(''),
]);

expect(results).toBe('foobarbazbug');
});

test('emits the errors from a sub-stream to the destination', async () => {
const dest = concatStreamProviders([
() => createListStream(['foo', 'bar']),
() =>
new Readable({
read() {
this.emit('error', new Error('foo'));
},
}),
]);

const errorListener = jest.fn();
dest.on('error', errorListener);

await expect(createPromiseFromStreams([dest])).rejects.toThrowErrorMatchingInlineSnapshot(
`"foo"`
);
expect(errorListener.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
[Error: foo],
],
]
`);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { PassThrough, TransformOptions } from 'stream';

/**
* Write the data and errors from a list of stream providers
* to a single stream in order. Stream providers are only
* called right before they will be consumed, and only one
* provider will be active at a time.
*/
export function concatStreamProviders(
sourceProviders: Array<() => NodeJS.ReadableStream>,
options: TransformOptions = {}
) {
const destination = new PassThrough(options);
const queue = sourceProviders.slice();

(function pipeNext() {
const provider = queue.shift();

if (!provider) {
return;
}

const source = provider();
const isLast = !queue.length;

// if there are more sources to pipe, hook
// into the source completion
if (!isLast) {
source.once('end', pipeNext);
}

source
// proxy errors from the source to the destination
.once('error', (error) => destination.emit('error', error))
// pipe the source to the destination but only proxy the
// end event if this is the last source
.pipe(destination, { end: isLast });
})();

return destination;
}
77 changes: 77 additions & 0 deletions packages/kbn-es-archiver/src/lib/streams/filter_stream.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import {
createConcatStream,
createFilterStream,
createListStream,
createPromiseFromStreams,
} from './';

describe('createFilterStream()', () => {
test('calls the function with each item in the source stream', async () => {
const filter = jest.fn().mockReturnValue(true);

await createPromiseFromStreams([createListStream(['a', 'b', 'c']), createFilterStream(filter)]);

expect(filter).toMatchInlineSnapshot(`
[MockFunction] {
"calls": Array [
Array [
"a",
],
Array [
"b",
],
Array [
"c",
],
],
"results": Array [
Object {
"type": "return",
"value": true,
},
Object {
"type": "return",
"value": true,
},
Object {
"type": "return",
"value": true,
},
],
}
`);
});

test('send the filtered values on the output stream', async () => {
const result = await createPromiseFromStreams([
createListStream([1, 2, 3]),
createFilterStream<number>((n) => n % 2 === 0),
createConcatStream([]),
]);

expect(result).toMatchInlineSnapshot(`
Array [
2,
]
`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,17 @@
* under the License.
*/

export * from '../../../../src/legacy/utils/streams';
import { Transform } from 'stream';

export function createFilterStream<T>(fn: (obj: T) => boolean) {
return new Transform({
objectMode: true,
async transform(obj, _, done) {
const canPushDownStream = fn(obj);
if (canPushDownStream) {
this.push(obj);
}
done();
},
});
}
29 changes: 29 additions & 0 deletions packages/kbn-es-archiver/src/lib/streams/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { concatStreamProviders } from './concat_stream_providers';
export { createIntersperseStream } from './intersperse_stream';
export { createSplitStream } from './split_stream';
export { createListStream } from './list_stream';
export { createReduceStream } from './reduce_stream';
export { createPromiseFromStreams } from './promise_from_streams';
export { createConcatStream } from './concat_stream';
export { createMapStream } from './map_stream';
export { createReplaceStream } from './replace_stream';
export { createFilterStream } from './filter_stream';
Loading

0 comments on commit 1981fb6

Please sign in to comment.