From 533046fd9ce73cddd1677a5179d1b325b9e15a09 Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Mon, 15 Jun 2020 08:48:10 -0400 Subject: [PATCH 01/82] [ES UI] Error handling (#68809) --- .../errors/index.ts | 20 +++++++++++ .../errors/is_es_error.ts | 33 +++++++++++++++++++ src/plugins/es_ui_shared/kibana.json | 3 +- .../es_ui_shared/server/errors/index.ts | 20 +++++++++++ src/plugins/es_ui_shared/server/index.ts | 28 ++++++++++++++++ .../server/lib/is_es_error.ts | 13 -------- .../server/plugin.ts | 2 +- .../register_create_route.test.ts | 2 +- .../register_delete_route.test.ts | 2 +- .../register_fetch_route.test.ts | 2 +- .../register_get_route.test.ts | 2 +- .../register_pause_route.test.ts | 2 +- .../register_resume_route.test.ts | 2 +- .../register_update_route.test.ts | 2 +- .../register_create_route.test.ts | 2 +- .../register_fetch_route.test.ts | 2 +- .../follower_index/register_get_route.test.ts | 2 +- .../register_pause_route.test.ts | 2 +- .../register_resume_route.test.ts | 2 +- .../register_unfollow_route.test.ts | 2 +- .../server/shared_imports.ts} | 2 +- .../cross_cluster_replication/server/types.ts | 2 +- .../server/lib/is_es_error.ts | 13 -------- .../server/plugin.ts | 2 +- .../server/shared_imports.ts} | 2 +- .../server/types.ts | 2 +- .../server/lib/is_es_error.ts | 13 -------- .../plugins/index_management/server/plugin.ts | 2 +- .../server/shared_imports.ts} | 2 +- .../plugins/index_management/server/types.ts | 2 +- .../server/lib/is_es_error.ts | 13 -------- .../plugins/ingest_pipelines/server/plugin.ts | 2 +- .../{lib/index.ts => shared_imports.ts} | 2 +- .../plugins/ingest_pipelines/server/types.ts | 2 +- .../server/lib/is_es_error.ts | 13 -------- .../license_management/server/plugin.ts | 2 +- .../server/shared_imports.ts | 7 ++++ .../license_management/server/types.ts | 2 +- .../painless_lab/server/lib/is_es_error.ts | 13 -------- .../painless_lab/server/routes/api/execute.ts | 2 +- .../painless_lab/server/shared_imports.ts | 7 ++++ .../server/lib/is_es_error/is_es_error.ts | 13 -------- .../server/routes/api/add_route.ts | 2 +- .../server/routes/api/delete_route.ts | 2 +- .../server/routes/api/get_route.ts | 2 +- .../server/routes/api/update_route.ts | 2 +- .../remote_clusters/server/shared_imports.ts | 7 ++++ .../plugins/rollup/server/lib/is_es_error.ts | 13 -------- x-pack/plugins/rollup/server/plugin.ts | 2 +- .../plugins/rollup/server/shared_imports.ts | 2 ++ x-pack/plugins/rollup/server/types.ts | 2 +- .../snapshot_restore/server/lib/index.ts | 1 - .../server/lib/is_es_error.ts | 13 -------- .../plugins/snapshot_restore/server/plugin.ts | 3 +- .../snapshot_restore/server/shared_imports.ts | 7 ++++ .../server/test/helpers/route_dependencies.ts | 3 +- .../plugins/snapshot_restore/server/types.ts | 3 +- .../server/lib/is_es_error/is_es_error.ts | 13 -------- .../routes/api/indices/register_get_route.ts | 2 +- .../routes/api/register_list_fields_route.ts | 2 +- .../routes/api/register_load_history_route.ts | 2 +- .../api/settings/register_load_route.ts | 2 +- .../action/register_acknowledge_route.ts | 2 +- .../api/watch/register_activate_route.ts | 2 +- .../api/watch/register_deactivate_route.ts | 2 +- .../routes/api/watch/register_delete_route.ts | 2 +- .../api/watch/register_execute_route.ts | 2 +- .../api/watch/register_history_route.ts | 2 +- .../routes/api/watch/register_load_route.ts | 2 +- .../routes/api/watch/register_save_route.ts | 2 +- .../api/watch/register_visualize_route.ts | 2 +- .../routes/api/watches/register_list_route.ts | 2 +- .../plugins/watcher/server/shared_imports.ts | 7 ++++ 73 files changed, 194 insertions(+), 183 deletions(-) create mode 100644 src/plugins/es_ui_shared/__packages_do_not_import__/errors/index.ts create mode 100644 src/plugins/es_ui_shared/__packages_do_not_import__/errors/is_es_error.ts create mode 100644 src/plugins/es_ui_shared/server/errors/index.ts create mode 100644 src/plugins/es_ui_shared/server/index.ts delete mode 100644 x-pack/plugins/cross_cluster_replication/server/lib/is_es_error.ts rename x-pack/plugins/{painless_lab/server/lib/index.ts => cross_cluster_replication/server/shared_imports.ts} (76%) delete mode 100644 x-pack/plugins/index_lifecycle_management/server/lib/is_es_error.ts rename x-pack/plugins/{remote_clusters/server/lib/is_es_error/index.ts => index_lifecycle_management/server/shared_imports.ts} (76%) delete mode 100644 x-pack/plugins/index_management/server/lib/is_es_error.ts rename x-pack/plugins/{watcher/server/lib/is_es_error/index.ts => index_management/server/shared_imports.ts} (76%) delete mode 100644 x-pack/plugins/ingest_pipelines/server/lib/is_es_error.ts rename x-pack/plugins/ingest_pipelines/server/{lib/index.ts => shared_imports.ts} (76%) delete mode 100644 x-pack/plugins/license_management/server/lib/is_es_error.ts create mode 100644 x-pack/plugins/license_management/server/shared_imports.ts delete mode 100644 x-pack/plugins/painless_lab/server/lib/is_es_error.ts create mode 100644 x-pack/plugins/painless_lab/server/shared_imports.ts delete mode 100644 x-pack/plugins/remote_clusters/server/lib/is_es_error/is_es_error.ts create mode 100644 x-pack/plugins/remote_clusters/server/shared_imports.ts delete mode 100644 x-pack/plugins/rollup/server/lib/is_es_error.ts delete mode 100644 x-pack/plugins/snapshot_restore/server/lib/is_es_error.ts create mode 100644 x-pack/plugins/snapshot_restore/server/shared_imports.ts delete mode 100644 x-pack/plugins/watcher/server/lib/is_es_error/is_es_error.ts create mode 100644 x-pack/plugins/watcher/server/shared_imports.ts diff --git a/src/plugins/es_ui_shared/__packages_do_not_import__/errors/index.ts b/src/plugins/es_ui_shared/__packages_do_not_import__/errors/index.ts new file mode 100644 index 00000000000000..0d025442f4a926 --- /dev/null +++ b/src/plugins/es_ui_shared/__packages_do_not_import__/errors/index.ts @@ -0,0 +1,20 @@ +/* + * 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 { isEsError } from './is_es_error'; diff --git a/src/plugins/es_ui_shared/__packages_do_not_import__/errors/is_es_error.ts b/src/plugins/es_ui_shared/__packages_do_not_import__/errors/is_es_error.ts new file mode 100644 index 00000000000000..1e212307ca1ccf --- /dev/null +++ b/src/plugins/es_ui_shared/__packages_do_not_import__/errors/is_es_error.ts @@ -0,0 +1,33 @@ +/* + * 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 * as legacyElasticsearch from 'elasticsearch'; + +const esErrorsParent = legacyElasticsearch.errors._Abstract; + +interface RequestError extends Error { + statusCode?: number; +} + +export function isEsError(err: RequestError) { + const isInstanceOfEsError = err instanceof esErrorsParent; + const hasStatusCode = Boolean(err.statusCode); + + return isInstanceOfEsError && hasStatusCode; +} diff --git a/src/plugins/es_ui_shared/kibana.json b/src/plugins/es_ui_shared/kibana.json index 5a3db3b3440901..5f772b3c83da95 100644 --- a/src/plugins/es_ui_shared/kibana.json +++ b/src/plugins/es_ui_shared/kibana.json @@ -1,5 +1,6 @@ { "id": "esUiShared", "version": "kibana", - "ui": true + "ui": true, + "server": true } diff --git a/src/plugins/es_ui_shared/server/errors/index.ts b/src/plugins/es_ui_shared/server/errors/index.ts new file mode 100644 index 00000000000000..c18374cd9ec315 --- /dev/null +++ b/src/plugins/es_ui_shared/server/errors/index.ts @@ -0,0 +1,20 @@ +/* + * 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 { isEsError } from '../../__packages_do_not_import__/errors'; diff --git a/src/plugins/es_ui_shared/server/index.ts b/src/plugins/es_ui_shared/server/index.ts new file mode 100644 index 00000000000000..0118bbda53262b --- /dev/null +++ b/src/plugins/es_ui_shared/server/index.ts @@ -0,0 +1,28 @@ +/* + * 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 { isEsError } from './errors'; + +/** dummy plugin*/ +export function plugin() { + return new (class EsUiSharedPlugin { + setup() {} + start() {} + })(); +} diff --git a/x-pack/plugins/cross_cluster_replication/server/lib/is_es_error.ts b/x-pack/plugins/cross_cluster_replication/server/lib/is_es_error.ts deleted file mode 100644 index 4137293cf39c06..00000000000000 --- a/x-pack/plugins/cross_cluster_replication/server/lib/is_es_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import * as legacyElasticsearch from 'elasticsearch'; - -const esErrorsParent = legacyElasticsearch.errors._Abstract; - -export function isEsError(err: Error) { - return err instanceof esErrorsParent; -} diff --git a/x-pack/plugins/cross_cluster_replication/server/plugin.ts b/x-pack/plugins/cross_cluster_replication/server/plugin.ts index f30378d874a9ad..d9fe296553f38c 100644 --- a/x-pack/plugins/cross_cluster_replication/server/plugin.ts +++ b/x-pack/plugins/cross_cluster_replication/server/plugin.ts @@ -30,7 +30,7 @@ import { registerApiRoutes } from './routes'; import { License } from './services'; import { elasticsearchJsPlugin } from './client/elasticsearch_ccr'; import { CrossClusterReplicationConfig } from './config'; -import { isEsError } from './lib/is_es_error'; +import { isEsError } from './shared_imports'; import { formatEsError } from './lib/format_es_error'; interface CrossClusterReplicationContext { diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_create_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_create_route.test.ts index b41b52e1764c83..0b5f04556596af 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_create_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_create_route.test.ts @@ -7,7 +7,7 @@ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; import { License } from '../../../services'; import { mockRouteContext } from '../test_lib'; diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_delete_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_delete_route.test.ts index e610d09b44275c..7468c643a3aa6a 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_delete_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_delete_route.test.ts @@ -7,7 +7,7 @@ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; import { License } from '../../../services'; import { mockRouteContext } from '../test_lib'; diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_fetch_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_fetch_route.test.ts index dd102c45665cbe..1aa7112c752765 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_fetch_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_fetch_route.test.ts @@ -7,7 +7,7 @@ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; import { License } from '../../../services'; import { mockRouteContext } from '../test_lib'; diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_get_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_get_route.test.ts index d5889074651f50..980128027c2f98 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_get_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_get_route.test.ts @@ -7,7 +7,7 @@ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; import { License } from '../../../services'; import { mockRouteContext } from '../test_lib'; diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_pause_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_pause_route.test.ts index 1eaac02918b88d..5b27c77ca86de6 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_pause_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_pause_route.test.ts @@ -7,7 +7,7 @@ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; import { License } from '../../../services'; import { mockRouteContext } from '../test_lib'; diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_resume_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_resume_route.test.ts index 9839761e701fc2..afea0f631fe48b 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_resume_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_resume_route.test.ts @@ -7,7 +7,7 @@ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; import { License } from '../../../services'; import { mockRouteContext } from '../test_lib'; diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_update_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_update_route.test.ts index 85f2270ec3aee1..bdce84f6404b15 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_update_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_update_route.test.ts @@ -7,7 +7,7 @@ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; import { License } from '../../../services'; import { mockRouteContext } from '../test_lib'; diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_create_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_create_route.test.ts index bba82b04ce9a0c..ccf7c469fe7807 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_create_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_create_route.test.ts @@ -7,7 +7,7 @@ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; import { License } from '../../../services'; import { mockRouteContext } from '../test_lib'; diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_fetch_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_fetch_route.test.ts index 151ab84fabf4c4..e1ec28a7c90b10 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_fetch_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_fetch_route.test.ts @@ -7,7 +7,7 @@ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; import { License } from '../../../services'; import { mockRouteContext } from '../test_lib'; diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_get_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_get_route.test.ts index 42d04ca65b1cb2..99c871d5d4f2dc 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_get_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_get_route.test.ts @@ -7,7 +7,7 @@ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; import { License } from '../../../services'; import { mockRouteContext } from '../test_lib'; diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_pause_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_pause_route.test.ts index 82cb88cbacea7e..3d28d36ac61827 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_pause_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_pause_route.test.ts @@ -7,7 +7,7 @@ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; import { License } from '../../../services'; import { mockRouteContext } from '../test_lib'; diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_resume_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_resume_route.test.ts index 04167c5db31628..09975b262dca8f 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_resume_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_resume_route.test.ts @@ -7,7 +7,7 @@ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; import { License } from '../../../services'; import { mockRouteContext } from '../test_lib'; diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_unfollow_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_unfollow_route.test.ts index 6302d5868b0dbf..5f0d148bfcae96 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_unfollow_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_unfollow_route.test.ts @@ -7,7 +7,7 @@ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; import { License } from '../../../services'; import { mockRouteContext } from '../test_lib'; diff --git a/x-pack/plugins/painless_lab/server/lib/index.ts b/x-pack/plugins/cross_cluster_replication/server/shared_imports.ts similarity index 76% rename from x-pack/plugins/painless_lab/server/lib/index.ts rename to x-pack/plugins/cross_cluster_replication/server/shared_imports.ts index a9a3c61472d8c7..454beda5394c71 100644 --- a/x-pack/plugins/painless_lab/server/lib/index.ts +++ b/x-pack/plugins/cross_cluster_replication/server/shared_imports.ts @@ -4,4 +4,4 @@ * you may not use this file except in compliance with the Elastic License. */ -export { isEsError } from './is_es_error'; +export { isEsError } from '../../../../src/plugins/es_ui_shared/server'; diff --git a/x-pack/plugins/cross_cluster_replication/server/types.ts b/x-pack/plugins/cross_cluster_replication/server/types.ts index 049d440e3d85db..c287acf86eb2b6 100644 --- a/x-pack/plugins/cross_cluster_replication/server/types.ts +++ b/x-pack/plugins/cross_cluster_replication/server/types.ts @@ -9,7 +9,7 @@ import { LicensingPluginSetup } from '../../licensing/server'; import { IndexManagementPluginSetup } from '../../index_management/server'; import { RemoteClustersPluginSetup } from '../../remote_clusters/server'; import { License } from './services'; -import { isEsError } from './lib/is_es_error'; +import { isEsError } from './shared_imports'; import { formatEsError } from './lib/format_es_error'; export interface Dependencies { diff --git a/x-pack/plugins/index_lifecycle_management/server/lib/is_es_error.ts b/x-pack/plugins/index_lifecycle_management/server/lib/is_es_error.ts deleted file mode 100644 index 2f514b93e5016c..00000000000000 --- a/x-pack/plugins/index_lifecycle_management/server/lib/is_es_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import * as legacyElasticsearch from 'elasticsearch'; - -const esErrorsParent = legacyElasticsearch.errors._Abstract; - -export function isEsError(err: Error): boolean { - return err instanceof esErrorsParent; -} diff --git a/x-pack/plugins/index_lifecycle_management/server/plugin.ts b/x-pack/plugins/index_lifecycle_management/server/plugin.ts index faeac67f62a21c..79a9849e634b5f 100644 --- a/x-pack/plugins/index_lifecycle_management/server/plugin.ts +++ b/x-pack/plugins/index_lifecycle_management/server/plugin.ts @@ -14,7 +14,7 @@ import { Dependencies } from './types'; import { registerApiRoutes } from './routes'; import { License } from './services'; import { IndexLifecycleManagementConfig } from './config'; -import { isEsError } from './lib/is_es_error'; +import { isEsError } from './shared_imports'; const indexLifecycleDataEnricher = async (indicesList: any, callAsCurrentUser: APICaller) => { if (!indicesList || !indicesList.length) { diff --git a/x-pack/plugins/remote_clusters/server/lib/is_es_error/index.ts b/x-pack/plugins/index_lifecycle_management/server/shared_imports.ts similarity index 76% rename from x-pack/plugins/remote_clusters/server/lib/is_es_error/index.ts rename to x-pack/plugins/index_lifecycle_management/server/shared_imports.ts index a9a3c61472d8c7..454beda5394c71 100644 --- a/x-pack/plugins/remote_clusters/server/lib/is_es_error/index.ts +++ b/x-pack/plugins/index_lifecycle_management/server/shared_imports.ts @@ -4,4 +4,4 @@ * you may not use this file except in compliance with the Elastic License. */ -export { isEsError } from './is_es_error'; +export { isEsError } from '../../../../src/plugins/es_ui_shared/server'; diff --git a/x-pack/plugins/index_lifecycle_management/server/types.ts b/x-pack/plugins/index_lifecycle_management/server/types.ts index 734d05a82000e2..8ea0956be08651 100644 --- a/x-pack/plugins/index_lifecycle_management/server/types.ts +++ b/x-pack/plugins/index_lifecycle_management/server/types.ts @@ -10,7 +10,7 @@ import { LicensingPluginSetup } from '../../licensing/server'; import { IndexManagementPluginSetup } from '../../index_management/server'; import { License } from './services'; import { IndexLifecycleManagementConfig } from './config'; -import { isEsError } from './lib/is_es_error'; +import { isEsError } from './shared_imports'; export interface Dependencies { licensing: LicensingPluginSetup; diff --git a/x-pack/plugins/index_management/server/lib/is_es_error.ts b/x-pack/plugins/index_management/server/lib/is_es_error.ts deleted file mode 100644 index 4137293cf39c06..00000000000000 --- a/x-pack/plugins/index_management/server/lib/is_es_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import * as legacyElasticsearch from 'elasticsearch'; - -const esErrorsParent = legacyElasticsearch.errors._Abstract; - -export function isEsError(err: Error) { - return err instanceof esErrorsParent; -} diff --git a/x-pack/plugins/index_management/server/plugin.ts b/x-pack/plugins/index_management/server/plugin.ts index c1b9945c2cd1dc..94af8415bfd559 100644 --- a/x-pack/plugins/index_management/server/plugin.ts +++ b/x-pack/plugins/index_management/server/plugin.ts @@ -24,7 +24,7 @@ import { PLUGIN } from '../common'; import { Dependencies } from './types'; import { ApiRoutes } from './routes'; import { License, IndexDataEnricher } from './services'; -import { isEsError } from './lib/is_es_error'; +import { isEsError } from './shared_imports'; import { elasticsearchJsPlugin } from './client/elasticsearch'; export interface DataManagementContext { diff --git a/x-pack/plugins/watcher/server/lib/is_es_error/index.ts b/x-pack/plugins/index_management/server/shared_imports.ts similarity index 76% rename from x-pack/plugins/watcher/server/lib/is_es_error/index.ts rename to x-pack/plugins/index_management/server/shared_imports.ts index a9a3c61472d8c7..454beda5394c71 100644 --- a/x-pack/plugins/watcher/server/lib/is_es_error/index.ts +++ b/x-pack/plugins/index_management/server/shared_imports.ts @@ -4,4 +4,4 @@ * you may not use this file except in compliance with the Elastic License. */ -export { isEsError } from './is_es_error'; +export { isEsError } from '../../../../src/plugins/es_ui_shared/server'; diff --git a/x-pack/plugins/index_management/server/types.ts b/x-pack/plugins/index_management/server/types.ts index 1482d9225c7b5f..dc151f510a0437 100644 --- a/x-pack/plugins/index_management/server/types.ts +++ b/x-pack/plugins/index_management/server/types.ts @@ -7,7 +7,7 @@ import { ScopedClusterClient, IRouter } from 'src/core/server'; import { LicensingPluginSetup } from '../../licensing/server'; import { SecurityPluginSetup } from '../../security/server'; import { License, IndexDataEnricher } from './services'; -import { isEsError } from './lib/is_es_error'; +import { isEsError } from './shared_imports'; export interface Dependencies { security: SecurityPluginSetup; diff --git a/x-pack/plugins/ingest_pipelines/server/lib/is_es_error.ts b/x-pack/plugins/ingest_pipelines/server/lib/is_es_error.ts deleted file mode 100644 index 4137293cf39c06..00000000000000 --- a/x-pack/plugins/ingest_pipelines/server/lib/is_es_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import * as legacyElasticsearch from 'elasticsearch'; - -const esErrorsParent = legacyElasticsearch.errors._Abstract; - -export function isEsError(err: Error) { - return err instanceof esErrorsParent; -} diff --git a/x-pack/plugins/ingest_pipelines/server/plugin.ts b/x-pack/plugins/ingest_pipelines/server/plugin.ts index 8cec03c49d4396..7a78bf608b8e1a 100644 --- a/x-pack/plugins/ingest_pipelines/server/plugin.ts +++ b/x-pack/plugins/ingest_pipelines/server/plugin.ts @@ -11,7 +11,7 @@ import { PLUGIN_ID, PLUGIN_MIN_LICENSE_TYPE } from '../common/constants'; import { License } from './services'; import { ApiRoutes } from './routes'; -import { isEsError } from './lib'; +import { isEsError } from './shared_imports'; import { Dependencies } from './types'; export class IngestPipelinesPlugin implements Plugin { diff --git a/x-pack/plugins/ingest_pipelines/server/lib/index.ts b/x-pack/plugins/ingest_pipelines/server/shared_imports.ts similarity index 76% rename from x-pack/plugins/ingest_pipelines/server/lib/index.ts rename to x-pack/plugins/ingest_pipelines/server/shared_imports.ts index a9a3c61472d8c7..454beda5394c71 100644 --- a/x-pack/plugins/ingest_pipelines/server/lib/index.ts +++ b/x-pack/plugins/ingest_pipelines/server/shared_imports.ts @@ -4,4 +4,4 @@ * you may not use this file except in compliance with the Elastic License. */ -export { isEsError } from './is_es_error'; +export { isEsError } from '../../../../src/plugins/es_ui_shared/server'; diff --git a/x-pack/plugins/ingest_pipelines/server/types.ts b/x-pack/plugins/ingest_pipelines/server/types.ts index 70094859dff3f0..261317daa26d98 100644 --- a/x-pack/plugins/ingest_pipelines/server/types.ts +++ b/x-pack/plugins/ingest_pipelines/server/types.ts @@ -8,7 +8,7 @@ import { IRouter } from 'src/core/server'; import { LicensingPluginSetup } from '../../licensing/server'; import { SecurityPluginSetup } from '../../security/server'; import { License } from './services'; -import { isEsError } from './lib'; +import { isEsError } from './shared_imports'; export interface Dependencies { security: SecurityPluginSetup; diff --git a/x-pack/plugins/license_management/server/lib/is_es_error.ts b/x-pack/plugins/license_management/server/lib/is_es_error.ts deleted file mode 100644 index 4137293cf39c06..00000000000000 --- a/x-pack/plugins/license_management/server/lib/is_es_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import * as legacyElasticsearch from 'elasticsearch'; - -const esErrorsParent = legacyElasticsearch.errors._Abstract; - -export function isEsError(err: Error) { - return err instanceof esErrorsParent; -} diff --git a/x-pack/plugins/license_management/server/plugin.ts b/x-pack/plugins/license_management/server/plugin.ts index 9546f5b1ef88a9..7b1887e4380245 100644 --- a/x-pack/plugins/license_management/server/plugin.ts +++ b/x-pack/plugins/license_management/server/plugin.ts @@ -7,7 +7,7 @@ import { Plugin, CoreSetup } from 'kibana/server'; import { ApiRoutes } from './routes'; -import { isEsError } from './lib/is_es_error'; +import { isEsError } from './shared_imports'; import { Dependencies } from './types'; export class LicenseManagementServerPlugin implements Plugin { diff --git a/x-pack/plugins/license_management/server/shared_imports.ts b/x-pack/plugins/license_management/server/shared_imports.ts new file mode 100644 index 00000000000000..454beda5394c71 --- /dev/null +++ b/x-pack/plugins/license_management/server/shared_imports.ts @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export { isEsError } from '../../../../src/plugins/es_ui_shared/server'; diff --git a/x-pack/plugins/license_management/server/types.ts b/x-pack/plugins/license_management/server/types.ts index 37f4781ba1e022..11b1ed696874bc 100644 --- a/x-pack/plugins/license_management/server/types.ts +++ b/x-pack/plugins/license_management/server/types.ts @@ -7,7 +7,7 @@ import { ScopedClusterClient, IRouter } from 'kibana/server'; import { LicensingPluginSetup } from '../../licensing/server'; import { SecurityPluginSetup } from '../../security/server'; -import { isEsError } from './lib/is_es_error'; +import { isEsError } from './shared_imports'; export interface Dependencies { licensing: LicensingPluginSetup; diff --git a/x-pack/plugins/painless_lab/server/lib/is_es_error.ts b/x-pack/plugins/painless_lab/server/lib/is_es_error.ts deleted file mode 100644 index 4137293cf39c06..00000000000000 --- a/x-pack/plugins/painless_lab/server/lib/is_es_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import * as legacyElasticsearch from 'elasticsearch'; - -const esErrorsParent = legacyElasticsearch.errors._Abstract; - -export function isEsError(err: Error) { - return err instanceof esErrorsParent; -} diff --git a/x-pack/plugins/painless_lab/server/routes/api/execute.ts b/x-pack/plugins/painless_lab/server/routes/api/execute.ts index 7d415761f04cb2..7bb2d9f93c6fcf 100644 --- a/x-pack/plugins/painless_lab/server/routes/api/execute.ts +++ b/x-pack/plugins/painless_lab/server/routes/api/execute.ts @@ -7,7 +7,7 @@ import { schema } from '@kbn/config-schema'; import { API_BASE_PATH } from '../../../common/constants'; import { RouteDependencies } from '../../types'; -import { isEsError } from '../../lib'; +import { isEsError } from '../../shared_imports'; const bodySchema = schema.string(); diff --git a/x-pack/plugins/painless_lab/server/shared_imports.ts b/x-pack/plugins/painless_lab/server/shared_imports.ts new file mode 100644 index 00000000000000..454beda5394c71 --- /dev/null +++ b/x-pack/plugins/painless_lab/server/shared_imports.ts @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export { isEsError } from '../../../../src/plugins/es_ui_shared/server'; diff --git a/x-pack/plugins/remote_clusters/server/lib/is_es_error/is_es_error.ts b/x-pack/plugins/remote_clusters/server/lib/is_es_error/is_es_error.ts deleted file mode 100644 index 4137293cf39c06..00000000000000 --- a/x-pack/plugins/remote_clusters/server/lib/is_es_error/is_es_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import * as legacyElasticsearch from 'elasticsearch'; - -const esErrorsParent = legacyElasticsearch.errors._Abstract; - -export function isEsError(err: Error) { - return err instanceof esErrorsParent; -} diff --git a/x-pack/plugins/remote_clusters/server/routes/api/add_route.ts b/x-pack/plugins/remote_clusters/server/routes/api/add_route.ts index 38f11db18a0889..c28d9f323cb571 100644 --- a/x-pack/plugins/remote_clusters/server/routes/api/add_route.ts +++ b/x-pack/plugins/remote_clusters/server/routes/api/add_route.ts @@ -13,7 +13,7 @@ import { serializeCluster, Cluster } from '../../../common/lib'; import { doesClusterExist } from '../../lib/does_cluster_exist'; import { API_BASE_PATH, PROXY_MODE, SNIFF_MODE } from '../../../common/constants'; import { licensePreRoutingFactory } from '../../lib/license_pre_routing_factory'; -import { isEsError } from '../../lib/is_es_error'; +import { isEsError } from '../../shared_imports'; import { RouteDependencies } from '../../types'; const bodyValidation = schema.object({ diff --git a/x-pack/plugins/remote_clusters/server/routes/api/delete_route.ts b/x-pack/plugins/remote_clusters/server/routes/api/delete_route.ts index 69760b7477e1b6..030e7587f870df 100644 --- a/x-pack/plugins/remote_clusters/server/routes/api/delete_route.ts +++ b/x-pack/plugins/remote_clusters/server/routes/api/delete_route.ts @@ -14,7 +14,7 @@ import { serializeCluster } from '../../../common/lib'; import { API_BASE_PATH } from '../../../common/constants'; import { doesClusterExist } from '../../lib/does_cluster_exist'; import { licensePreRoutingFactory } from '../../lib/license_pre_routing_factory'; -import { isEsError } from '../../lib/is_es_error'; +import { isEsError } from '../../shared_imports'; const paramsValidation = schema.object({ nameOrNames: schema.string(), diff --git a/x-pack/plugins/remote_clusters/server/routes/api/get_route.ts b/x-pack/plugins/remote_clusters/server/routes/api/get_route.ts index 4e3fa34ac94c3d..3ebb136356645d 100644 --- a/x-pack/plugins/remote_clusters/server/routes/api/get_route.ts +++ b/x-pack/plugins/remote_clusters/server/routes/api/get_route.ts @@ -10,7 +10,7 @@ import { RequestHandler } from 'src/core/server'; import { deserializeCluster } from '../../../common/lib'; import { API_BASE_PATH } from '../../../common/constants'; import { licensePreRoutingFactory } from '../../lib/license_pre_routing_factory'; -import { isEsError } from '../../lib/is_es_error'; +import { isEsError } from '../../shared_imports'; import { RouteDependencies } from '../../types'; export const register = (deps: RouteDependencies): void => { diff --git a/x-pack/plugins/remote_clusters/server/routes/api/update_route.ts b/x-pack/plugins/remote_clusters/server/routes/api/update_route.ts index 0666a295de456f..60671b4a800756 100644 --- a/x-pack/plugins/remote_clusters/server/routes/api/update_route.ts +++ b/x-pack/plugins/remote_clusters/server/routes/api/update_route.ts @@ -14,7 +14,7 @@ import { serializeCluster, deserializeCluster, Cluster, ClusterInfoEs } from '.. import { doesClusterExist } from '../../lib/does_cluster_exist'; import { RouteDependencies } from '../../types'; import { licensePreRoutingFactory } from '../../lib/license_pre_routing_factory'; -import { isEsError } from '../../lib/is_es_error'; +import { isEsError } from '../../shared_imports'; const bodyValidation = schema.object({ skipUnavailable: schema.boolean(), diff --git a/x-pack/plugins/remote_clusters/server/shared_imports.ts b/x-pack/plugins/remote_clusters/server/shared_imports.ts new file mode 100644 index 00000000000000..454beda5394c71 --- /dev/null +++ b/x-pack/plugins/remote_clusters/server/shared_imports.ts @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export { isEsError } from '../../../../src/plugins/es_ui_shared/server'; diff --git a/x-pack/plugins/rollup/server/lib/is_es_error.ts b/x-pack/plugins/rollup/server/lib/is_es_error.ts deleted file mode 100644 index 4137293cf39c06..00000000000000 --- a/x-pack/plugins/rollup/server/lib/is_es_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import * as legacyElasticsearch from 'elasticsearch'; - -const esErrorsParent = legacyElasticsearch.errors._Abstract; - -export function isEsError(err: Error) { - return err instanceof esErrorsParent; -} diff --git a/x-pack/plugins/rollup/server/plugin.ts b/x-pack/plugins/rollup/server/plugin.ts index f5ddab70342deb..0d795ab7dbfe1d 100644 --- a/x-pack/plugins/rollup/server/plugin.ts +++ b/x-pack/plugins/rollup/server/plugin.ts @@ -35,7 +35,7 @@ import { rollupDataEnricher } from './rollup_data_enricher'; import { IndexPatternsFetcher } from './shared_imports'; import { registerRollupSearchStrategy } from './lib/search_strategies'; import { elasticsearchJsPlugin } from './client/elasticsearch_rollup'; -import { isEsError } from './lib/is_es_error'; +import { isEsError } from './shared_imports'; import { formatEsError } from './lib/format_es_error'; import { getCapabilitiesForRollupIndices } from './lib/map_capabilities'; import { mergeCapabilitiesWithFields } from './lib/merge_capabilities_with_fields'; diff --git a/x-pack/plugins/rollup/server/shared_imports.ts b/x-pack/plugins/rollup/server/shared_imports.ts index 09842f529abed3..1e39a323186782 100644 --- a/x-pack/plugins/rollup/server/shared_imports.ts +++ b/x-pack/plugins/rollup/server/shared_imports.ts @@ -5,3 +5,5 @@ */ export { IndexPatternsFetcher } from '../../../../src/plugins/data/server'; + +export { isEsError } from '../../../../src/plugins/es_ui_shared/server'; diff --git a/x-pack/plugins/rollup/server/types.ts b/x-pack/plugins/rollup/server/types.ts index c21d76400164ea..6659ac2b023579 100644 --- a/x-pack/plugins/rollup/server/types.ts +++ b/x-pack/plugins/rollup/server/types.ts @@ -12,7 +12,7 @@ import { IndexManagementPluginSetup } from '../../index_management/server'; import { LicensingPluginSetup } from '../../licensing/server'; import { License } from './services'; import { IndexPatternsFetcher } from './shared_imports'; -import { isEsError } from './lib/is_es_error'; +import { isEsError } from './shared_imports'; import { formatEsError } from './lib/format_es_error'; import { getCapabilitiesForRollupIndices } from './lib/map_capabilities'; import { mergeCapabilitiesWithFields } from './lib/merge_capabilities_with_fields'; diff --git a/x-pack/plugins/snapshot_restore/server/lib/index.ts b/x-pack/plugins/snapshot_restore/server/lib/index.ts index 801f105fc5c07c..4bec874b3abc7c 100644 --- a/x-pack/plugins/snapshot_restore/server/lib/index.ts +++ b/x-pack/plugins/snapshot_restore/server/lib/index.ts @@ -12,5 +12,4 @@ export { cleanSettings } from './clean_settings'; export { getManagedRepositoryName } from './get_managed_repository_name'; export { getManagedPolicyNames } from './get_managed_policy_names'; export { deserializeRestoreShard } from './restore_serialization'; -export { isEsError } from './is_es_error'; export { wrapEsError } from './wrap_es_error'; diff --git a/x-pack/plugins/snapshot_restore/server/lib/is_es_error.ts b/x-pack/plugins/snapshot_restore/server/lib/is_es_error.ts deleted file mode 100644 index 4137293cf39c06..00000000000000 --- a/x-pack/plugins/snapshot_restore/server/lib/is_es_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import * as legacyElasticsearch from 'elasticsearch'; - -const esErrorsParent = legacyElasticsearch.errors._Abstract; - -export function isEsError(err: Error) { - return err instanceof esErrorsParent; -} diff --git a/x-pack/plugins/snapshot_restore/server/plugin.ts b/x-pack/plugins/snapshot_restore/server/plugin.ts index 1d28442332c55a..10d259e28ee43b 100644 --- a/x-pack/plugins/snapshot_restore/server/plugin.ts +++ b/x-pack/plugins/snapshot_restore/server/plugin.ts @@ -23,7 +23,8 @@ import { import { PLUGIN } from '../common'; import { License } from './services'; import { ApiRoutes } from './routes'; -import { isEsError, wrapEsError } from './lib'; +import { wrapEsError } from './lib'; +import { isEsError } from './shared_imports'; import { elasticsearchJsPlugin } from './client/elasticsearch_sr'; import { Dependencies } from './types'; import { SnapshotRestoreConfig } from './config'; diff --git a/x-pack/plugins/snapshot_restore/server/shared_imports.ts b/x-pack/plugins/snapshot_restore/server/shared_imports.ts new file mode 100644 index 00000000000000..454beda5394c71 --- /dev/null +++ b/x-pack/plugins/snapshot_restore/server/shared_imports.ts @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export { isEsError } from '../../../../src/plugins/es_ui_shared/server'; diff --git a/x-pack/plugins/snapshot_restore/server/test/helpers/route_dependencies.ts b/x-pack/plugins/snapshot_restore/server/test/helpers/route_dependencies.ts index a4c7ecac953d8c..02ee0228922607 100644 --- a/x-pack/plugins/snapshot_restore/server/test/helpers/route_dependencies.ts +++ b/x-pack/plugins/snapshot_restore/server/test/helpers/route_dependencies.ts @@ -4,7 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ import { License } from '../../services'; -import { isEsError, wrapEsError } from '../../lib'; +import { wrapEsError } from '../../lib'; +import { isEsError } from '../../shared_imports'; const license = new License(); license.getStatus = jest.fn().mockReturnValue({ isValid: true }); diff --git a/x-pack/plugins/snapshot_restore/server/types.ts b/x-pack/plugins/snapshot_restore/server/types.ts index 71d8dda7bc50db..9710f812abf234 100644 --- a/x-pack/plugins/snapshot_restore/server/types.ts +++ b/x-pack/plugins/snapshot_restore/server/types.ts @@ -8,7 +8,8 @@ import { LicensingPluginSetup } from '../../licensing/server'; import { SecurityPluginSetup } from '../../security/server'; import { CloudSetup } from '../../cloud/server'; import { License } from './services'; -import { isEsError, wrapEsError } from './lib'; +import { wrapEsError } from './lib'; +import { isEsError } from './shared_imports'; export interface Dependencies { licensing: LicensingPluginSetup; diff --git a/x-pack/plugins/watcher/server/lib/is_es_error/is_es_error.ts b/x-pack/plugins/watcher/server/lib/is_es_error/is_es_error.ts deleted file mode 100644 index 4137293cf39c06..00000000000000 --- a/x-pack/plugins/watcher/server/lib/is_es_error/is_es_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import * as legacyElasticsearch from 'elasticsearch'; - -const esErrorsParent = legacyElasticsearch.errors._Abstract; - -export function isEsError(err: Error) { - return err instanceof esErrorsParent; -} diff --git a/x-pack/plugins/watcher/server/routes/api/indices/register_get_route.ts b/x-pack/plugins/watcher/server/routes/api/indices/register_get_route.ts index a1184cbebd1390..6d5b359b53d396 100644 --- a/x-pack/plugins/watcher/server/routes/api/indices/register_get_route.ts +++ b/x-pack/plugins/watcher/server/routes/api/indices/register_get_route.ts @@ -7,7 +7,7 @@ import { schema } from '@kbn/config-schema'; import { IScopedClusterClient } from 'kibana/server'; import { reduce, size } from 'lodash'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { RouteDependencies } from '../../../types'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; diff --git a/x-pack/plugins/watcher/server/routes/api/register_list_fields_route.ts b/x-pack/plugins/watcher/server/routes/api/register_list_fields_route.ts index d72e5ad2f817de..e3c82ef3965f45 100644 --- a/x-pack/plugins/watcher/server/routes/api/register_list_fields_route.ts +++ b/x-pack/plugins/watcher/server/routes/api/register_list_fields_route.ts @@ -6,7 +6,7 @@ import { schema } from '@kbn/config-schema'; import { IScopedClusterClient } from 'kibana/server'; -import { isEsError } from '../../lib/is_es_error'; +import { isEsError } from '../../shared_imports'; // @ts-ignore import { Fields } from '../../models/fields/index'; import { licensePreRoutingFactory } from '../../lib/license_pre_routing_factory'; diff --git a/x-pack/plugins/watcher/server/routes/api/register_load_history_route.ts b/x-pack/plugins/watcher/server/routes/api/register_load_history_route.ts index 8c9068123ce8d7..c61953db555d3e 100644 --- a/x-pack/plugins/watcher/server/routes/api/register_load_history_route.ts +++ b/x-pack/plugins/watcher/server/routes/api/register_load_history_route.ts @@ -7,7 +7,7 @@ import { schema } from '@kbn/config-schema'; import { get } from 'lodash'; import { IScopedClusterClient } from 'kibana/server'; -import { isEsError } from '../../lib/is_es_error'; +import { isEsError } from '../../shared_imports'; import { INDEX_NAMES } from '../../../common/constants'; import { RouteDependencies } from '../../types'; import { licensePreRoutingFactory } from '../../lib/license_pre_routing_factory'; diff --git a/x-pack/plugins/watcher/server/routes/api/settings/register_load_route.ts b/x-pack/plugins/watcher/server/routes/api/settings/register_load_route.ts index fe9dd32735692d..9f501b56d47030 100644 --- a/x-pack/plugins/watcher/server/routes/api/settings/register_load_route.ts +++ b/x-pack/plugins/watcher/server/routes/api/settings/register_load_route.ts @@ -5,7 +5,7 @@ */ import { IScopedClusterClient } from 'kibana/server'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; // @ts-ignore import { Settings } from '../../../models/settings/index'; import { RouteDependencies } from '../../../types'; diff --git a/x-pack/plugins/watcher/server/routes/api/watch/action/register_acknowledge_route.ts b/x-pack/plugins/watcher/server/routes/api/watch/action/register_acknowledge_route.ts index 9e024a63b82c57..923714739065ee 100644 --- a/x-pack/plugins/watcher/server/routes/api/watch/action/register_acknowledge_route.ts +++ b/x-pack/plugins/watcher/server/routes/api/watch/action/register_acknowledge_route.ts @@ -7,7 +7,7 @@ import { schema } from '@kbn/config-schema'; import { get } from 'lodash'; import { IScopedClusterClient } from 'kibana/server'; -import { isEsError } from '../../../../lib/is_es_error'; +import { isEsError } from '../../../../shared_imports'; // @ts-ignore import { WatchStatus } from '../../../../models/watch_status/index'; import { RouteDependencies } from '../../../../types'; diff --git a/x-pack/plugins/watcher/server/routes/api/watch/register_activate_route.ts b/x-pack/plugins/watcher/server/routes/api/watch/register_activate_route.ts index 1afeeb4e80efbf..e7e3f5e3d9ba3a 100644 --- a/x-pack/plugins/watcher/server/routes/api/watch/register_activate_route.ts +++ b/x-pack/plugins/watcher/server/routes/api/watch/register_activate_route.ts @@ -7,7 +7,7 @@ import { schema } from '@kbn/config-schema'; import { IScopedClusterClient } from 'kibana/server'; import { get } from 'lodash'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { RouteDependencies } from '../../../types'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; // @ts-ignore diff --git a/x-pack/plugins/watcher/server/routes/api/watch/register_deactivate_route.ts b/x-pack/plugins/watcher/server/routes/api/watch/register_deactivate_route.ts index 3171d8ee2e1e55..de4b1dbb4b44db 100644 --- a/x-pack/plugins/watcher/server/routes/api/watch/register_deactivate_route.ts +++ b/x-pack/plugins/watcher/server/routes/api/watch/register_deactivate_route.ts @@ -7,7 +7,7 @@ import { schema } from '@kbn/config-schema'; import { IScopedClusterClient } from 'kibana/server'; import { get } from 'lodash'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { RouteDependencies } from '../../../types'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; // @ts-ignore diff --git a/x-pack/plugins/watcher/server/routes/api/watch/register_delete_route.ts b/x-pack/plugins/watcher/server/routes/api/watch/register_delete_route.ts index bfdf328550bbea..9f43d311a182fc 100644 --- a/x-pack/plugins/watcher/server/routes/api/watch/register_delete_route.ts +++ b/x-pack/plugins/watcher/server/routes/api/watch/register_delete_route.ts @@ -6,7 +6,7 @@ import { schema } from '@kbn/config-schema'; import { IScopedClusterClient } from 'kibana/server'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { RouteDependencies } from '../../../types'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; diff --git a/x-pack/plugins/watcher/server/routes/api/watch/register_execute_route.ts b/x-pack/plugins/watcher/server/routes/api/watch/register_execute_route.ts index 14a14a6f64d7b4..9f27f3ca35bf6d 100644 --- a/x-pack/plugins/watcher/server/routes/api/watch/register_execute_route.ts +++ b/x-pack/plugins/watcher/server/routes/api/watch/register_execute_route.ts @@ -7,7 +7,7 @@ import { schema } from '@kbn/config-schema'; import { IScopedClusterClient } from 'kibana/server'; import { get } from 'lodash'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; import { RouteDependencies } from '../../../types'; diff --git a/x-pack/plugins/watcher/server/routes/api/watch/register_history_route.ts b/x-pack/plugins/watcher/server/routes/api/watch/register_history_route.ts index b64c28e114b72c..faa860b3ce6dd9 100644 --- a/x-pack/plugins/watcher/server/routes/api/watch/register_history_route.ts +++ b/x-pack/plugins/watcher/server/routes/api/watch/register_history_route.ts @@ -9,7 +9,7 @@ import { IScopedClusterClient } from 'kibana/server'; import { get } from 'lodash'; import { fetchAllFromScroll } from '../../../lib/fetch_all_from_scroll'; import { INDEX_NAMES, ES_SCROLL_SETTINGS } from '../../../../common/constants'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { RouteDependencies } from '../../../types'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; // @ts-ignore diff --git a/x-pack/plugins/watcher/server/routes/api/watch/register_load_route.ts b/x-pack/plugins/watcher/server/routes/api/watch/register_load_route.ts index 6363054921333f..d8905bcebeef33 100644 --- a/x-pack/plugins/watcher/server/routes/api/watch/register_load_route.ts +++ b/x-pack/plugins/watcher/server/routes/api/watch/register_load_route.ts @@ -7,7 +7,7 @@ import { schema } from '@kbn/config-schema'; import { IScopedClusterClient } from 'kibana/server'; import { get } from 'lodash'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; // @ts-ignore import { Watch } from '../../../models/watch/index'; diff --git a/x-pack/plugins/watcher/server/routes/api/watch/register_save_route.ts b/x-pack/plugins/watcher/server/routes/api/watch/register_save_route.ts index 10ee0c4857862b..d3054bfb3ce8c1 100644 --- a/x-pack/plugins/watcher/server/routes/api/watch/register_save_route.ts +++ b/x-pack/plugins/watcher/server/routes/api/watch/register_save_route.ts @@ -8,7 +8,7 @@ import { schema } from '@kbn/config-schema'; import { i18n } from '@kbn/i18n'; import { WATCH_TYPES } from '../../../../common/constants'; import { serializeJsonWatch, serializeThresholdWatch } from '../../../../common/lib/serialization'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { RouteDependencies } from '../../../types'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; diff --git a/x-pack/plugins/watcher/server/routes/api/watch/register_visualize_route.ts b/x-pack/plugins/watcher/server/routes/api/watch/register_visualize_route.ts index 90550731bf23a2..2eb6d270e808a3 100644 --- a/x-pack/plugins/watcher/server/routes/api/watch/register_visualize_route.ts +++ b/x-pack/plugins/watcher/server/routes/api/watch/register_visualize_route.ts @@ -6,7 +6,7 @@ import { schema } from '@kbn/config-schema'; import { IScopedClusterClient } from 'kibana/server'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { RouteDependencies } from '../../../types'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; diff --git a/x-pack/plugins/watcher/server/routes/api/watches/register_list_route.ts b/x-pack/plugins/watcher/server/routes/api/watches/register_list_route.ts index 5e823a0a8d2de6..ca93221bf1de77 100644 --- a/x-pack/plugins/watcher/server/routes/api/watches/register_list_route.ts +++ b/x-pack/plugins/watcher/server/routes/api/watches/register_list_route.ts @@ -8,7 +8,7 @@ import { IScopedClusterClient } from 'kibana/server'; import { get } from 'lodash'; import { fetchAllFromScroll } from '../../../lib/fetch_all_from_scroll'; import { INDEX_NAMES, ES_SCROLL_SETTINGS } from '../../../../common/constants'; -import { isEsError } from '../../../lib/is_es_error'; +import { isEsError } from '../../../shared_imports'; import { RouteDependencies } from '../../../types'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; // @ts-ignore diff --git a/x-pack/plugins/watcher/server/shared_imports.ts b/x-pack/plugins/watcher/server/shared_imports.ts new file mode 100644 index 00000000000000..454beda5394c71 --- /dev/null +++ b/x-pack/plugins/watcher/server/shared_imports.ts @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export { isEsError } from '../../../../src/plugins/es_ui_shared/server'; From 99a868a1259239896bfa0b9b5e16188bf36f0929 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Mon, 15 Jun 2020 14:56:33 +0200 Subject: [PATCH 02/82] [Console] Scrub the lead and trailing brackets from ipv6 host names (#68991) * scrub the lead and trailing brackets from ipv6 host names * Update comment * refactor: scrub -> sanitize Co-authored-by: Elastic Machine --- src/plugins/console/server/lib/proxy_request.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/plugins/console/server/lib/proxy_request.ts b/src/plugins/console/server/lib/proxy_request.ts index 4c6c7c21f32a49..fb07b7c49a0038 100644 --- a/src/plugins/console/server/lib/proxy_request.ts +++ b/src/plugins/console/server/lib/proxy_request.ts @@ -34,6 +34,13 @@ interface Args { rejectUnauthorized?: boolean; } +/** + * Node http request library does not expect there to be trailing "[" or "]" + * characters in ipv6 host names. + */ +const sanitizeHostname = (hostName: string): string => + hostName.trim().replace(/^\[/, '').replace(/\]$/, ''); + // We use a modified version of Hapi's Wreck because Hapi, Axios, and Superagent don't support GET requests // with bodies, but ES APIs do. Similarly with DELETE requests with bodies. Another library, `request` // diverged too much from current behaviour. @@ -67,7 +74,7 @@ export const proxyRequest = ({ method: method.toUpperCase(), // We support overriding this on a per request basis to support legacy proxy config. See ./proxy_config. rejectUnauthorized: typeof rejectUnauthorized === 'boolean' ? rejectUnauthorized : undefined, - host: hostname, + host: sanitizeHostname(hostname), port: port === '' ? undefined : parseInt(port, 10), protocol, path: `${pathname}${search || ''}`, From 4e864268ce7fb6feda1e9f0cae88597b7b75efc8 Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Mon, 15 Jun 2020 15:57:20 +0300 Subject: [PATCH 03/82] fix spec color highlighting not working on vega vis (#68995) Co-authored-by: Elastic Machine --- src/plugins/vis_type_vega/public/components/vega_vis_editor.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/vis_type_vega/public/components/vega_vis_editor.tsx b/src/plugins/vis_type_vega/public/components/vega_vis_editor.tsx index 31144065d7b40b..1da5e7544850a0 100644 --- a/src/plugins/vis_type_vega/public/components/vega_vis_editor.tsx +++ b/src/plugins/vis_type_vega/public/components/vega_vis_editor.tsx @@ -22,6 +22,7 @@ import { EuiCodeEditor } from '@elastic/eui'; import compactStringify from 'json-stringify-pretty-compact'; // @ts-ignore import hjson from 'hjson'; +import 'brace/mode/hjson'; import { i18n } from '@kbn/i18n'; import { VisOptionsProps } from 'src/plugins/vis_default_editor/public'; From 46ed40ec075e397a0600d735e114c56c298093d4 Mon Sep 17 00:00:00 2001 From: Xavier Mouligneau <189600+XavierM@users.noreply.github.com> Date: Mon, 15 Jun 2020 09:16:52 -0400 Subject: [PATCH 04/82] [SECURITY] rename server plugin to siem (#69044) * rename server plugin to siem to avoid privilege issue * review from alerting * missing change with rename * fix tests * missing api integration test * fix api integration spaces --- x-pack/plugins/security_solution/common/constants.ts | 1 + .../alerts/components/user_info/index.test.tsx | 2 +- .../public/alerts/components/user_info/index.tsx | 4 +--- .../public/common/lib/kibana/hooks.ts | 8 ++------ .../flyout/header_with_close_button/index.test.tsx | 2 +- .../components/timeline/properties/helpers.test.tsx | 2 +- .../components/timeline/properties/helpers.tsx | 2 +- .../components/timeline/properties/index.test.tsx | 2 +- .../properties/new_template_timeline.test.tsx | 4 ++-- .../timeline/properties/new_template_timeline.tsx | 2 +- .../timeline/properties/properties_right.test.tsx | 12 ++++++------ .../timeline/properties/properties_right.tsx | 2 +- .../public/timelines/pages/timelines_page.test.tsx | 4 ++-- .../public/timelines/pages/timelines_page.tsx | 2 +- .../notifications/rules_notification_alert_type.ts | 4 ++-- .../signals/signal_rule_alert_type.ts | 8 ++++++-- x-pack/plugins/security_solution/server/plugin.ts | 4 ++-- .../apis/features/features/features.ts | 2 +- .../test/api_integration/apis/security/privileges.ts | 2 +- .../apis/security/privileges_basic.ts | 2 +- .../apis/security_solution/feature_controls.ts | 2 +- 21 files changed, 36 insertions(+), 37 deletions(-) diff --git a/x-pack/plugins/security_solution/common/constants.ts b/x-pack/plugins/security_solution/common/constants.ts index 7a2b531346ac34..d7f271535228c2 100644 --- a/x-pack/plugins/security_solution/common/constants.ts +++ b/x-pack/plugins/security_solution/common/constants.ts @@ -5,6 +5,7 @@ */ export const APP_ID = 'securitySolution'; +export const SERVER_APP_ID = 'siem'; export const APP_NAME = 'Security'; export const APP_ICON = 'securityAnalyticsApp'; export const APP_PATH = `/app/security`; diff --git a/x-pack/plugins/security_solution/public/alerts/components/user_info/index.test.tsx b/x-pack/plugins/security_solution/public/alerts/components/user_info/index.test.tsx index 1d0f0e2e24f773..b01edac2605eb6 100644 --- a/x-pack/plugins/security_solution/public/alerts/components/user_info/index.test.tsx +++ b/x-pack/plugins/security_solution/public/alerts/components/user_info/index.test.tsx @@ -22,7 +22,7 @@ describe('useUserInfo', () => { services: { application: { capabilities: { - securitySolution: { + siem: { crud: true, }, }, diff --git a/x-pack/plugins/security_solution/public/alerts/components/user_info/index.tsx b/x-pack/plugins/security_solution/public/alerts/components/user_info/index.tsx index fc3fec7c29c1fe..50348578cb039a 100644 --- a/x-pack/plugins/security_solution/public/alerts/components/user_info/index.tsx +++ b/x-pack/plugins/security_solution/public/alerts/components/user_info/index.tsx @@ -163,9 +163,7 @@ export const useUserInfo = (): State => { const uiCapabilities = useKibana().services.application.capabilities; const capabilitiesCanUserCRUD: boolean = - typeof uiCapabilities.securitySolution.crud === 'boolean' - ? uiCapabilities.securitySolution.crud - : false; + typeof uiCapabilities.siem.crud === 'boolean' ? uiCapabilities.siem.crud : false; useEffect(() => { if (loading !== privilegeLoading || indexNameLoading) { diff --git a/x-pack/plugins/security_solution/public/common/lib/kibana/hooks.ts b/x-pack/plugins/security_solution/public/common/lib/kibana/hooks.ts index bc16e8334e81cd..813907d9af4164 100644 --- a/x-pack/plugins/security_solution/public/common/lib/kibana/hooks.ts +++ b/x-pack/plugins/security_solution/public/common/lib/kibana/hooks.ts @@ -113,13 +113,9 @@ export const useGetUserSavedObjectPermissions = () => { useEffect(() => { const capabilitiesCanUserCRUD: boolean = - typeof uiCapabilities.securitySolution.crud === 'boolean' - ? uiCapabilities.securitySolution.crud - : false; + typeof uiCapabilities.siem.crud === 'boolean' ? uiCapabilities.siem.crud : false; const capabilitiesCanUserRead: boolean = - typeof uiCapabilities.securitySolution.show === 'boolean' - ? uiCapabilities.securitySolution.show - : false; + typeof uiCapabilities.siem.show === 'boolean' ? uiCapabilities.siem.show : false; setSavedObjectsPermissions({ crud: capabilitiesCanUserCRUD, read: capabilitiesCanUserRead, diff --git a/x-pack/plugins/security_solution/public/timelines/components/flyout/header_with_close_button/index.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/flyout/header_with_close_button/index.test.tsx index e5fc8b68b1cb7a..ddb8fb023195a4 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/flyout/header_with_close_button/index.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/flyout/header_with_close_button/index.test.tsx @@ -20,7 +20,7 @@ jest.mock('../../../../common/lib/kibana', () => ({ services: { application: { capabilities: { - securitySolution: { + siem: { crud: true, }, }, diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/helpers.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/helpers.test.tsx index fb91bbd5a11240..d8c9d2ed02cc6e 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/helpers.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/helpers.test.tsx @@ -18,7 +18,7 @@ jest.mock('../../../../common/lib/kibana', () => { services: { application: { capabilities: { - securitySolution: { + siem: { crud: true, }, }, diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/helpers.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/helpers.tsx index 00a0e573248415..4d5c16dc30b8e5 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/helpers.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/helpers.tsx @@ -222,7 +222,7 @@ export interface NewTimelineProps { export const NewTimeline = React.memo( ({ closeGearMenu, outline = false, timelineId, title = i18n.NEW_TIMELINE }) => { const uiCapabilities = useKibana().services.application.capabilities; - const capabilitiesCanUserCRUD: boolean = !!uiCapabilities.securitySolution.crud; + const capabilitiesCanUserCRUD: boolean = !!uiCapabilities.siem.crud; const { getButton } = useCreateTimelineButton({ timelineId, diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/index.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/index.test.tsx index 505d0b8cba8548..660beffd9a0893 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/index.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/index.test.tsx @@ -30,7 +30,7 @@ jest.mock('../../../../common/lib/kibana', () => { services: { application: { capabilities: { - securitySolution: { + siem: { crud: true, }, }, diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/new_template_timeline.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/new_template_timeline.test.tsx index b9b6dadf6f9d70..879302d4a92c1f 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/new_template_timeline.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/new_template_timeline.test.tsx @@ -35,7 +35,7 @@ describe('NewTemplateTimeline', () => { services: { application: { capabilities: { - securitySolution: { + siem: { crud: true, }, }, @@ -76,7 +76,7 @@ describe('NewTemplateTimeline', () => { services: { application: { capabilities: { - securitySolution: { + siem: { crud: false, }, }, diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/new_template_timeline.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/new_template_timeline.tsx index 45b2ce62fb85b0..e88ecee81d364f 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/new_template_timeline.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/new_template_timeline.tsx @@ -25,7 +25,7 @@ export const NewTemplateTimelineComponent: React.FC = ({ timelineId = 'timeline-1', }) => { const uiCapabilities = useKibana().services.application.capabilities; - const capabilitiesCanUserCRUD: boolean = !!uiCapabilities.securitySolution.crud; + const capabilitiesCanUserCRUD: boolean = !!uiCapabilities.siem.crud; const { getButton } = useCreateTimelineButton({ timelineId, diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/properties_right.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/properties_right.test.tsx index e297a3cc595d6d..ae167515495f7e 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/properties_right.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/properties_right.test.tsx @@ -78,7 +78,7 @@ describe('Properties Right', () => { services: { application: { capabilities: { - securitySolution: { + siem: { crud: true, }, }, @@ -129,7 +129,7 @@ describe('Properties Right', () => { services: { application: { capabilities: { - securitySolution: { + siem: { crud: true, }, }, @@ -158,7 +158,7 @@ describe('Properties Right', () => { services: { application: { capabilities: { - securitySolution: { + siem: { crud: true, }, }, @@ -189,7 +189,7 @@ describe('Properties Right', () => { services: { application: { capabilities: { - securitySolution: { + siem: { crud: false, }, }, @@ -236,7 +236,7 @@ describe('Properties Right', () => { services: { application: { capabilities: { - securitySolution: { + siem: { crud: false, }, }, @@ -265,7 +265,7 @@ describe('Properties Right', () => { services: { application: { capabilities: { - securitySolution: { + siem: { crud: false, }, }, diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/properties_right.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/properties_right.tsx index a9baf73676ffb1..7d176d57b5d818 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/properties_right.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/properties_right.tsx @@ -116,7 +116,7 @@ const PropertiesRightComponent: React.FC = ({ usersViewing, }) => { const uiCapabilities = useKibana().services.application.capabilities; - const capabilitiesCanUserCRUD: boolean = !!uiCapabilities.securitySolution.crud; + const capabilitiesCanUserCRUD: boolean = !!uiCapabilities.siem.crud; return ( diff --git a/x-pack/plugins/security_solution/public/timelines/pages/timelines_page.test.tsx b/x-pack/plugins/security_solution/public/timelines/pages/timelines_page.test.tsx index e7b66c4e8addbc..3a5e3b56e5cc47 100644 --- a/x-pack/plugins/security_solution/public/timelines/pages/timelines_page.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/pages/timelines_page.test.tsx @@ -30,7 +30,7 @@ describe('TimelinesPageComponent', () => { services: { application: { capabilities: { - securitySolution: { + siem: { crud: true, }, }, @@ -82,7 +82,7 @@ describe('TimelinesPageComponent', () => { services: { application: { capabilities: { - securitySolution: { + siem: { crud: false, }, }, diff --git a/x-pack/plugins/security_solution/public/timelines/pages/timelines_page.tsx b/x-pack/plugins/security_solution/public/timelines/pages/timelines_page.tsx index 2c692d850cd162..95a2e4f5fd0ee9 100644 --- a/x-pack/plugins/security_solution/public/timelines/pages/timelines_page.tsx +++ b/x-pack/plugins/security_solution/public/timelines/pages/timelines_page.tsx @@ -42,7 +42,7 @@ export const TimelinesPageComponent: React.FC = ({ apolloClient }) => }, [setImportDataModalToggle]); const uiCapabilities = useKibana().services.application.capabilities; - const capabilitiesCanUserCRUD: boolean = !!uiCapabilities.securitySolution.crud; + const capabilitiesCanUserCRUD: boolean = !!uiCapabilities.siem.crud; return ( <> diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/notifications/rules_notification_alert_type.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/notifications/rules_notification_alert_type.ts index cf5a6aa01f29e8..ab824957087fc1 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/notifications/rules_notification_alert_type.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/notifications/rules_notification_alert_type.ts @@ -6,7 +6,7 @@ import { Logger } from 'src/core/server'; import { schema } from '@kbn/config-schema'; -import { NOTIFICATIONS_ID } from '../../../../common/constants'; +import { NOTIFICATIONS_ID, SERVER_APP_ID } from '../../../../common/constants'; import { NotificationAlertTypeDefinition } from './types'; import { getSignalsCount } from './get_signals_count'; @@ -25,7 +25,7 @@ export const rulesNotificationAlertType = ({ name: 'SIEM notification', actionGroups: siemRuleActionGroups, defaultActionGroupId: 'default', - producer: 'siem', + producer: SERVER_APP_ID, validate: { params: schema.object({ ruleAlertId: schema.string(), diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts index 091ee54e3174e1..728bd66b7d65c6 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts @@ -8,7 +8,11 @@ import { Logger, KibanaRequest } from 'src/core/server'; -import { SIGNALS_ID, DEFAULT_SEARCH_AFTER_PAGE_SIZE } from '../../../../common/constants'; +import { + SIGNALS_ID, + DEFAULT_SEARCH_AFTER_PAGE_SIZE, + SERVER_APP_ID, +} from '../../../../common/constants'; import { isJobStarted, isMlRule } from '../../../../common/machine_learning/helpers'; import { SetupPlugins } from '../../../plugin'; @@ -55,7 +59,7 @@ export const signalRulesAlertType = ({ validate: { params: signalParamsSchema(), }, - producer: 'siem', + producer: SERVER_APP_ID, async executor({ previousStartedAt, alertId, diff --git a/x-pack/plugins/security_solution/server/plugin.ts b/x-pack/plugins/security_solution/server/plugin.ts index 00f2cba304c88d..ebb2310ac53104 100644 --- a/x-pack/plugins/security_solution/server/plugin.ts +++ b/x-pack/plugins/security_solution/server/plugin.ts @@ -36,7 +36,7 @@ import { initSavedObjects, savedObjectTypes } from './saved_objects'; import { AppClientFactory } from './client'; import { createConfig$, ConfigType } from './config'; import { initUiSettings } from './ui_settings'; -import { APP_ID, APP_ICON } from '../common/constants'; +import { APP_ID, APP_ICON, SERVER_APP_ID } from '../common/constants'; import { registerEndpointRoutes } from './endpoint/routes/metadata'; import { registerResolverRoutes } from './endpoint/routes/resolver'; import { registerAlertRoutes } from './endpoint/alerts/routes'; @@ -125,7 +125,7 @@ export class Plugin implements IPlugin Date: Mon, 15 Jun 2020 16:32:08 +0300 Subject: [PATCH 05/82] Type safe browser.executeAsync (#69018) * make browserAsync type safe * adopt tests * prefer unknown over any * simplify signature --- test/functional/services/common/browser.ts | 24 +++++++++++++++---- .../test_suites/run_pipeline/helpers.ts | 14 +++++------ .../application_links/redirect_app_links.ts | 5 ++-- .../core_plugins/application_status.ts | 6 ++--- .../test_suites/core_plugins/ui_plugins.ts | 2 +- .../test_suites/core_plugins/ui_settings.ts | 2 +- .../test/licensing_plugin/public/updates.ts | 8 +++---- .../global_search/global_search_api.ts | 8 +++---- 8 files changed, 41 insertions(+), 28 deletions(-) diff --git a/test/functional/services/common/browser.ts b/test/functional/services/common/browser.ts index 3f71c16bd3c44b..3297f6e094f7c8 100644 --- a/test/functional/services/common/browser.ts +++ b/test/functional/services/common/browser.ts @@ -479,11 +479,27 @@ export async function BrowserProvider({ getService }: FtrProviderContext) { ); } - public async executeAsync( - fn: string | ((...args: any[]) => Promise), + public async executeAsync(fn: (cb: (value?: T) => void) => void): Promise; + public async executeAsync( + fn: (a1: A1, cb: (value?: T) => void) => void, + a1: A1 + ): Promise; + public async executeAsync( + fn: (a1: A1, a2: A2, cb: (value?: T) => void) => void, + a1: A1, + a2: A2 + ): Promise; + public async executeAsync( + fn: (a1: A1, a2: A2, a3: A3, cb: (value?: T) => void) => void, + a1: A1, + a2: A2, + a3: A3 + ): Promise; + public async executeAsync( + fn: (...args: any[]) => void, ...args: any[] - ): Promise { - return await driver.executeAsyncScript( + ): Promise { + return await driver.executeAsyncScript( fn, ...cloneDeep(args, (arg) => { if (arg instanceof WebElementWrapper) { diff --git a/test/interpreter_functional/test_suites/run_pipeline/helpers.ts b/test/interpreter_functional/test_suites/run_pipeline/helpers.ts index 2486fb0e1fbd04..bbf45b003c3300 100644 --- a/test/interpreter_functional/test_suites/run_pipeline/helpers.ts +++ b/test/interpreter_functional/test_suites/run_pipeline/helpers.ts @@ -110,13 +110,13 @@ export function expectExpressionProvider({ stepContext: ExpressionValue = context ): Promise => { log.debug(`running expression ${step || expression}`); - return browser.executeAsync( - ( - _expression: string, - _currentContext: ExpressionValue & { type: string }, - _initialContext: ExpressionValue, - done: (expressionResult: ExpressionResult) => void - ) => { + return browser.executeAsync< + ExpressionResult, + string, + ExpressionValue & { type: string }, + ExpressionValue + >( + (_expression, _currentContext, _initialContext, done) => { if (!_currentContext) _currentContext = { type: 'null' }; if (!_currentContext.type) _currentContext.type = 'null'; return window diff --git a/test/plugin_functional/test_suites/application_links/redirect_app_links.ts b/test/plugin_functional/test_suites/application_links/redirect_app_links.ts index 54f7cdf1fdff55..9120018958bda7 100644 --- a/test/plugin_functional/test_suites/application_links/redirect_app_links.ts +++ b/test/plugin_functional/test_suites/application_links/redirect_app_links.ts @@ -40,16 +40,15 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide const testSubjects = getService('testSubjects'); const setNonReloadedFlag = () => { - return browser.executeAsync(async (cb: Function) => { + return browser.executeAsync(async (cb) => { window.__nonReloadedFlag = true; cb(); }); }; - const wasReloaded = (): Promise => { + const wasReloaded = () => { return browser.executeAsync(async (cb) => { const reloaded = window.__nonReloadedFlag !== true; cb(reloaded); - return reloaded; }); }; diff --git a/test/plugin_functional/test_suites/core_plugins/application_status.ts b/test/plugin_functional/test_suites/core_plugins/application_status.ts index 96bcda39f39815..31a1c28b508429 100644 --- a/test/plugin_functional/test_suites/core_plugins/application_status.ts +++ b/test/plugin_functional/test_suites/core_plugins/application_status.ts @@ -44,17 +44,17 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide const testSubjects = getService('testSubjects'); const setAppStatus = async (s: Partial) => { - return browser.executeAsync(async (status: Partial, cb: Function) => { + return browser.executeAsync(async (status, cb) => { window.__coreAppStatus.setAppStatus(status); cb(); }, s); }; const navigateToApp = async (i: string) => { - return (await browser.executeAsync(async (appId, cb: Function) => { + return await browser.executeAsync(async (appId, cb) => { await window.__coreAppStatus.navigateToApp(appId); cb(); - }, i)) as any; + }, i); }; // FLAKY: https://github.com/elastic/kibana/issues/65423 diff --git a/test/plugin_functional/test_suites/core_plugins/ui_plugins.ts b/test/plugin_functional/test_suites/core_plugins/ui_plugins.ts index 929d5b68be93d5..3a27be42a2a424 100644 --- a/test/plugin_functional/test_suites/core_plugins/ui_plugins.ts +++ b/test/plugin_functional/test_suites/core_plugins/ui_plugins.ts @@ -49,7 +49,7 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide it('to start services via coreSetup.getStartServices', async () => { expect( - await browser.executeAsync(async (cb) => { + await browser.executeAsync(async (cb) => { const [coreStart] = await window.__coreProvider.setup.core.getStartServices(); cb(Boolean(coreStart.overlays)); }) diff --git a/test/plugin_functional/test_suites/core_plugins/ui_settings.ts b/test/plugin_functional/test_suites/core_plugins/ui_settings.ts index 6a0a5fed48e6d8..3a618ceaeb22f4 100644 --- a/test/plugin_functional/test_suites/core_plugins/ui_settings.ts +++ b/test/plugin_functional/test_suites/core_plugins/ui_settings.ts @@ -49,7 +49,7 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide expect(settingsValue).to.be('2'); - const settingsValueViaObservables = await browser.executeAsync(async (callback: Function) => { + const settingsValueViaObservables = await browser.executeAsync(async (callback) => { window.__coreProvider.setup.core.uiSettings .get$('ui_settings_plugin') .subscribe((v) => callback(v)); diff --git a/x-pack/test/licensing_plugin/public/updates.ts b/x-pack/test/licensing_plugin/public/updates.ts index 4914513193cb4f..4604cfe032b0b8 100644 --- a/x-pack/test/licensing_plugin/public/updates.ts +++ b/x-pack/test/licensing_plugin/public/updates.ts @@ -27,7 +27,7 @@ export default function (ftrContext: FtrProviderContext) { await scenario.waitForPluginToDetectLicenseUpdate(); expect( - await browser.executeAsync(async (cb: Function) => { + await browser.executeAsync(async (cb) => { const { setup, testUtils } = window.__coreProvider; // this call enforces signature check to detect license update // and causes license re-fetch @@ -43,7 +43,7 @@ export default function (ftrContext: FtrProviderContext) { await scenario.waitForPluginToDetectLicenseUpdate(); expect( - await browser.executeAsync(async (cb: Function) => { + await browser.executeAsync(async (cb) => { const { setup, testUtils } = window.__coreProvider; // this call enforces signature check to detect license update // and causes license re-fetch @@ -59,7 +59,7 @@ export default function (ftrContext: FtrProviderContext) { await scenario.waitForPluginToDetectLicenseUpdate(); expect( - await browser.executeAsync(async (cb: Function) => { + await browser.executeAsync(async (cb) => { const { setup, testUtils } = window.__coreProvider; // this call enforces signature check to detect license update // and causes license re-fetch @@ -75,7 +75,7 @@ export default function (ftrContext: FtrProviderContext) { await scenario.waitForPluginToDetectLicenseUpdate(); expect( - await browser.executeAsync(async (cb: Function) => { + await browser.executeAsync(async (cb) => { const { setup, testUtils } = window.__coreProvider; // this call enforces signature check to detect license update // and causes license re-fetch diff --git a/x-pack/test/plugin_functional/test_suites/global_search/global_search_api.ts b/x-pack/test/plugin_functional/test_suites/global_search/global_search_api.ts index 4cc056fd51c2aa..ee1745436b7357 100644 --- a/x-pack/test/plugin_functional/test_suites/global_search/global_search_api.ts +++ b/x-pack/test/plugin_functional/test_suites/global_search/global_search_api.ts @@ -14,13 +14,11 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { const browser = getService('browser'); const findResultsWithAPI = async (t: string): Promise => { - return browser.executeAsync(async (term: string, cb: Function) => { + return browser.executeAsync(async (term, cb) => { const { start } = window.__coreProvider; const globalSearchTestApi: GlobalSearchTestApi = start.plugins.globalSearchTest; - globalSearchTestApi.findAll(term).then((results) => { - cb(results); - }); - }, t) as any; // executeAsync signature is broken. return type should be inferred from the cb param. + globalSearchTestApi.findAll(term).then(cb); + }, t); }; describe('GlobalSearch API', function () { From 80ab0d9792fecb775a93b319a15c12a663134e50 Mon Sep 17 00:00:00 2001 From: MadameSheema Date: Mon, 15 Jun 2020 16:58:47 +0200 Subject: [PATCH 06/82] fixes 'Configures a new connector' flaky test (#69011) Co-authored-by: Elastic Machine --- .../cypress/integration/cases_connectors.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/security_solution/cypress/integration/cases_connectors.spec.ts b/x-pack/plugins/security_solution/cypress/integration/cases_connectors.spec.ts index ae4bb82ebfee65..266d183ea1b858 100644 --- a/x-pack/plugins/security_solution/cypress/integration/cases_connectors.spec.ts +++ b/x-pack/plugins/security_solution/cypress/integration/cases_connectors.spec.ts @@ -17,8 +17,7 @@ import { loginAndWaitForPageWithoutDateRange } from '../tasks/login'; import { CASES } from '../urls/navigation'; -// FLAKY: https://github.com/elastic/kibana/issues/65278 -describe.skip('Cases connectors', () => { +describe('Cases connectors', () => { before(() => { cy.server(); cy.route('POST', '**/api/actions/action').as('createConnector'); @@ -33,6 +32,7 @@ describe.skip('Cases connectors', () => { cy.wait('@createConnector').its('status').should('eql', 200); cy.get(TOASTER).should('have.text', "Created 'New connector'"); + cy.get(TOASTER).should('not.exist'); selectLastConnectorCreated(); From 3d0552e03ce1ff2112a7ca50555575c2cd828c1b Mon Sep 17 00:00:00 2001 From: Anton Dosov Date: Mon, 15 Jun 2020 17:13:31 +0200 Subject: [PATCH 07/82] Embed dashboard by value example & some embeddable clean up (#67783) Added example for using dashboard container by value 1.1 Refactored embeddable explorer e2e test to use new example, removed not needed kbn_tp_embeddable_explorer plugin. For embeddable explorer examples went away from using getFactoryById() to improve type checks There is new component a replacement for EmbeddableFactoryRenderer with slightly more flexible api: EmbeddableRenderer. 3.1 We can improve it going forward to support more use case --- .../dashboard_embeddable_examples/README.md | 1 + .../dashboard_embeddable_examples/kibana.json | 9 + .../public/app.tsx | 112 ++++++++++++ .../public/by_value/embeddable.tsx | 120 +++++++++++++ .../public/by_value/input_editor.tsx | 56 ++++++ .../public}/index.ts | 4 +- .../public/plugin.tsx | 64 +++++++ .../tsconfig.json | 15 ++ .../hello_world_embeddable_factory.ts | 4 +- examples/embeddable_examples/public/index.ts | 13 +- .../public/list_container/index.ts | 2 +- .../public/list_container/list_container.tsx | 2 +- .../list_container/list_container_factory.ts | 6 +- .../multi_task_todo_embeddable_factory.ts | 17 +- examples/embeddable_examples/public/plugin.ts | 69 +++++--- .../public/searchable_list_container/index.ts | 5 +- .../searchable_list_container_factory.ts | 9 +- .../public/todo/todo_embeddable_factory.tsx | 10 +- .../todo/todo_ref_embeddable_factory.tsx | 10 +- examples/embeddable_explorer/public/app.tsx | 33 ++-- .../public/embeddable_panel_example.tsx | 8 +- .../public/hello_world_embeddable_example.tsx | 36 ++-- .../public/list_container_example.tsx | 41 +++-- .../embeddable_explorer/public/plugin.tsx | 1 + .../public/todo_embeddable_example.tsx | 89 +++------- package.json | 1 + renovate.json5 | 8 + .../embeddable/dashboard_container.tsx | 2 +- .../dashboard_container_by_value_renderer.tsx | 37 ++-- .../dashboard_container_factory.tsx | 9 +- .../public/application/embeddable/index.ts | 7 +- src/plugins/dashboard/public/index.ts | 2 +- src/plugins/dashboard/public/plugin.tsx | 37 ++-- src/plugins/embeddable/README.md | 8 +- src/plugins/embeddable/docs/README.md | 5 + .../docs/containers_and_inherited_state.md | 33 ++++ src/plugins/embeddable/public/index.ts | 3 +- .../embeddable_factory_renderer.test.tsx | 71 -------- .../embeddable_factory_renderer.tsx | 80 --------- .../embeddables/embeddable_renderer.test.tsx | 56 ++++++ .../lib/embeddables/embeddable_renderer.tsx | 164 ++++++++++++++++++ .../lib/embeddables/embeddable_root.test.tsx | 9 + .../lib/embeddables/embeddable_root.tsx | 22 ++- .../public/lib/embeddables/index.ts | 2 +- src/plugins/embeddable/public/plugin.tsx | 30 +++- .../embeddable/public/tests/container.test.ts | 6 +- .../public/tests/explicit_input.test.ts | 7 +- test/examples/embeddables/adding_children.ts | 2 +- .../embeddables/dashboard.ts} | 70 ++++++-- test/examples/embeddables/index.ts | 1 + test/plugin_functional/config.js | 1 - .../kbn_tp_embeddable_explorer/README.md | 17 -- .../kbn_tp_embeddable_explorer/kibana.json | 16 -- .../kbn_tp_embeddable_explorer/package.json | 22 --- .../public/README.md | 21 --- .../public/app/app.tsx | 79 --------- .../app/dashboard_container_example.tsx | 102 ----------- .../public/embeddable_api.ts | 25 --- .../public/index.ts | 30 ---- .../public/plugin.tsx | 98 ----------- .../kbn_tp_embeddable_explorer/tsconfig.json | 20 --- .../test_suites/embeddable_explorer/index.js | 42 ----- .../translations/translations/ja-JP.json | 1 - .../translations/translations/zh-CN.json | 1 - yarn.lock | 7 + 65 files changed, 1029 insertions(+), 861 deletions(-) create mode 100644 examples/dashboard_embeddable_examples/README.md create mode 100644 examples/dashboard_embeddable_examples/kibana.json create mode 100644 examples/dashboard_embeddable_examples/public/app.tsx create mode 100644 examples/dashboard_embeddable_examples/public/by_value/embeddable.tsx create mode 100644 examples/dashboard_embeddable_examples/public/by_value/input_editor.tsx rename {test/plugin_functional/plugins/kbn_tp_embeddable_explorer/public/app => examples/dashboard_embeddable_examples/public}/index.ts (86%) create mode 100644 examples/dashboard_embeddable_examples/public/plugin.tsx create mode 100644 examples/dashboard_embeddable_examples/tsconfig.json rename test/plugin_functional/test_suites/embeddable_explorer/dashboard_container.js => src/plugins/dashboard/public/application/embeddable/dashboard_container_by_value_renderer.tsx (55%) create mode 100644 src/plugins/embeddable/docs/README.md create mode 100644 src/plugins/embeddable/docs/containers_and_inherited_state.md delete mode 100644 src/plugins/embeddable/public/lib/embeddables/embeddable_factory_renderer.test.tsx delete mode 100644 src/plugins/embeddable/public/lib/embeddables/embeddable_factory_renderer.tsx create mode 100644 src/plugins/embeddable/public/lib/embeddables/embeddable_renderer.test.tsx create mode 100644 src/plugins/embeddable/public/lib/embeddables/embeddable_renderer.tsx rename test/{plugin_functional/plugins/kbn_tp_embeddable_explorer/public/app/dashboard_input.ts => examples/embeddables/dashboard.ts} (56%) delete mode 100644 test/plugin_functional/plugins/kbn_tp_embeddable_explorer/README.md delete mode 100644 test/plugin_functional/plugins/kbn_tp_embeddable_explorer/kibana.json delete mode 100644 test/plugin_functional/plugins/kbn_tp_embeddable_explorer/package.json delete mode 100644 test/plugin_functional/plugins/kbn_tp_embeddable_explorer/public/README.md delete mode 100644 test/plugin_functional/plugins/kbn_tp_embeddable_explorer/public/app/app.tsx delete mode 100644 test/plugin_functional/plugins/kbn_tp_embeddable_explorer/public/app/dashboard_container_example.tsx delete mode 100644 test/plugin_functional/plugins/kbn_tp_embeddable_explorer/public/embeddable_api.ts delete mode 100644 test/plugin_functional/plugins/kbn_tp_embeddable_explorer/public/index.ts delete mode 100644 test/plugin_functional/plugins/kbn_tp_embeddable_explorer/public/plugin.tsx delete mode 100644 test/plugin_functional/plugins/kbn_tp_embeddable_explorer/tsconfig.json delete mode 100644 test/plugin_functional/test_suites/embeddable_explorer/index.js diff --git a/examples/dashboard_embeddable_examples/README.md b/examples/dashboard_embeddable_examples/README.md new file mode 100644 index 00000000000000..e1528e36f4c4bc --- /dev/null +++ b/examples/dashboard_embeddable_examples/README.md @@ -0,0 +1 @@ +Example of using dashboard container embeddable outside of dashboard app diff --git a/examples/dashboard_embeddable_examples/kibana.json b/examples/dashboard_embeddable_examples/kibana.json new file mode 100644 index 00000000000000..bb2ced569edb5c --- /dev/null +++ b/examples/dashboard_embeddable_examples/kibana.json @@ -0,0 +1,9 @@ +{ + "id": "dashboardEmbeddableExamples", + "version": "0.0.1", + "kibanaVersion": "kibana", + "server": false, + "ui": true, + "requiredPlugins": ["embeddable", "embeddableExamples", "dashboard", "developerExamples"], + "optionalPlugins": [] +} diff --git a/examples/dashboard_embeddable_examples/public/app.tsx b/examples/dashboard_embeddable_examples/public/app.tsx new file mode 100644 index 00000000000000..b166b8444f080b --- /dev/null +++ b/examples/dashboard_embeddable_examples/public/app.tsx @@ -0,0 +1,112 @@ +/* + * 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 React from 'react'; +import ReactDOM from 'react-dom'; +import { BrowserRouter as Router, Route, RouteComponentProps, withRouter } from 'react-router-dom'; + +import { + EuiPage, + EuiPageContent, + EuiPageContentBody, + EuiPageSideBar, + EuiSideNav, +} from '@elastic/eui'; +import 'brace/mode/json'; +import { AppMountParameters } from '../../../src/core/public'; +import { DashboardEmbeddableByValue } from './by_value/embeddable'; +import { DashboardStart } from '../../../src/plugins/dashboard/public'; + +interface PageDef { + title: string; + id: string; + component: React.ReactNode; +} + +type NavProps = RouteComponentProps & { + pages: PageDef[]; +}; + +const Nav = withRouter(({ history, pages }: NavProps) => { + const navItems = pages.map((page) => ({ + id: page.id, + name: page.title, + onClick: () => history.push(`/${page.id}`), + 'data-test-subj': page.id, + })); + + return ( + + ); +}); + +interface Props { + basename: string; + DashboardContainerByValueRenderer: DashboardStart['DashboardContainerByValueRenderer']; +} + +const DashboardEmbeddableExplorerApp = ({ basename, DashboardContainerByValueRenderer }: Props) => { + const pages: PageDef[] = [ + { + title: 'By value dashboard embeddable', + id: 'dashboardEmbeddableByValue', + component: ( + + ), + }, + { + title: 'By ref dashboard embeddable', + id: 'dashboardEmbeddableByRef', + component:
TODO: Not implemented, but coming soon...
, + }, + ]; + + const routes = pages.map((page, i) => ( + page.component} /> + )); + + return ( + + + +