Skip to content

Commit 016b299

Browse files
committed
Merge branch 'master' of github.com:elastic/kibana into pr/76397
2 parents 425523b + c46e777 commit 016b299

File tree

398 files changed

+9121
-4948
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

398 files changed

+9121
-4948
lines changed

docs/settings/alert-action-settings.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ You can configure the following settings in the `kibana.yml` file.
3737
[cols="2*<"]
3838
|===
3939

40-
| `xpack.actions.whitelistedHosts`
40+
| `xpack.actions.whitelistedHosts` {ess-icon}
4141
| 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. +
4242
+
4343
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.
4444

45-
| `xpack.actions.enabledActionTypes`
45+
| `xpack.actions.enabledActionTypes` {ess-icon}
4646
| 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. +
4747
+
4848
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.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { createListStream, createPromiseFromStreams, createConcatStream } from './';
21+
22+
describe('concatStream', () => {
23+
test('accepts an initial value', async () => {
24+
const output = await createPromiseFromStreams([
25+
createListStream([1, 2, 3]),
26+
createConcatStream([0]),
27+
]);
28+
29+
expect(output).toEqual([0, 1, 2, 3]);
30+
});
31+
32+
describe(`combines using the previous value's concat method`, () => {
33+
test('works with strings', async () => {
34+
const output = await createPromiseFromStreams([
35+
createListStream(['a', 'b', 'c']),
36+
createConcatStream(),
37+
]);
38+
expect(output).toEqual('abc');
39+
});
40+
41+
test('works with arrays', async () => {
42+
const output = await createPromiseFromStreams([
43+
createListStream([[1], [2, 3, 4], [10]]),
44+
createConcatStream(),
45+
]);
46+
expect(output).toEqual([1, 2, 3, 4, 10]);
47+
});
48+
49+
test('works with a mixture, starting with array', async () => {
50+
const output = await createPromiseFromStreams([
51+
createListStream([[], 1, 2, 3, 4, [5, 6, 7]]),
52+
createConcatStream(),
53+
]);
54+
expect(output).toEqual([1, 2, 3, 4, 5, 6, 7]);
55+
});
56+
57+
test('fails when the value does not have a concat method', async () => {
58+
let promise;
59+
try {
60+
promise = createPromiseFromStreams([createListStream([1, '1']), createConcatStream()]);
61+
} catch (err) {
62+
throw new Error('createPromiseFromStreams() should not fail synchronously');
63+
}
64+
65+
try {
66+
await promise;
67+
throw new Error('Promise should have rejected');
68+
} catch (err) {
69+
expect(err).toBeInstanceOf(Error);
70+
expect(err.message).toContain('concat');
71+
}
72+
});
73+
});
74+
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { createReduceStream } from './reduce_stream';
21+
22+
/**
23+
* Creates a Transform stream that consumes all provided
24+
* values and concatenates them using each values `concat`
25+
* method.
26+
*
27+
* Concatenate strings:
28+
* createListStream(['f', 'o', 'o'])
29+
* .pipe(createConcatStream())
30+
* .on('data', console.log)
31+
* // logs "foo"
32+
*
33+
* Concatenate values into an array:
34+
* createListStream([1,2,3])
35+
* .pipe(createConcatStream([]))
36+
* .on('data', console.log)
37+
* // logs "[1,2,3]"
38+
*/
39+
export function createConcatStream(initial: any) {
40+
return createReduceStream((acc, chunk) => acc.concat(chunk), initial);
41+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { Readable } from 'stream';
21+
22+
import { concatStreamProviders } from './concat_stream_providers';
23+
import { createListStream } from './list_stream';
24+
import { createConcatStream } from './concat_stream';
25+
import { createPromiseFromStreams } from './promise_from_streams';
26+
27+
describe('concatStreamProviders() helper', () => {
28+
test('writes the data from an array of stream providers into a destination stream in order', async () => {
29+
const results = await createPromiseFromStreams([
30+
concatStreamProviders([
31+
() => createListStream(['foo', 'bar']),
32+
() => createListStream(['baz']),
33+
() => createListStream(['bug']),
34+
]),
35+
createConcatStream(''),
36+
]);
37+
38+
expect(results).toBe('foobarbazbug');
39+
});
40+
41+
test('emits the errors from a sub-stream to the destination', async () => {
42+
const dest = concatStreamProviders([
43+
() => createListStream(['foo', 'bar']),
44+
() =>
45+
new Readable({
46+
read() {
47+
this.emit('error', new Error('foo'));
48+
},
49+
}),
50+
]);
51+
52+
const errorListener = jest.fn();
53+
dest.on('error', errorListener);
54+
55+
await expect(createPromiseFromStreams([dest])).rejects.toThrowErrorMatchingInlineSnapshot(
56+
`"foo"`
57+
);
58+
expect(errorListener.mock.calls).toMatchInlineSnapshot(`
59+
Array [
60+
Array [
61+
[Error: foo],
62+
],
63+
]
64+
`);
65+
});
66+
});
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { PassThrough, TransformOptions } from 'stream';
21+
22+
/**
23+
* Write the data and errors from a list of stream providers
24+
* to a single stream in order. Stream providers are only
25+
* called right before they will be consumed, and only one
26+
* provider will be active at a time.
27+
*/
28+
export function concatStreamProviders(
29+
sourceProviders: Array<() => NodeJS.ReadableStream>,
30+
options: TransformOptions = {}
31+
) {
32+
const destination = new PassThrough(options);
33+
const queue = sourceProviders.slice();
34+
35+
(function pipeNext() {
36+
const provider = queue.shift();
37+
38+
if (!provider) {
39+
return;
40+
}
41+
42+
const source = provider();
43+
const isLast = !queue.length;
44+
45+
// if there are more sources to pipe, hook
46+
// into the source completion
47+
if (!isLast) {
48+
source.once('end', pipeNext);
49+
}
50+
51+
source
52+
// proxy errors from the source to the destination
53+
.once('error', (error) => destination.emit('error', error))
54+
// pipe the source to the destination but only proxy the
55+
// end event if this is the last source
56+
.pipe(destination, { end: isLast });
57+
})();
58+
59+
return destination;
60+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import {
21+
createConcatStream,
22+
createFilterStream,
23+
createListStream,
24+
createPromiseFromStreams,
25+
} from './';
26+
27+
describe('createFilterStream()', () => {
28+
test('calls the function with each item in the source stream', async () => {
29+
const filter = jest.fn().mockReturnValue(true);
30+
31+
await createPromiseFromStreams([createListStream(['a', 'b', 'c']), createFilterStream(filter)]);
32+
33+
expect(filter).toMatchInlineSnapshot(`
34+
[MockFunction] {
35+
"calls": Array [
36+
Array [
37+
"a",
38+
],
39+
Array [
40+
"b",
41+
],
42+
Array [
43+
"c",
44+
],
45+
],
46+
"results": Array [
47+
Object {
48+
"type": "return",
49+
"value": true,
50+
},
51+
Object {
52+
"type": "return",
53+
"value": true,
54+
},
55+
Object {
56+
"type": "return",
57+
"value": true,
58+
},
59+
],
60+
}
61+
`);
62+
});
63+
64+
test('send the filtered values on the output stream', async () => {
65+
const result = await createPromiseFromStreams([
66+
createListStream([1, 2, 3]),
67+
createFilterStream<number>((n) => n % 2 === 0),
68+
createConcatStream([]),
69+
]);
70+
71+
expect(result).toMatchInlineSnapshot(`
72+
Array [
73+
2,
74+
]
75+
`);
76+
});
77+
});

packages/kbn-es-archiver/src/lib/streams.ts renamed to packages/kbn-es-archiver/src/lib/streams/filter_stream.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@
1717
* under the License.
1818
*/
1919

20-
export {
21-
createFilterStream,
22-
concatStreamProviders,
23-
createConcatStream,
24-
createIntersperseStream,
25-
createListStream,
26-
createPromiseFromStreams,
27-
createReduceStream,
28-
createSplitStream,
29-
createMapStream,
30-
createReplaceStream,
31-
} from '../../../../src/legacy/utils';
20+
import { Transform } from 'stream';
21+
22+
export function createFilterStream<T>(fn: (obj: T) => boolean) {
23+
return new Transform({
24+
objectMode: true,
25+
async transform(obj, _, done) {
26+
const canPushDownStream = fn(obj);
27+
if (canPushDownStream) {
28+
this.push(obj);
29+
}
30+
done();
31+
},
32+
});
33+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
export { concatStreamProviders } from './concat_stream_providers';
21+
export { createIntersperseStream } from './intersperse_stream';
22+
export { createSplitStream } from './split_stream';
23+
export { createListStream } from './list_stream';
24+
export { createReduceStream } from './reduce_stream';
25+
export { createPromiseFromStreams } from './promise_from_streams';
26+
export { createConcatStream } from './concat_stream';
27+
export { createMapStream } from './map_stream';
28+
export { createReplaceStream } from './replace_stream';
29+
export { createFilterStream } from './filter_stream';

0 commit comments

Comments
 (0)