From 447e0959a0f6181c3c30fe5e383bde4eb84eb49c Mon Sep 17 00:00:00 2001 From: oatkiller Date: Thu, 7 Nov 2019 08:09:16 -0500 Subject: [PATCH 01/40] Add a stub endpoint plugin --- x-pack/plugins/endpoint/kibana.json | 8 ++++++ .../public/applications/endpoint/index.tsx | 26 ++++++++++++++++++ x-pack/plugins/endpoint/public/index.ts | 15 +++++++++++ x-pack/plugins/endpoint/public/plugin.ts | 27 +++++++++++++++++++ x-pack/plugins/endpoint/server/index.ts | 16 +++++++++++ x-pack/plugins/endpoint/server/plugin.ts | 18 +++++++++++++ .../plugins/endpoint/server/routes/index.ts | 27 +++++++++++++++++++ 7 files changed, 137 insertions(+) create mode 100644 x-pack/plugins/endpoint/kibana.json create mode 100644 x-pack/plugins/endpoint/public/applications/endpoint/index.tsx create mode 100644 x-pack/plugins/endpoint/public/index.ts create mode 100644 x-pack/plugins/endpoint/public/plugin.ts create mode 100644 x-pack/plugins/endpoint/server/index.ts create mode 100644 x-pack/plugins/endpoint/server/plugin.ts create mode 100644 x-pack/plugins/endpoint/server/routes/index.ts diff --git a/x-pack/plugins/endpoint/kibana.json b/x-pack/plugins/endpoint/kibana.json new file mode 100644 index 0000000000000..81de3ebd1d9d9 --- /dev/null +++ b/x-pack/plugins/endpoint/kibana.json @@ -0,0 +1,8 @@ +{ + "id": "endpoint", + "version": "1.0.0", + "kibanaVersion": "kibana", + "configPath": ["x-pack", "endpoint"], + "server": true, + "ui": true +} diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx new file mode 100644 index 0000000000000..bdc93f9594f0b --- /dev/null +++ b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx @@ -0,0 +1,26 @@ +/* + * 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 React from 'react'; +import ReactDOM from 'react-dom'; +import { AppMountContext, AppMountParameters } from 'kibana/public'; + +/** + * This module will be loaded asynchronously to reduce the bundle size of your plugin's main bundle. + */ +export function renderApp(appMountContext: AppMountContext, { element }: AppMountParameters) { + appMountContext.core.http.get('/endpoint/hello-world'); + + ReactDOM.render(, element); + + return function() { + ReactDOM.unmountComponentAtNode(element); + }; +} + +const AppRoot = React.memo(function Root() { + return

Welcome to Endpoint

; +}); diff --git a/x-pack/plugins/endpoint/public/index.ts b/x-pack/plugins/endpoint/public/index.ts new file mode 100644 index 0000000000000..bb50a3580a6d0 --- /dev/null +++ b/x-pack/plugins/endpoint/public/index.ts @@ -0,0 +1,15 @@ +/* + * 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 { PluginInitializer } from 'kibana/public'; +import { schema } from '@kbn/config-schema'; +import { EndpointPlugin } from './plugin'; + +export const config = { + schema: schema.object({ enabled: schema.boolean({ defaultValue: false }) }), +}; + +export const plugin: PluginInitializer<{}, {}> = () => new EndpointPlugin(); diff --git a/x-pack/plugins/endpoint/public/plugin.ts b/x-pack/plugins/endpoint/public/plugin.ts new file mode 100644 index 0000000000000..85952a561561c --- /dev/null +++ b/x-pack/plugins/endpoint/public/plugin.ts @@ -0,0 +1,27 @@ +/* + * 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 { Plugin, CoreSetup } from 'kibana/public'; + +export class EndpointPlugin implements Plugin<{}, {}> { + public setup(core: CoreSetup) { + core.application.register({ + id: 'endpoint', + title: 'Endpoint', + async mount(context, params) { + const { renderApp } = await import('./applications/endpoint'); + return renderApp(context, params); + }, + }); + return {}; + } + + public start() { + return {}; + } + + public stop() {} +} diff --git a/x-pack/plugins/endpoint/server/index.ts b/x-pack/plugins/endpoint/server/index.ts new file mode 100644 index 0000000000000..26c2bbd5ef873 --- /dev/null +++ b/x-pack/plugins/endpoint/server/index.ts @@ -0,0 +1,16 @@ +/* + * 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 { schema } from '@kbn/config-schema'; +import { EndpointPlugin } from './plugin'; + +export const config = { + schema: schema.object({ enabled: schema.boolean({ defaultValue: false }) }), +}; + +export function plugin() { + return new EndpointPlugin(); +} diff --git a/x-pack/plugins/endpoint/server/plugin.ts b/x-pack/plugins/endpoint/server/plugin.ts new file mode 100644 index 0000000000000..d5e87d9c8f8c3 --- /dev/null +++ b/x-pack/plugins/endpoint/server/plugin.ts @@ -0,0 +1,18 @@ +/* + * 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 { Plugin, CoreSetup } from 'kibana/server'; +import { addRoutes } from './routes'; + +export class EndpointPlugin implements Plugin { + public setup(core: CoreSetup) { + const router = core.http.createRouter(); + addRoutes(router); + } + + public start() {} + public stop() {} +} diff --git a/x-pack/plugins/endpoint/server/routes/index.ts b/x-pack/plugins/endpoint/server/routes/index.ts new file mode 100644 index 0000000000000..7ae7187af5bb7 --- /dev/null +++ b/x-pack/plugins/endpoint/server/routes/index.ts @@ -0,0 +1,27 @@ +/* + * 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 { IRouter, KibanaResponseFactory } from 'kibana/server'; + +export function addRoutes(router: IRouter) { + router.get( + { + path: '/endpoint/hello-world', + validate: false, + }, + greetingIndex + ); +} + +async function greetingIndex(...passedArgs: [unknown, unknown, KibanaResponseFactory]) { + const [, , response] = passedArgs; + return response.ok({ + body: JSON.stringify({ hello: 'world' }), + headers: { + 'Content-Type': 'application/json', + }, + }); +} From 2a15ab0b0c38105f1a2e7089adfff66bba6baab5 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Fri, 15 Nov 2019 15:21:02 -0500 Subject: [PATCH 02/40] Fix config path for endpoint plugin --- x-pack/plugins/endpoint/kibana.json | 2 +- x-pack/plugins/endpoint/public/index.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/endpoint/kibana.json b/x-pack/plugins/endpoint/kibana.json index 81de3ebd1d9d9..60c4d496ee253 100644 --- a/x-pack/plugins/endpoint/kibana.json +++ b/x-pack/plugins/endpoint/kibana.json @@ -2,7 +2,7 @@ "id": "endpoint", "version": "1.0.0", "kibanaVersion": "kibana", - "configPath": ["x-pack", "endpoint"], + "configPath": ["xpack", "endpoint"], "server": true, "ui": true } diff --git a/x-pack/plugins/endpoint/public/index.ts b/x-pack/plugins/endpoint/public/index.ts index bb50a3580a6d0..783a8f4cbfbe3 100644 --- a/x-pack/plugins/endpoint/public/index.ts +++ b/x-pack/plugins/endpoint/public/index.ts @@ -6,6 +6,7 @@ import { PluginInitializer } from 'kibana/public'; import { schema } from '@kbn/config-schema'; +import { schema } from '@kbn/config-schema'; import { EndpointPlugin } from './plugin'; export const config = { From f8428a181aaf01557ed94a9dddf041857b92577b Mon Sep 17 00:00:00 2001 From: oatkiller Date: Fri, 15 Nov 2019 15:21:37 -0500 Subject: [PATCH 03/40] Remove useless config schema definition from public endpoint plugin --- x-pack/plugins/endpoint/public/index.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/x-pack/plugins/endpoint/public/index.ts b/x-pack/plugins/endpoint/public/index.ts index 783a8f4cbfbe3..062dd9ab93afa 100644 --- a/x-pack/plugins/endpoint/public/index.ts +++ b/x-pack/plugins/endpoint/public/index.ts @@ -5,12 +5,6 @@ */ import { PluginInitializer } from 'kibana/public'; -import { schema } from '@kbn/config-schema'; -import { schema } from '@kbn/config-schema'; import { EndpointPlugin } from './plugin'; -export const config = { - schema: schema.object({ enabled: schema.boolean({ defaultValue: false }) }), -}; - export const plugin: PluginInitializer<{}, {}> = () => new EndpointPlugin(); From ed09f4c25080ccb3b53e691cadcc424cf4ab935f Mon Sep 17 00:00:00 2001 From: oatkiller Date: Fri, 15 Nov 2019 15:22:09 -0500 Subject: [PATCH 04/40] Prefix endpoint route w/ `api` --- .../plugins/endpoint/server/routes/index.ts | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/x-pack/plugins/endpoint/server/routes/index.ts b/x-pack/plugins/endpoint/server/routes/index.ts index 7ae7187af5bb7..bb7de2f690a98 100644 --- a/x-pack/plugins/endpoint/server/routes/index.ts +++ b/x-pack/plugins/endpoint/server/routes/index.ts @@ -4,24 +4,22 @@ * you may not use this file except in compliance with the Elastic License. */ -import { IRouter, KibanaResponseFactory } from 'kibana/server'; +import { IRouter } from 'kibana/server'; export function addRoutes(router: IRouter) { router.get( { - path: '/endpoint/hello-world', + path: '/api/endpoint/hello-world', validate: false, }, - greetingIndex + async function greetingIndex(...passedArgs) { + const [, , response] = passedArgs; + return response.ok({ + body: { hello: 'world' }, + headers: { + 'Content-Type': 'application/json', + }, + }); + } ); } - -async function greetingIndex(...passedArgs: [unknown, unknown, KibanaResponseFactory]) { - const [, , response] = passedArgs; - return response.ok({ - body: JSON.stringify({ hello: 'world' }), - headers: { - 'Content-Type': 'application/json', - }, - }); -} From 654b8cda1a6d39dcea4e8468ca3db93ea2c0e429 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Fri, 15 Nov 2019 16:28:25 -0500 Subject: [PATCH 05/40] added api smoketest for resolver --- .../api_integration/apis/endpoint/index.ts | 13 +++++++++ .../api_integration/apis/endpoint/resolver.ts | 29 +++++++++++++++++++ x-pack/test/api_integration/apis/index.js | 5 ++-- x-pack/test/functional/config.js | 5 ++-- 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 x-pack/test/api_integration/apis/endpoint/index.ts create mode 100644 x-pack/test/api_integration/apis/endpoint/resolver.ts diff --git a/x-pack/test/api_integration/apis/endpoint/index.ts b/x-pack/test/api_integration/apis/endpoint/index.ts new file mode 100644 index 0000000000000..eaab3b1f18657 --- /dev/null +++ b/x-pack/test/api_integration/apis/endpoint/index.ts @@ -0,0 +1,13 @@ +/* + * 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 { FtrProviderContext } from '../../ftr_provider_context'; + +export default function endpointAPIIntegrationTests({ loadTestFile }: FtrProviderContext) { + describe('Endpoint', function() { + loadTestFile(require.resolve('./resolver')); + }); +} diff --git a/x-pack/test/api_integration/apis/endpoint/resolver.ts b/x-pack/test/api_integration/apis/endpoint/resolver.ts new file mode 100644 index 0000000000000..42278ab4ac238 --- /dev/null +++ b/x-pack/test/api_integration/apis/endpoint/resolver.ts @@ -0,0 +1,29 @@ +/* + * 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 expect from '@kbn/expect'; +import { FtrProviderContext } from '../../ftr_provider_context'; + +const commonHeaders = { + Accept: 'application/json', + 'kbn-xsrf': 'some-xsrf-token', +}; + +// eslint-disable-next-line import/no-default-export +export default function resolverAPIIntegrationTests({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + describe('Resolver', function() { + it('should response to hello-world', async function() { + const { body } = await supertest + .get('/api/endpoint/hello-world') + .set(commonHeaders) + .expect('Content-Type', /application\/json/) + .expect(200); + + expect(body).to.eql({ hello: 'world' }); + }); + }); +} diff --git a/x-pack/test/api_integration/apis/index.js b/x-pack/test/api_integration/apis/index.js index ca339e9f407f2..eea5b692abc4f 100644 --- a/x-pack/test/api_integration/apis/index.js +++ b/x-pack/test/api_integration/apis/index.js @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -export default function ({ loadTestFile }) { - describe('apis', function () { +export default function({ loadTestFile }) { + describe('apis', function() { this.tags('ciGroup6'); loadTestFile(require.resolve('./es')); @@ -28,5 +28,6 @@ export default function ({ loadTestFile }) { loadTestFile(require.resolve('./short_urls')); loadTestFile(require.resolve('./lens')); loadTestFile(require.resolve('./licensing')); + loadTestFile(require.resolve('./endpoint')); }); } diff --git a/x-pack/test/functional/config.js b/x-pack/test/functional/config.js index f4b2be3420298..2148574c32260 100644 --- a/x-pack/test/functional/config.js +++ b/x-pack/test/functional/config.js @@ -86,6 +86,7 @@ export default async function ({ readConfigFile }) { '--xpack.encryptedSavedObjects.encryptionKey="DkdXazszSCYexXqz4YktBGHCRkV6hyNK"', '--telemetry.banner=false', '--timelion.ui.enabled=true', + '--xpack.endpoint.enabled=true', ], }, uiSettings: { @@ -153,10 +154,10 @@ export default async function ({ readConfigFile }) { pathname: '/app/uptime', }, apm: { - pathname: '/app/apm' + pathname: '/app/apm', }, ml: { - pathname: '/app/ml' + pathname: '/app/ml', }, rollupJob: { pathname: '/app/kibana', From c9eaa0cff9ab4f697a517ee5c20ef693947233b0 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 18 Nov 2019 11:20:53 -0500 Subject: [PATCH 06/40] i18n for stub Endpoint application --- .../endpoint/public/applications/endpoint/index.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx index bdc93f9594f0b..1d9dee224dea7 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx @@ -7,6 +7,7 @@ import * as React from 'react'; import ReactDOM from 'react-dom'; import { AppMountContext, AppMountParameters } from 'kibana/public'; +import { I18nProvider, FormattedMessage } from '@kbn/i18n/react'; /** * This module will be loaded asynchronously to reduce the bundle size of your plugin's main bundle. @@ -22,5 +23,11 @@ export function renderApp(appMountContext: AppMountContext, { element }: AppMoun } const AppRoot = React.memo(function Root() { - return

Welcome to Endpoint

; + return ( + +

+ +

+
+ ); }); From f699a0d24405591b5e10c4e9e293ae9a012015db Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 18 Nov 2019 12:27:03 -0500 Subject: [PATCH 07/40] Track translations in endpoint plugin --- x-pack/.i18nrc.json | 3 ++- x-pack/plugins/endpoint/public/applications/endpoint/index.tsx | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/x-pack/.i18nrc.json b/x-pack/.i18nrc.json index 6d0da2f0b693d..983271b2cfb1d 100644 --- a/x-pack/.i18nrc.json +++ b/x-pack/.i18nrc.json @@ -38,7 +38,8 @@ "xpack.transform": "legacy/plugins/transform", "xpack.upgradeAssistant": "legacy/plugins/upgrade_assistant", "xpack.uptime": "legacy/plugins/uptime", - "xpack.watcher": "legacy/plugins/watcher" + "xpack.watcher": "legacy/plugins/watcher", + "xpack.endpoint": "plugins/endpoint" }, "translations": [ "plugins/translations/translations/zh-CN.json", diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx index 1d9dee224dea7..166b355f511b4 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx @@ -26,7 +26,7 @@ const AppRoot = React.memo(function Root() { return (

- +

); From 4c2e0797969649bac607eb954311c0dbea73247c Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 18 Nov 2019 13:32:13 -0500 Subject: [PATCH 08/40] Add translations too? --- x-pack/plugins/endpoint/translations/en.json | 81 ++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 x-pack/plugins/endpoint/translations/en.json diff --git a/x-pack/plugins/endpoint/translations/en.json b/x-pack/plugins/endpoint/translations/en.json new file mode 100644 index 0000000000000..469d551cb6ef6 --- /dev/null +++ b/x-pack/plugins/endpoint/translations/en.json @@ -0,0 +1,81 @@ +{ + "formats": { + "number": { + "currency": { + "style": "currency" + }, + "percent": { + "style": "percent" + } + }, + "date": { + "short": { + "month": "numeric", + "day": "numeric", + "year": "2-digit" + }, + "medium": { + "month": "short", + "day": "numeric", + "year": "numeric" + }, + "long": { + "month": "long", + "day": "numeric", + "year": "numeric" + }, + "full": { + "weekday": "long", + "month": "long", + "day": "numeric", + "year": "numeric" + } + }, + "time": { + "short": { + "hour": "numeric", + "minute": "numeric" + }, + "medium": { + "hour": "numeric", + "minute": "numeric", + "second": "numeric" + }, + "long": { + "hour": "numeric", + "minute": "numeric", + "second": "numeric", + "timeZoneName": "short" + }, + "full": { + "hour": "numeric", + "minute": "numeric", + "second": "numeric", + "timeZoneName": "short" + } + }, + "relative": { + "years": { + "units": "year" + }, + "months": { + "units": "month" + }, + "days": { + "units": "day" + }, + "hours": { + "units": "hour" + }, + "minutes": { + "units": "minute" + }, + "seconds": { + "units": "second" + } + } + }, + "messages": { + "xpack.endpoint.welcome": "Hello World" + } +} \ No newline at end of file From b29b3360a780af0d2974d34c52b71d22bd110cf1 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 18 Nov 2019 15:12:57 -0500 Subject: [PATCH 09/40] Only enable endpoint in x-pack api integration tests --- x-pack/test/api_integration/config.js | 1 + x-pack/test/functional/config.js | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/test/api_integration/config.js b/x-pack/test/api_integration/config.js index 9c67dfe61b957..e5860fba80770 100644 --- a/x-pack/test/api_integration/config.js +++ b/x-pack/test/api_integration/config.js @@ -23,6 +23,7 @@ export async function getApiIntegrationConfig({ readConfigFile }) { ...xPackFunctionalTestsConfig.get('kbnTestServer.serverArgs'), '--xpack.security.session.idleTimeout=3600000', // 1 hour '--optimize.enabled=false', + '--xpack.endpoint.enabled=true', ], }, esTestCluster: { diff --git a/x-pack/test/functional/config.js b/x-pack/test/functional/config.js index 2148574c32260..bf3435582ef47 100644 --- a/x-pack/test/functional/config.js +++ b/x-pack/test/functional/config.js @@ -86,7 +86,6 @@ export default async function ({ readConfigFile }) { '--xpack.encryptedSavedObjects.encryptionKey="DkdXazszSCYexXqz4YktBGHCRkV6hyNK"', '--telemetry.banner=false', '--timelion.ui.enabled=true', - '--xpack.endpoint.enabled=true', ], }, uiSettings: { From 6134b3161e562ccb7691f72d108cd5513049cbbd Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 18 Nov 2019 19:19:05 -0500 Subject: [PATCH 10/40] Add basic functional test --- .../public/applications/endpoint/index.tsx | 6 ++--- x-pack/test/functional/apps/endpoint/index.ts | 25 +++++++++++++++++++ x-pack/test/functional/config.js | 9 +++++-- 3 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 x-pack/test/functional/apps/endpoint/index.ts diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx index 166b355f511b4..f8828330461fb 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx @@ -13,7 +13,7 @@ import { I18nProvider, FormattedMessage } from '@kbn/i18n/react'; * This module will be loaded asynchronously to reduce the bundle size of your plugin's main bundle. */ export function renderApp(appMountContext: AppMountContext, { element }: AppMountParameters) { - appMountContext.core.http.get('/endpoint/hello-world'); + appMountContext.core.http.get('/api/endpoint/hello-world'); ReactDOM.render(, element); @@ -25,8 +25,8 @@ export function renderApp(appMountContext: AppMountContext, { element }: AppMoun const AppRoot = React.memo(function Root() { return ( -

- +

+

); diff --git a/x-pack/test/functional/apps/endpoint/index.ts b/x-pack/test/functional/apps/endpoint/index.ts new file mode 100644 index 0000000000000..d2268a8339e95 --- /dev/null +++ b/x-pack/test/functional/apps/endpoint/index.ts @@ -0,0 +1,25 @@ +/* + * 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 expect from '@kbn/expect'; +import { FtrProviderContext } from '../../ftr_provider_context'; + +export default function({ getPageObjects, getService }: FtrProviderContext) { + const { common } = getPageObjects(['common']); + const navigateToApp = common.navigateToApp.bind(common); + + const { find } = getService('testSubjects'); + + describe('The Endpoint app', function() { + beforeEach(async function() { + await navigateToApp('endpoint'); + }); + + it("welcomes the user with 'Hello World'", async function() { + await find('welcomeMessage'); + }); + }); +} diff --git a/x-pack/test/functional/config.js b/x-pack/test/functional/config.js index bf3435582ef47..9e6bed2d20f4a 100644 --- a/x-pack/test/functional/config.js +++ b/x-pack/test/functional/config.js @@ -56,6 +56,7 @@ export default async function ({ readConfigFile }) { resolve(__dirname, './apps/cross_cluster_replication'), resolve(__dirname, './apps/remote_clusters'), resolve(__dirname, './apps/transform'), + resolve(__dirname, './apps/endpoint'), // This license_management file must be last because it is destructive. resolve(__dirname, './apps/license_management'), ], @@ -86,6 +87,7 @@ export default async function ({ readConfigFile }) { '--xpack.encryptedSavedObjects.encryptionKey="DkdXazszSCYexXqz4YktBGHCRkV6hyNK"', '--telemetry.banner=false', '--timelion.ui.enabled=true', + '--xpack.endpoint.enabled=true', ], }, uiSettings: { @@ -195,8 +197,11 @@ export default async function ({ readConfigFile }) { }, transform: { pathname: '/app/kibana/', - hash: '/management/elasticsearch/transform' - } + hash: '/management/elasticsearch/transform', + }, + endpoint: { + pathname: '/app/endpoint', + }, }, // choose where esArchiver should load archives from From 325e8d10ca56348785c4044fad54ca7aafa07189 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 18 Nov 2019 21:40:02 -0500 Subject: [PATCH 11/40] remove unused import --- x-pack/test/functional/apps/endpoint/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/test/functional/apps/endpoint/index.ts b/x-pack/test/functional/apps/endpoint/index.ts index d2268a8339e95..30136ed1ff259 100644 --- a/x-pack/test/functional/apps/endpoint/index.ts +++ b/x-pack/test/functional/apps/endpoint/index.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import expect from '@kbn/expect'; import { FtrProviderContext } from '../../ftr_provider_context'; export default function({ getPageObjects, getService }: FtrProviderContext) { From 22b273880922aa870770264e11d861c00d9d1a26 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Tue, 19 Nov 2019 08:33:45 -0500 Subject: [PATCH 12/40] Move page object access into beforeEach --- x-pack/test/functional/apps/endpoint/index.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/x-pack/test/functional/apps/endpoint/index.ts b/x-pack/test/functional/apps/endpoint/index.ts index 30136ed1ff259..afc033f39b1aa 100644 --- a/x-pack/test/functional/apps/endpoint/index.ts +++ b/x-pack/test/functional/apps/endpoint/index.ts @@ -8,13 +8,11 @@ import { FtrProviderContext } from '../../ftr_provider_context'; export default function({ getPageObjects, getService }: FtrProviderContext) { const { common } = getPageObjects(['common']); - const navigateToApp = common.navigateToApp.bind(common); - const { find } = getService('testSubjects'); describe('The Endpoint app', function() { beforeEach(async function() { - await navigateToApp('endpoint'); + await common.navigateToApp('endpoint'); }); it("welcomes the user with 'Hello World'", async function() { From 212c144d39616ae6f7333b7f28ea8f0cb0d61187 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Tue, 19 Nov 2019 11:26:59 -0500 Subject: [PATCH 13/40] Remove access to services and page objects before test has started --- x-pack/test/functional/apps/endpoint/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/test/functional/apps/endpoint/index.ts b/x-pack/test/functional/apps/endpoint/index.ts index afc033f39b1aa..e35bd24fac8d6 100644 --- a/x-pack/test/functional/apps/endpoint/index.ts +++ b/x-pack/test/functional/apps/endpoint/index.ts @@ -7,16 +7,16 @@ import { FtrProviderContext } from '../../ftr_provider_context'; export default function({ getPageObjects, getService }: FtrProviderContext) { - const { common } = getPageObjects(['common']); - const { find } = getService('testSubjects'); + const pageObjects = getPageObjects(['common']); + const testSubjects = getService('testSubjects'); describe('The Endpoint app', function() { beforeEach(async function() { - await common.navigateToApp('endpoint'); + await pageObjects.common.navigateToApp('endpoint'); }); it("welcomes the user with 'Hello World'", async function() { - await find('welcomeMessage'); + await testSubjects.find('welcomeMessage'); }); }); } From 791024621db996c8beb2f0bb7ab0129dafc7ccf2 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Tue, 19 Nov 2019 12:15:59 -0500 Subject: [PATCH 14/40] Select ci group 7 for functional tests --- x-pack/test/functional/apps/endpoint/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x-pack/test/functional/apps/endpoint/index.ts b/x-pack/test/functional/apps/endpoint/index.ts index e35bd24fac8d6..63a6afde64785 100644 --- a/x-pack/test/functional/apps/endpoint/index.ts +++ b/x-pack/test/functional/apps/endpoint/index.ts @@ -11,6 +11,8 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { const testSubjects = getService('testSubjects'); describe('The Endpoint app', function() { + this.tags('ciGroup7'); + beforeEach(async function() { await pageObjects.common.navigateToApp('endpoint'); }); From 8d9fda07a1318594664720e6cbd6728a923d8fc3 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Tue, 19 Nov 2019 12:21:56 -0500 Subject: [PATCH 15/40] More tags. everyone gets tags --- x-pack/test/api_integration/apis/endpoint/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/test/api_integration/apis/endpoint/index.ts b/x-pack/test/api_integration/apis/endpoint/index.ts index eaab3b1f18657..4ea1c67438e49 100644 --- a/x-pack/test/api_integration/apis/endpoint/index.ts +++ b/x-pack/test/api_integration/apis/endpoint/index.ts @@ -8,6 +8,7 @@ import { FtrProviderContext } from '../../ftr_provider_context'; export default function endpointAPIIntegrationTests({ loadTestFile }: FtrProviderContext) { describe('Endpoint', function() { + this.tags('ciGroup7'); loadTestFile(require.resolve('./resolver')); }); } From 0294f8e0be0a2c920bed6211969d26c4a1128fa4 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Tue, 19 Nov 2019 13:45:44 -0500 Subject: [PATCH 16/40] i18n id conforms guidelines,remove API test ci tag --- .../plugins/endpoint/public/applications/endpoint/index.tsx | 4 ++-- x-pack/test/api_integration/apis/endpoint/index.ts | 1 - x-pack/test/functional/apps/endpoint/index.ts | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx index f8828330461fb..84597e6d5f81a 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx @@ -25,8 +25,8 @@ export function renderApp(appMountContext: AppMountContext, { element }: AppMoun const AppRoot = React.memo(function Root() { return ( -

- +

+

); diff --git a/x-pack/test/api_integration/apis/endpoint/index.ts b/x-pack/test/api_integration/apis/endpoint/index.ts index 4ea1c67438e49..eaab3b1f18657 100644 --- a/x-pack/test/api_integration/apis/endpoint/index.ts +++ b/x-pack/test/api_integration/apis/endpoint/index.ts @@ -8,7 +8,6 @@ import { FtrProviderContext } from '../../ftr_provider_context'; export default function endpointAPIIntegrationTests({ loadTestFile }: FtrProviderContext) { describe('Endpoint', function() { - this.tags('ciGroup7'); loadTestFile(require.resolve('./resolver')); }); } diff --git a/x-pack/test/functional/apps/endpoint/index.ts b/x-pack/test/functional/apps/endpoint/index.ts index 63a6afde64785..5ff8e6c5b0db8 100644 --- a/x-pack/test/functional/apps/endpoint/index.ts +++ b/x-pack/test/functional/apps/endpoint/index.ts @@ -18,7 +18,7 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { }); it("welcomes the user with 'Hello World'", async function() { - await testSubjects.find('welcomeMessage'); + await testSubjects.find('welcomeTitle'); }); }); } From e1cc28c48e960defeb06387a4d92e54c64f6fd74 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Tue, 19 Nov 2019 14:23:27 -0500 Subject: [PATCH 17/40] remove useless endpoint.enabled flag in API integration tests --- x-pack/test/api_integration/config.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/x-pack/test/api_integration/config.js b/x-pack/test/api_integration/config.js index e5860fba80770..4794a7bee5dfb 100644 --- a/x-pack/test/api_integration/config.js +++ b/x-pack/test/api_integration/config.js @@ -7,7 +7,9 @@ import { services } from './services'; export async function getApiIntegrationConfig({ readConfigFile }) { - const xPackFunctionalTestsConfig = await readConfigFile(require.resolve('../functional/config.js')); + const xPackFunctionalTestsConfig = await readConfigFile( + require.resolve('../functional/config.js') + ); return { testFiles: [require.resolve('./apis')], @@ -23,14 +25,13 @@ export async function getApiIntegrationConfig({ readConfigFile }) { ...xPackFunctionalTestsConfig.get('kbnTestServer.serverArgs'), '--xpack.security.session.idleTimeout=3600000', // 1 hour '--optimize.enabled=false', - '--xpack.endpoint.enabled=true', ], }, esTestCluster: { ...xPackFunctionalTestsConfig.get('esTestCluster'), serverArgs: [ ...xPackFunctionalTestsConfig.get('esTestCluster.serverArgs'), - 'node.attr.name=apiIntegrationTestNode' + 'node.attr.name=apiIntegrationTestNode', ], }, }; From cde371779d5cf2848cf34d81f9592e027a4578b3 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Wed, 20 Nov 2019 14:30:22 -0500 Subject: [PATCH 18/40] Make an attempt/guess at registering plugin features --- x-pack/plugins/endpoint/kibana.json | 1 + x-pack/plugins/endpoint/server/plugin.ts | 28 +++++++++++++++++-- .../plugins/endpoint/server/routes/index.ts | 3 ++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/endpoint/kibana.json b/x-pack/plugins/endpoint/kibana.json index 60c4d496ee253..90a7076d0bd91 100644 --- a/x-pack/plugins/endpoint/kibana.json +++ b/x-pack/plugins/endpoint/kibana.json @@ -3,6 +3,7 @@ "version": "1.0.0", "kibanaVersion": "kibana", "configPath": ["xpack", "endpoint"], + "requiredPlugins": ["features"], "server": true, "ui": true } diff --git a/x-pack/plugins/endpoint/server/plugin.ts b/x-pack/plugins/endpoint/server/plugin.ts index d5e87d9c8f8c3..17c8dce3be454 100644 --- a/x-pack/plugins/endpoint/server/plugin.ts +++ b/x-pack/plugins/endpoint/server/plugin.ts @@ -4,11 +4,33 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Plugin, CoreSetup } from 'kibana/server'; +import { Plugin, CoreSetup, CoreStart } from 'kibana/server'; import { addRoutes } from './routes'; +import { PluginSetupContract as FeaturesPluginSetupContract } from 'x-pack/plugins/features/server'; -export class EndpointPlugin implements Plugin { - public setup(core: CoreSetup) { +export interface PluginsSetup { + features: FeaturesPluginSetupContract; +} + +export class EndpointPlugin implements Plugin { + public setup(core: CoreSetup, plugins: PluginsSetup) { + plugins.features.registerFeature({ + id: 'endpoint', + name: 'Endpoint', + icon: 'bug', + navLinkId: 'endpoint', + app: ['endpoint', 'kibana'], + privileges: { + read: { + api: ['resolver'], + savedObject: { + all: [], + read: [], + }, + ui: ['show'], + }, + }, + }); const router = core.http.createRouter(); addRoutes(router); } diff --git a/x-pack/plugins/endpoint/server/routes/index.ts b/x-pack/plugins/endpoint/server/routes/index.ts index bb7de2f690a98..c2b3ab8fa1658 100644 --- a/x-pack/plugins/endpoint/server/routes/index.ts +++ b/x-pack/plugins/endpoint/server/routes/index.ts @@ -11,6 +11,9 @@ export function addRoutes(router: IRouter) { { path: '/api/endpoint/hello-world', validate: false, + options: { + tags: ['access:resolver'], + }, }, async function greetingIndex(...passedArgs) { const [, , response] = passedArgs; From 41852282dfc72f27f2bc12fdfe4bae97bd948c50 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Thu, 21 Nov 2019 11:33:33 -0500 Subject: [PATCH 19/40] Remove useless translation file --- x-pack/plugins/endpoint/translations/en.json | 81 -------------------- 1 file changed, 81 deletions(-) delete mode 100644 x-pack/plugins/endpoint/translations/en.json diff --git a/x-pack/plugins/endpoint/translations/en.json b/x-pack/plugins/endpoint/translations/en.json deleted file mode 100644 index 469d551cb6ef6..0000000000000 --- a/x-pack/plugins/endpoint/translations/en.json +++ /dev/null @@ -1,81 +0,0 @@ -{ - "formats": { - "number": { - "currency": { - "style": "currency" - }, - "percent": { - "style": "percent" - } - }, - "date": { - "short": { - "month": "numeric", - "day": "numeric", - "year": "2-digit" - }, - "medium": { - "month": "short", - "day": "numeric", - "year": "numeric" - }, - "long": { - "month": "long", - "day": "numeric", - "year": "numeric" - }, - "full": { - "weekday": "long", - "month": "long", - "day": "numeric", - "year": "numeric" - } - }, - "time": { - "short": { - "hour": "numeric", - "minute": "numeric" - }, - "medium": { - "hour": "numeric", - "minute": "numeric", - "second": "numeric" - }, - "long": { - "hour": "numeric", - "minute": "numeric", - "second": "numeric", - "timeZoneName": "short" - }, - "full": { - "hour": "numeric", - "minute": "numeric", - "second": "numeric", - "timeZoneName": "short" - } - }, - "relative": { - "years": { - "units": "year" - }, - "months": { - "units": "month" - }, - "days": { - "units": "day" - }, - "hours": { - "units": "hour" - }, - "minutes": { - "units": "minute" - }, - "seconds": { - "units": "second" - } - } - }, - "messages": { - "xpack.endpoint.welcome": "Hello World" - } -} \ No newline at end of file From 599018e05a4a559cf71c3c65ee62db14b387c80d Mon Sep 17 00:00:00 2001 From: oatkiller Date: Thu, 21 Nov 2019 11:40:51 -0500 Subject: [PATCH 20/40] Alphabetize x-pack/.i18nrc.json --- x-pack/.i18nrc.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/x-pack/.i18nrc.json b/x-pack/.i18nrc.json index 983271b2cfb1d..ed4c279576d17 100644 --- a/x-pack/.i18nrc.json +++ b/x-pack/.i18nrc.json @@ -9,6 +9,7 @@ "xpack.canvas": "legacy/plugins/canvas", "xpack.crossClusterReplication": "legacy/plugins/cross_cluster_replication", "xpack.dashboardMode": "legacy/plugins/dashboard_mode", + "xpack.endpoint": "plugins/endpoint" "xpack.features": "plugins/features", "xpack.fileUpload": "legacy/plugins/file_upload", "xpack.graph": "legacy/plugins/graph", @@ -18,20 +19,20 @@ "xpack.infra": "legacy/plugins/infra", "xpack.kueryAutocomplete": "legacy/plugins/kuery_autocomplete", "xpack.lens": "legacy/plugins/lens", - "xpack.licensing": "plugins/licensing", "xpack.licenseMgmt": "legacy/plugins/license_management", - "xpack.maps": "legacy/plugins/maps", - "xpack.ml": "legacy/plugins/ml", + "xpack.licensing": "plugins/licensing", "xpack.logstash": "legacy/plugins/logstash", "xpack.main": "legacy/plugins/xpack_main", + "xpack.maps": "legacy/plugins/maps", + "xpack.ml": "legacy/plugins/ml", "xpack.monitoring": "legacy/plugins/monitoring", "xpack.remoteClusters": "legacy/plugins/remote_clusters", "xpack.reporting": [ "plugins/reporting", "legacy/plugins/reporting" ], "xpack.rollupJobs": "legacy/plugins/rollup", "xpack.searchProfiler": "legacy/plugins/searchprofiler", - "xpack.siem": "legacy/plugins/siem", "xpack.security": ["legacy/plugins/security", "plugins/security"], "xpack.server": "legacy/server", + "xpack.siem": "legacy/plugins/siem", "xpack.snapshotRestore": "legacy/plugins/snapshot_restore", "xpack.spaces": ["legacy/plugins/spaces", "plugins/spaces"], "xpack.taskManager": "legacy/plugins/task_manager", @@ -39,7 +40,6 @@ "xpack.upgradeAssistant": "legacy/plugins/upgrade_assistant", "xpack.uptime": "legacy/plugins/uptime", "xpack.watcher": "legacy/plugins/watcher", - "xpack.endpoint": "plugins/endpoint" }, "translations": [ "plugins/translations/translations/zh-CN.json", From 057335240245df720de5e3697c3c6ecd69e2a135 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Thu, 21 Nov 2019 11:46:21 -0500 Subject: [PATCH 21/40] code formatting changes --- .../public/applications/endpoint/index.tsx | 18 ++++++++---------- x-pack/plugins/endpoint/public/plugin.ts | 5 ++++- x-pack/test/functional/apps/endpoint/index.ts | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx index 84597e6d5f81a..73adc2defe604 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx @@ -17,17 +17,15 @@ export function renderApp(appMountContext: AppMountContext, { element }: AppMoun ReactDOM.render(, element); - return function() { + return () => { ReactDOM.unmountComponentAtNode(element); }; } -const AppRoot = React.memo(function Root() { - return ( - -

- -

-
- ); -}); +const AppRoot = React.memo(() => ( + +

+ +

+
+)); diff --git a/x-pack/plugins/endpoint/public/plugin.ts b/x-pack/plugins/endpoint/public/plugin.ts index 85952a561561c..0094b01644f39 100644 --- a/x-pack/plugins/endpoint/public/plugin.ts +++ b/x-pack/plugins/endpoint/public/plugin.ts @@ -5,12 +5,15 @@ */ import { Plugin, CoreSetup } from 'kibana/public'; +import { i18n } from '@kbn/i18n'; export class EndpointPlugin implements Plugin<{}, {}> { public setup(core: CoreSetup) { core.application.register({ id: 'endpoint', - title: 'Endpoint', + title: i18n.translate('xpack.endpoint.pluginTitle', { + defaultMessage: 'Endpoint', + }), async mount(context, params) { const { renderApp } = await import('./applications/endpoint'); return renderApp(context, params); diff --git a/x-pack/test/functional/apps/endpoint/index.ts b/x-pack/test/functional/apps/endpoint/index.ts index 5ff8e6c5b0db8..4465242b018e0 100644 --- a/x-pack/test/functional/apps/endpoint/index.ts +++ b/x-pack/test/functional/apps/endpoint/index.ts @@ -18,7 +18,7 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { }); it("welcomes the user with 'Hello World'", async function() { - await testSubjects.find('welcomeTitle'); + await testSubjects.existOrFail('welcomeTitle'); }); }); } From f6b7ec68f7c23f29d95a4c8aebbd9ad69adef2a3 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Thu, 21 Nov 2019 12:20:52 -0500 Subject: [PATCH 22/40] fix formatting of x-pack/.i18nrc.json --- x-pack/.i18nrc.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/.i18nrc.json b/x-pack/.i18nrc.json index ed4c279576d17..180aafe504c63 100644 --- a/x-pack/.i18nrc.json +++ b/x-pack/.i18nrc.json @@ -9,7 +9,7 @@ "xpack.canvas": "legacy/plugins/canvas", "xpack.crossClusterReplication": "legacy/plugins/cross_cluster_replication", "xpack.dashboardMode": "legacy/plugins/dashboard_mode", - "xpack.endpoint": "plugins/endpoint" + "xpack.endpoint": "plugins/endpoint", "xpack.features": "plugins/features", "xpack.fileUpload": "legacy/plugins/file_upload", "xpack.graph": "legacy/plugins/graph", @@ -39,7 +39,7 @@ "xpack.transform": "legacy/plugins/transform", "xpack.upgradeAssistant": "legacy/plugins/upgrade_assistant", "xpack.uptime": "legacy/plugins/uptime", - "xpack.watcher": "legacy/plugins/watcher", + "xpack.watcher": "legacy/plugins/watcher" }, "translations": [ "plugins/translations/translations/zh-CN.json", From eda5b367f72d1f0a2683cd586b5d25599e2ff5cb Mon Sep 17 00:00:00 2001 From: oatkiller Date: Thu, 21 Nov 2019 13:03:17 -0500 Subject: [PATCH 23/40] trying to fix lint --- x-pack/plugins/endpoint/server/plugin.ts | 2 +- x-pack/test/api_integration/apis/index.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/endpoint/server/plugin.ts b/x-pack/plugins/endpoint/server/plugin.ts index 17c8dce3be454..0fe6ab218cb2d 100644 --- a/x-pack/plugins/endpoint/server/plugin.ts +++ b/x-pack/plugins/endpoint/server/plugin.ts @@ -5,8 +5,8 @@ */ import { Plugin, CoreSetup, CoreStart } from 'kibana/server'; +import { PluginSetupContract as FeaturesPluginSetupContract } from '../../features/server'; import { addRoutes } from './routes'; -import { PluginSetupContract as FeaturesPluginSetupContract } from 'x-pack/plugins/features/server'; export interface PluginsSetup { features: FeaturesPluginSetupContract; diff --git a/x-pack/test/api_integration/apis/index.js b/x-pack/test/api_integration/apis/index.js index eea5b692abc4f..ddf2c9a13ff67 100644 --- a/x-pack/test/api_integration/apis/index.js +++ b/x-pack/test/api_integration/apis/index.js @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -export default function({ loadTestFile }) { - describe('apis', function() { +export default function ({ loadTestFile }) { + describe('apis', function () { this.tags('ciGroup6'); loadTestFile(require.resolve('./es')); From bbb33ee5f252d48baa8ccda610502579f60775af Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 2 Dec 2019 08:17:26 -0500 Subject: [PATCH 24/40] fixing typecheck --- x-pack/plugins/endpoint/server/plugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/endpoint/server/plugin.ts b/x-pack/plugins/endpoint/server/plugin.ts index 0fe6ab218cb2d..ce0c86d862c86 100644 --- a/x-pack/plugins/endpoint/server/plugin.ts +++ b/x-pack/plugins/endpoint/server/plugin.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Plugin, CoreSetup, CoreStart } from 'kibana/server'; +import { Plugin, CoreSetup } from 'kibana/server'; import { PluginSetupContract as FeaturesPluginSetupContract } from '../../features/server'; import { addRoutes } from './routes'; From 8e0f893c30c4f3e06f70392f1784e73d5f3fdf43 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 25 Nov 2019 22:35:28 -0500 Subject: [PATCH 25/40] first attempt at rendering an embeddable --- x-pack/plugins/endpoint/kibana.json | 2 +- .../embeddables/resolver/embeddable.tsx | 34 ++++++++++ .../public/embeddables/resolver/factory.ts | 31 +++++++++ .../public/embeddables/resolver/index.ts | 8 +++ x-pack/plugins/endpoint/public/plugin.ts | 14 ++++- .../resolver_test/common/flattened_promise.ts | 20 ++++++ .../plugins/resolver_test/kibana.json | 9 +++ .../applications/resolver_test/index.tsx | 63 +++++++++++++++++++ .../plugins/resolver_test/public/index.ts | 10 +++ .../plugins/resolver_test/public/plugin.ts | 36 +++++++++++ 10 files changed, 225 insertions(+), 2 deletions(-) create mode 100644 x-pack/plugins/endpoint/public/embeddables/resolver/embeddable.tsx create mode 100644 x-pack/plugins/endpoint/public/embeddables/resolver/factory.ts create mode 100644 x-pack/plugins/endpoint/public/embeddables/resolver/index.ts create mode 100644 x-pack/test/plugin_functional/plugins/resolver_test/common/flattened_promise.ts create mode 100644 x-pack/test/plugin_functional/plugins/resolver_test/kibana.json create mode 100644 x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx create mode 100644 x-pack/test/plugin_functional/plugins/resolver_test/public/index.ts create mode 100644 x-pack/test/plugin_functional/plugins/resolver_test/public/plugin.ts diff --git a/x-pack/plugins/endpoint/kibana.json b/x-pack/plugins/endpoint/kibana.json index 90a7076d0bd91..f7a4acd629324 100644 --- a/x-pack/plugins/endpoint/kibana.json +++ b/x-pack/plugins/endpoint/kibana.json @@ -3,7 +3,7 @@ "version": "1.0.0", "kibanaVersion": "kibana", "configPath": ["xpack", "endpoint"], - "requiredPlugins": ["features"], + "requiredPlugins": ["features", "embeddable"], "server": true, "ui": true } diff --git a/x-pack/plugins/endpoint/public/embeddables/resolver/embeddable.tsx b/x-pack/plugins/endpoint/public/embeddables/resolver/embeddable.tsx new file mode 100644 index 0000000000000..55f9fd52f4662 --- /dev/null +++ b/x-pack/plugins/endpoint/public/embeddables/resolver/embeddable.tsx @@ -0,0 +1,34 @@ +/* + * 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 { + EmbeddableInput, + IContainer, + Embeddable, +} from '../../../../../../src/plugins/embeddable/public'; + +export class ResolverEmbeddable extends Embeddable { + public readonly type = 'resolver'; + constructor(initialInput: EmbeddableInput, parent?: IContainer) { + super( + // Input state is irrelevant to this embeddable, just pass it along. + initialInput, + // Initial output state - this embeddable does not do anything with output, so just + // pass along an empty object. + {}, + // Optional parent component, this embeddable can optionally be rendered inside a container. + parent + ); + } + + public render(node: HTMLElement) { + node.innerHTML = '
Welcome from Resolver
'; + } + + public reload(): void { + throw new Error('Method not implemented.'); + } +} diff --git a/x-pack/plugins/endpoint/public/embeddables/resolver/factory.ts b/x-pack/plugins/endpoint/public/embeddables/resolver/factory.ts new file mode 100644 index 0000000000000..aef2e309254ef --- /dev/null +++ b/x-pack/plugins/endpoint/public/embeddables/resolver/factory.ts @@ -0,0 +1,31 @@ +/* + * 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 { i18n } from '@kbn/i18n'; +import { ResolverEmbeddable } from './'; +import { + EmbeddableFactory, + EmbeddableInput, + IContainer, +} from '../../../../../../src/plugins/embeddable/public'; + +export class ResolverEmbeddableFactory extends EmbeddableFactory { + public readonly type = 'resolver'; + + public isEditable() { + return true; + } + + public async create(initialInput: EmbeddableInput, parent?: IContainer) { + return new ResolverEmbeddable(initialInput, parent); + } + + public getDisplayName() { + return i18n.translate('xpack.endpoint.resolver.displayNameTitle', { + defaultMessage: 'Resolver', + }); + } +} diff --git a/x-pack/plugins/endpoint/public/embeddables/resolver/index.ts b/x-pack/plugins/endpoint/public/embeddables/resolver/index.ts new file mode 100644 index 0000000000000..e4f3cc90ae30a --- /dev/null +++ b/x-pack/plugins/endpoint/public/embeddables/resolver/index.ts @@ -0,0 +1,8 @@ +/* + * 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 { ResolverEmbeddableFactory } from './factory'; +export { ResolverEmbeddable } from './embeddable'; diff --git a/x-pack/plugins/endpoint/public/plugin.ts b/x-pack/plugins/endpoint/public/plugin.ts index 0094b01644f39..589f001ef5a4b 100644 --- a/x-pack/plugins/endpoint/public/plugin.ts +++ b/x-pack/plugins/endpoint/public/plugin.ts @@ -6,6 +6,12 @@ import { Plugin, CoreSetup } from 'kibana/public'; import { i18n } from '@kbn/i18n'; +import { ResolverEmbeddableFactory } from './embeddables/resolver'; +import { Plugin as EmbeddablePlugin } from '../../../../src/plugins/embeddable/public'; + +interface StartDependencies { + embeddable: ReturnType; +} export class EndpointPlugin implements Plugin<{}, {}> { public setup(core: CoreSetup) { @@ -22,7 +28,13 @@ export class EndpointPlugin implements Plugin<{}, {}> { return {}; } - public start() { + public start(...args: [unknown, StartDependencies]) { + const [, plugins] = args; + const resolverEmbeddableFactory = new ResolverEmbeddableFactory(); + plugins.embeddable.registerEmbeddableFactory( + resolverEmbeddableFactory.type, + resolverEmbeddableFactory + ); return {}; } diff --git a/x-pack/test/plugin_functional/plugins/resolver_test/common/flattened_promise.ts b/x-pack/test/plugin_functional/plugins/resolver_test/common/flattened_promise.ts new file mode 100644 index 0000000000000..14a37eb718411 --- /dev/null +++ b/x-pack/test/plugin_functional/plugins/resolver_test/common/flattened_promise.ts @@ -0,0 +1,20 @@ +/* + * 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 interface FlattenedPromise { + promise: Promise; + resolve: (value: T | PromiseLike | undefined) => void; + reject: (reason?: any) => void; +} + +export function flattenedPromise(): FlattenedPromise { + const returnValue: Partial> = {}; + returnValue.promise = new Promise(function(resolve, reject) { + returnValue.resolve = resolve; + returnValue.reject = reject; + }); + return returnValue as FlattenedPromise; +} diff --git a/x-pack/test/plugin_functional/plugins/resolver_test/kibana.json b/x-pack/test/plugin_functional/plugins/resolver_test/kibana.json new file mode 100644 index 0000000000000..c715a0aaa3b20 --- /dev/null +++ b/x-pack/test/plugin_functional/plugins/resolver_test/kibana.json @@ -0,0 +1,9 @@ +{ + "id": "resolver_test", + "version": "1.0.0", + "kibanaVersion": "kibana", + "configPath": ["xpack", "resolver_test"], + "requiredPlugins": ["embeddable"], + "server": false, + "ui": true +} diff --git a/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx b/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx new file mode 100644 index 0000000000000..dfb869ee0dff4 --- /dev/null +++ b/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx @@ -0,0 +1,63 @@ +/* + * 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 React from 'react'; +import ReactDOM from 'react-dom'; +import { AppMountContext, AppMountParameters } from 'kibana/public'; +import { I18nProvider, FormattedMessage } from '@kbn/i18n/react'; +import { IEmbeddable } from 'src/plugins/embeddable/public'; + +/** + * This module will be loaded asynchronously to reduce the bundle size of your plugin's main bundle. + */ +export function renderApp( + ...args: [AppMountContext, AppMountParameters, Promise] +) { + const [, { element }, embeddable] = args; + + ReactDOM.render( + + + , + element + ); + + return () => { + ReactDOM.unmountComponentAtNode(element); + }; +} + +const AppRoot: React.FC<{ + embeddable: Promise; +}> = React.memo(({ embeddable: embeddablePromise }) => { + const [embeddable, setEmbeddable] = React.useState(null); + + embeddablePromise.then(setEmbeddable); + + return ( + <> + {embeddable !== null && embeddable !== undefined && ( + + )} + + ); +}); + +const EmbeddableHouse: React.FunctionComponent<{ embeddable: IEmbeddable }> = ({ embeddable }) => { + const embeddableRef = React.createRef(); + if (embeddableRef.current !== embeddable && embeddableRef.current) { + // Should this component have this concern? + embeddable.destroy(); + } + + const callbackRef = React.useCallback( + function(element) { + embeddable.render(element); + }, + [embeddable] + ); + return
; +}; diff --git a/x-pack/test/plugin_functional/plugins/resolver_test/public/index.ts b/x-pack/test/plugin_functional/plugins/resolver_test/public/index.ts new file mode 100644 index 0000000000000..c5f3c0e19138f --- /dev/null +++ b/x-pack/test/plugin_functional/plugins/resolver_test/public/index.ts @@ -0,0 +1,10 @@ +/* + * 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 { PluginInitializer } from 'kibana/public'; +import { ResolverTestPlugin } from './plugin'; + +export const plugin: PluginInitializer = () => new ResolverTestPlugin(); diff --git a/x-pack/test/plugin_functional/plugins/resolver_test/public/plugin.ts b/x-pack/test/plugin_functional/plugins/resolver_test/public/plugin.ts new file mode 100644 index 0000000000000..c06786c64a22c --- /dev/null +++ b/x-pack/test/plugin_functional/plugins/resolver_test/public/plugin.ts @@ -0,0 +1,36 @@ +/* + * 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 { Plugin, CoreSetup } from 'kibana/public'; +import { i18n } from '@kbn/i18n'; +import { FlattenedPromise, flattenedPromise } from '../common/flattened_promise'; +import { + Start as EmbeddablePluginStart, + IEmbeddable, +} from '../../../../../../src/plugins/embeddable/public'; + +export class ResolverTestPlugin implements Plugin { + private embeddable: FlattenedPromise = flattenedPromise(); + public setup(core: CoreSetup) { + core.application.register({ + id: 'resolver_test', + title: i18n.translate('xpack.resolver_test.pluginTitle', { + defaultMessage: 'Resolver Test', + }), + mount: async (context, params) => { + const { renderApp } = await import('./applications/resolver_test'); + return renderApp(context, params, this.embeddable.promise); + }, + }); + } + + public start(...args: [unknown, { embeddable: EmbeddablePluginStart }]) { + const [, plugins] = args; + const factory = plugins.embeddable.getEmbeddableFactory('resolver'); + this.embeddable.resolve(factory.create({ id: 'what is id for?' })); + } + public stop() {} +} From 258eed6f866276717bc366d3c6e383093e942654 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 2 Dec 2019 11:13:36 -0500 Subject: [PATCH 26/40] rework the embeddable harness w/ new cool react skills --- .../resolver_test/common/flattened_promise.ts | 20 ------- .../applications/resolver_test/index.tsx | 53 ++++++++++--------- .../plugins/resolver_test/public/plugin.ts | 21 ++++---- 3 files changed, 39 insertions(+), 55 deletions(-) delete mode 100644 x-pack/test/plugin_functional/plugins/resolver_test/common/flattened_promise.ts diff --git a/x-pack/test/plugin_functional/plugins/resolver_test/common/flattened_promise.ts b/x-pack/test/plugin_functional/plugins/resolver_test/common/flattened_promise.ts deleted file mode 100644 index 14a37eb718411..0000000000000 --- a/x-pack/test/plugin_functional/plugins/resolver_test/common/flattened_promise.ts +++ /dev/null @@ -1,20 +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. - */ - -export interface FlattenedPromise { - promise: Promise; - resolve: (value: T | PromiseLike | undefined) => void; - reject: (reason?: any) => void; -} - -export function flattenedPromise(): FlattenedPromise { - const returnValue: Partial> = {}; - returnValue.promise = new Promise(function(resolve, reject) { - returnValue.resolve = resolve; - returnValue.reject = reject; - }); - return returnValue as FlattenedPromise; -} diff --git a/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx b/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx index dfb869ee0dff4..2ce821d47fdd6 100644 --- a/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx +++ b/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx @@ -7,8 +7,9 @@ import * as React from 'react'; import ReactDOM from 'react-dom'; import { AppMountContext, AppMountParameters } from 'kibana/public'; -import { I18nProvider, FormattedMessage } from '@kbn/i18n/react'; +import { I18nProvider } from '@kbn/i18n/react'; import { IEmbeddable } from 'src/plugins/embeddable/public'; +import { useEffect } from 'react'; /** * This module will be loaded asynchronously to reduce the bundle size of your plugin's main bundle. @@ -33,31 +34,31 @@ export function renderApp( const AppRoot: React.FC<{ embeddable: Promise; }> = React.memo(({ embeddable: embeddablePromise }) => { - const [embeddable, setEmbeddable] = React.useState(null); + const [embeddable, setEmbeddable] = React.useState(undefined); + const [renderTarget, setRenderTarget] = React.useState(null); - embeddablePromise.then(setEmbeddable); + useEffect(() => { + let reject; + Promise.race([ + new Promise((...args) => { + reject = args[1]; + }), + embeddablePromise, + ]).then(value => { + setEmbeddable(value); + }); - return ( - <> - {embeddable !== null && embeddable !== undefined && ( - - )} - - ); -}); + return reject; + }, [embeddablePromise]); -const EmbeddableHouse: React.FunctionComponent<{ embeddable: IEmbeddable }> = ({ embeddable }) => { - const embeddableRef = React.createRef(); - if (embeddableRef.current !== embeddable && embeddableRef.current) { - // Should this component have this concern? - embeddable.destroy(); - } - - const callbackRef = React.useCallback( - function(element) { - embeddable.render(element); - }, - [embeddable] - ); - return
; -}; + useEffect(() => { + if (embeddable && renderTarget) { + embeddable.render(renderTarget); + return () => { + embeddable.destroy(); + }; + } + }, [embeddable, renderTarget]); + + return
; +}); diff --git a/x-pack/test/plugin_functional/plugins/resolver_test/public/plugin.ts b/x-pack/test/plugin_functional/plugins/resolver_test/public/plugin.ts index c06786c64a22c..9bba05ab525ab 100644 --- a/x-pack/test/plugin_functional/plugins/resolver_test/public/plugin.ts +++ b/x-pack/test/plugin_functional/plugins/resolver_test/public/plugin.ts @@ -6,14 +6,17 @@ import { Plugin, CoreSetup } from 'kibana/public'; import { i18n } from '@kbn/i18n'; -import { FlattenedPromise, flattenedPromise } from '../common/flattened_promise'; -import { - Start as EmbeddablePluginStart, - IEmbeddable, -} from '../../../../../../src/plugins/embeddable/public'; +import { IEmbeddable, IEmbeddableStart } from '../../../../../../src/plugins/embeddable/public'; export class ResolverTestPlugin implements Plugin { - private embeddable: FlattenedPromise = flattenedPromise(); + private resolveEmbeddable!: ( + value: IEmbeddable | undefined | PromiseLike | undefined + ) => void; + private embeddablePromise: Promise = new Promise< + IEmbeddable | undefined + >(resolve => { + this.resolveEmbeddable = resolve; + }); public setup(core: CoreSetup) { core.application.register({ id: 'resolver_test', @@ -22,15 +25,15 @@ export class ResolverTestPlugin implements Plugin { }), mount: async (context, params) => { const { renderApp } = await import('./applications/resolver_test'); - return renderApp(context, params, this.embeddable.promise); + return renderApp(context, params, this.embeddablePromise); }, }); } - public start(...args: [unknown, { embeddable: EmbeddablePluginStart }]) { + public start(...args: [unknown, { embeddable: IEmbeddableStart }]) { const [, plugins] = args; const factory = plugins.embeddable.getEmbeddableFactory('resolver'); - this.embeddable.resolve(factory.create({ id: 'what is id for?' })); + this.resolveEmbeddable(factory.create({ id: 'test basic render' })); } public stop() {} } From e833e780aed228091e6351a20a295cf8dd4d14cd Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 2 Dec 2019 12:25:02 -0500 Subject: [PATCH 27/40] Cleanup Endpoint plugin definitions Export plugin setup and start interfaces Export plugin setup deps and start deps Remove Endpoint application registration --- x-pack/plugins/endpoint/public/index.ts | 15 +++++++-- x-pack/plugins/endpoint/public/plugin.ts | 39 +++++++++++------------- x-pack/plugins/endpoint/server/index.ts | 18 ++++++++--- x-pack/plugins/endpoint/server/plugin.ts | 18 ++++++++--- 4 files changed, 59 insertions(+), 31 deletions(-) diff --git a/x-pack/plugins/endpoint/public/index.ts b/x-pack/plugins/endpoint/public/index.ts index 062dd9ab93afa..e6a7683efd9a3 100644 --- a/x-pack/plugins/endpoint/public/index.ts +++ b/x-pack/plugins/endpoint/public/index.ts @@ -5,6 +5,17 @@ */ import { PluginInitializer } from 'kibana/public'; -import { EndpointPlugin } from './plugin'; +import { + EndpointPlugin, + EndpointPluginStart, + EndpointPluginSetup, + EndpointPluginStartDependencies, + EndpointPluginSetupDependencies, +} from './plugin'; -export const plugin: PluginInitializer<{}, {}> = () => new EndpointPlugin(); +export const plugin: PluginInitializer< + EndpointPluginSetup, + EndpointPluginStart, + EndpointPluginSetupDependencies, + EndpointPluginStartDependencies +> = () => new EndpointPlugin(); diff --git a/x-pack/plugins/endpoint/public/plugin.ts b/x-pack/plugins/endpoint/public/plugin.ts index 589f001ef5a4b..916d9bed09c6a 100644 --- a/x-pack/plugins/endpoint/public/plugin.ts +++ b/x-pack/plugins/endpoint/public/plugin.ts @@ -4,38 +4,35 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Plugin, CoreSetup } from 'kibana/public'; -import { i18n } from '@kbn/i18n'; +import { Plugin } from 'kibana/public'; +import { IEmbeddableStart } from 'src/plugins/embeddable/public'; import { ResolverEmbeddableFactory } from './embeddables/resolver'; -import { Plugin as EmbeddablePlugin } from '../../../../src/plugins/embeddable/public'; -interface StartDependencies { - embeddable: ReturnType; +export type EndpointPluginStart = void; +export type EndpointPluginSetup = void; +export interface EndpointPluginSetupDependencies {} // eslint-disable-line @typescript-eslint/no-empty-interface + +export interface EndpointPluginStartDependencies { + embeddable: IEmbeddableStart; } -export class EndpointPlugin implements Plugin<{}, {}> { - public setup(core: CoreSetup) { - core.application.register({ - id: 'endpoint', - title: i18n.translate('xpack.endpoint.pluginTitle', { - defaultMessage: 'Endpoint', - }), - async mount(context, params) { - const { renderApp } = await import('./applications/endpoint'); - return renderApp(context, params); - }, - }); - return {}; - } +export class EndpointPlugin + implements + Plugin< + EndpointPluginSetup, + EndpointPluginStart, + EndpointPluginSetupDependencies, + EndpointPluginStartDependencies + > { + public setup() {} - public start(...args: [unknown, StartDependencies]) { + public start(...args: [unknown, EndpointPluginStartDependencies]) { const [, plugins] = args; const resolverEmbeddableFactory = new ResolverEmbeddableFactory(); plugins.embeddable.registerEmbeddableFactory( resolverEmbeddableFactory.type, resolverEmbeddableFactory ); - return {}; } public stop() {} diff --git a/x-pack/plugins/endpoint/server/index.ts b/x-pack/plugins/endpoint/server/index.ts index 26c2bbd5ef873..f10bc7ee51b2c 100644 --- a/x-pack/plugins/endpoint/server/index.ts +++ b/x-pack/plugins/endpoint/server/index.ts @@ -5,12 +5,22 @@ */ import { schema } from '@kbn/config-schema'; -import { EndpointPlugin } from './plugin'; +import { PluginInitializer } from 'src/core/server'; +import { + EndpointPlugin, + EndpointPluginStart, + EndpointPluginSetup, + EndpointPluginStartDependencies, + EndpointPluginSetupDependencies, +} from './plugin'; export const config = { schema: schema.object({ enabled: schema.boolean({ defaultValue: false }) }), }; -export function plugin() { - return new EndpointPlugin(); -} +export const plugin: PluginInitializer< + EndpointPluginStart, + EndpointPluginSetup, + EndpointPluginStartDependencies, + EndpointPluginSetupDependencies +> = () => new EndpointPlugin(); diff --git a/x-pack/plugins/endpoint/server/plugin.ts b/x-pack/plugins/endpoint/server/plugin.ts index ce0c86d862c86..1ab271042b54b 100644 --- a/x-pack/plugins/endpoint/server/plugin.ts +++ b/x-pack/plugins/endpoint/server/plugin.ts @@ -8,12 +8,23 @@ import { Plugin, CoreSetup } from 'kibana/server'; import { PluginSetupContract as FeaturesPluginSetupContract } from '../../features/server'; import { addRoutes } from './routes'; -export interface PluginsSetup { +export type EndpointPluginStart = void; +export type EndpointPluginSetup = void; +export interface EndpointPluginSetupDependencies { features: FeaturesPluginSetupContract; } -export class EndpointPlugin implements Plugin { - public setup(core: CoreSetup, plugins: PluginsSetup) { +export interface EndpointPluginStartDependencies {} // eslint-disable-line @typescript-eslint/no-empty-interface + +export class EndpointPlugin + implements + Plugin< + EndpointPluginStart, + EndpointPluginSetup, + EndpointPluginStartDependencies, + EndpointPluginSetupDependencies + > { + public setup(core: CoreSetup, plugins: EndpointPluginSetupDependencies) { plugins.features.registerFeature({ id: 'endpoint', name: 'Endpoint', @@ -36,5 +47,4 @@ export class EndpointPlugin implements Plugin { } public start() {} - public stop() {} } From 27dffa576422c0717261ed66531e21bbf01a314f Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 2 Dec 2019 12:26:36 -0500 Subject: [PATCH 28/40] Cleanup Resolver test messages --- x-pack/test/api_integration/apis/endpoint/index.ts | 2 +- x-pack/test/api_integration/apis/endpoint/resolver.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/test/api_integration/apis/endpoint/index.ts b/x-pack/test/api_integration/apis/endpoint/index.ts index eaab3b1f18657..e0ffbb13e5978 100644 --- a/x-pack/test/api_integration/apis/endpoint/index.ts +++ b/x-pack/test/api_integration/apis/endpoint/index.ts @@ -7,7 +7,7 @@ import { FtrProviderContext } from '../../ftr_provider_context'; export default function endpointAPIIntegrationTests({ loadTestFile }: FtrProviderContext) { - describe('Endpoint', function() { + describe('Endpoint plugin', function() { loadTestFile(require.resolve('./resolver')); }); } diff --git a/x-pack/test/api_integration/apis/endpoint/resolver.ts b/x-pack/test/api_integration/apis/endpoint/resolver.ts index 42278ab4ac238..96d16e0d76e40 100644 --- a/x-pack/test/api_integration/apis/endpoint/resolver.ts +++ b/x-pack/test/api_integration/apis/endpoint/resolver.ts @@ -15,8 +15,8 @@ const commonHeaders = { // eslint-disable-next-line import/no-default-export export default function resolverAPIIntegrationTests({ getService }: FtrProviderContext) { const supertest = getService('supertest'); - describe('Resolver', function() { - it('should response to hello-world', async function() { + describe('Resolver api', function() { + it('should respond to hello-world', async function() { const { body } = await supertest .get('/api/endpoint/hello-world') .set(commonHeaders) From e59993750bf650d5e9884fd5904d059f51f5b045 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 2 Dec 2019 12:28:02 -0500 Subject: [PATCH 29/40] Remove Endpoint app functional tests --- x-pack/test/functional/apps/endpoint/index.ts | 24 ------------------- x-pack/test/functional/config.js | 4 ---- 2 files changed, 28 deletions(-) delete mode 100644 x-pack/test/functional/apps/endpoint/index.ts diff --git a/x-pack/test/functional/apps/endpoint/index.ts b/x-pack/test/functional/apps/endpoint/index.ts deleted file mode 100644 index 4465242b018e0..0000000000000 --- a/x-pack/test/functional/apps/endpoint/index.ts +++ /dev/null @@ -1,24 +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 { FtrProviderContext } from '../../ftr_provider_context'; - -export default function({ getPageObjects, getService }: FtrProviderContext) { - const pageObjects = getPageObjects(['common']); - const testSubjects = getService('testSubjects'); - - describe('The Endpoint app', function() { - this.tags('ciGroup7'); - - beforeEach(async function() { - await pageObjects.common.navigateToApp('endpoint'); - }); - - it("welcomes the user with 'Hello World'", async function() { - await testSubjects.existOrFail('welcomeTitle'); - }); - }); -} diff --git a/x-pack/test/functional/config.js b/x-pack/test/functional/config.js index 9e6bed2d20f4a..7c3464a1cbd45 100644 --- a/x-pack/test/functional/config.js +++ b/x-pack/test/functional/config.js @@ -56,7 +56,6 @@ export default async function ({ readConfigFile }) { resolve(__dirname, './apps/cross_cluster_replication'), resolve(__dirname, './apps/remote_clusters'), resolve(__dirname, './apps/transform'), - resolve(__dirname, './apps/endpoint'), // This license_management file must be last because it is destructive. resolve(__dirname, './apps/license_management'), ], @@ -199,9 +198,6 @@ export default async function ({ readConfigFile }) { pathname: '/app/kibana/', hash: '/management/elasticsearch/transform', }, - endpoint: { - pathname: '/app/endpoint', - }, }, // choose where esArchiver should load archives from From a2288a94401fb48bed7a4cd341461b43b7c8848a Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 2 Dec 2019 12:29:40 -0500 Subject: [PATCH 30/40] Don't enable endpoint plugin in functional tests --- x-pack/test/functional/config.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/x-pack/test/functional/config.js b/x-pack/test/functional/config.js index 7c3464a1cbd45..f4b2be3420298 100644 --- a/x-pack/test/functional/config.js +++ b/x-pack/test/functional/config.js @@ -86,7 +86,6 @@ export default async function ({ readConfigFile }) { '--xpack.encryptedSavedObjects.encryptionKey="DkdXazszSCYexXqz4YktBGHCRkV6hyNK"', '--telemetry.banner=false', '--timelion.ui.enabled=true', - '--xpack.endpoint.enabled=true', ], }, uiSettings: { @@ -154,10 +153,10 @@ export default async function ({ readConfigFile }) { pathname: '/app/uptime', }, apm: { - pathname: '/app/apm', + pathname: '/app/apm' }, ml: { - pathname: '/app/ml', + pathname: '/app/ml' }, rollupJob: { pathname: '/app/kibana', @@ -196,8 +195,8 @@ export default async function ({ readConfigFile }) { }, transform: { pathname: '/app/kibana/', - hash: '/management/elasticsearch/transform', - }, + hash: '/management/elasticsearch/transform' + } }, // choose where esArchiver should load archives from From 51f3d9e2ffaa03bc9f3ab4b811a7042459f6d063 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 2 Dec 2019 12:37:07 -0500 Subject: [PATCH 31/40] Remove Endpoint plugin feature registration --- x-pack/plugins/endpoint/kibana.json | 2 +- x-pack/plugins/endpoint/server/plugin.ts | 23 ++--------------------- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/x-pack/plugins/endpoint/kibana.json b/x-pack/plugins/endpoint/kibana.json index f7a4acd629324..a7fd20b93f62d 100644 --- a/x-pack/plugins/endpoint/kibana.json +++ b/x-pack/plugins/endpoint/kibana.json @@ -3,7 +3,7 @@ "version": "1.0.0", "kibanaVersion": "kibana", "configPath": ["xpack", "endpoint"], - "requiredPlugins": ["features", "embeddable"], + "requiredPlugins": ["embeddable"], "server": true, "ui": true } diff --git a/x-pack/plugins/endpoint/server/plugin.ts b/x-pack/plugins/endpoint/server/plugin.ts index 1ab271042b54b..559e4abf69066 100644 --- a/x-pack/plugins/endpoint/server/plugin.ts +++ b/x-pack/plugins/endpoint/server/plugin.ts @@ -10,9 +10,7 @@ import { addRoutes } from './routes'; export type EndpointPluginStart = void; export type EndpointPluginSetup = void; -export interface EndpointPluginSetupDependencies { - features: FeaturesPluginSetupContract; -} +export interface EndpointPluginSetupDependencies {} // eslint-disable-line @typescript-eslint/no-empty-interface export interface EndpointPluginStartDependencies {} // eslint-disable-line @typescript-eslint/no-empty-interface @@ -24,24 +22,7 @@ export class EndpointPlugin EndpointPluginStartDependencies, EndpointPluginSetupDependencies > { - public setup(core: CoreSetup, plugins: EndpointPluginSetupDependencies) { - plugins.features.registerFeature({ - id: 'endpoint', - name: 'Endpoint', - icon: 'bug', - navLinkId: 'endpoint', - app: ['endpoint', 'kibana'], - privileges: { - read: { - api: ['resolver'], - savedObject: { - all: [], - read: [], - }, - ui: ['show'], - }, - }, - }); + public setup(core: CoreSetup) { const router = core.http.createRouter(); addRoutes(router); } From 719a648993d9c746e34aa607753a2e6a3f9d7616 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 2 Dec 2019 12:42:47 -0500 Subject: [PATCH 32/40] Remove endpoint app --- .../public/applications/endpoint/index.tsx | 31 ------------------- 1 file changed, 31 deletions(-) delete mode 100644 x-pack/plugins/endpoint/public/applications/endpoint/index.tsx diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx deleted file mode 100644 index 73adc2defe604..0000000000000 --- a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx +++ /dev/null @@ -1,31 +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 React from 'react'; -import ReactDOM from 'react-dom'; -import { AppMountContext, AppMountParameters } from 'kibana/public'; -import { I18nProvider, FormattedMessage } from '@kbn/i18n/react'; - -/** - * This module will be loaded asynchronously to reduce the bundle size of your plugin's main bundle. - */ -export function renderApp(appMountContext: AppMountContext, { element }: AppMountParameters) { - appMountContext.core.http.get('/api/endpoint/hello-world'); - - ReactDOM.render(, element); - - return () => { - ReactDOM.unmountComponentAtNode(element); - }; -} - -const AppRoot = React.memo(() => ( - -

- -

-
-)); From 7c045a7ad070f96145cc7df781bf4a125cbeae98 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 2 Dec 2019 12:48:18 -0500 Subject: [PATCH 33/40] Enable endpoint plugin in api integration tests --- x-pack/test/api_integration/config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/test/api_integration/config.js b/x-pack/test/api_integration/config.js index 4794a7bee5dfb..6e35a6f31d79b 100644 --- a/x-pack/test/api_integration/config.js +++ b/x-pack/test/api_integration/config.js @@ -25,6 +25,7 @@ export async function getApiIntegrationConfig({ readConfigFile }) { ...xPackFunctionalTestsConfig.get('kbnTestServer.serverArgs'), '--xpack.security.session.idleTimeout=3600000', // 1 hour '--optimize.enabled=false', + '--xpack.endpoint.enabled=true', ], }, esTestCluster: { From e905f870a837eacf9a40c8eca667603ff13e1411 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 2 Dec 2019 14:57:55 -0500 Subject: [PATCH 34/40] Remove unused type --- x-pack/plugins/endpoint/server/plugin.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/endpoint/server/plugin.ts b/x-pack/plugins/endpoint/server/plugin.ts index 559e4abf69066..400b906c5230e 100644 --- a/x-pack/plugins/endpoint/server/plugin.ts +++ b/x-pack/plugins/endpoint/server/plugin.ts @@ -5,7 +5,6 @@ */ import { Plugin, CoreSetup } from 'kibana/server'; -import { PluginSetupContract as FeaturesPluginSetupContract } from '../../features/server'; import { addRoutes } from './routes'; export type EndpointPluginStart = void; From 8b5e63db851638006222a2175b346af670376271 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 2 Dec 2019 15:02:33 -0500 Subject: [PATCH 35/40] Add functional tests for plugins to x-pack --- x-pack/scripts/functional_tests.js | 1 + x-pack/test/plugin_functional/config.ts | 72 +++++++++++++++++++ .../ftr_provider_context.d.ts | 11 +++ x-pack/test/plugin_functional/page_objects.ts | 6 ++ .../applications/resolver_test/index.tsx | 2 +- x-pack/test/plugin_functional/services.ts | 7 ++ .../test_suites/resolver/index.ts | 27 +++++++ 7 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 x-pack/test/plugin_functional/config.ts create mode 100644 x-pack/test/plugin_functional/ftr_provider_context.d.ts create mode 100644 x-pack/test/plugin_functional/page_objects.ts create mode 100644 x-pack/test/plugin_functional/services.ts create mode 100644 x-pack/test/plugin_functional/test_suites/resolver/index.ts diff --git a/x-pack/scripts/functional_tests.js b/x-pack/scripts/functional_tests.js index 2ac8fff6ef8ab..6efe35dd58e7b 100644 --- a/x-pack/scripts/functional_tests.js +++ b/x-pack/scripts/functional_tests.js @@ -15,6 +15,7 @@ require('@kbn/test').runTestsCli([ require.resolve('../test/alerting_api_integration/spaces_only/config.ts'), require.resolve('../test/alerting_api_integration/security_and_spaces/config.ts'), require.resolve('../test/plugin_api_integration/config.js'), + require.resolve('../test/plugin_functional/config.js'), require.resolve('../test/kerberos_api_integration/config'), require.resolve('../test/kerberos_api_integration/anonymous_access.config'), require.resolve('../test/saml_api_integration/config'), diff --git a/x-pack/test/plugin_functional/config.ts b/x-pack/test/plugin_functional/config.ts new file mode 100644 index 0000000000000..6c3c496da71f6 --- /dev/null +++ b/x-pack/test/plugin_functional/config.ts @@ -0,0 +1,72 @@ +/* + * 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 { resolve } from 'path'; +import fs from 'fs'; +import { FtrConfigProviderContext } from '@kbn/test/types/ftr'; +import { services } from './services'; +import { pageObjects } from './page_objects'; + +// the default export of config files must be a config provider +// that returns an object with the projects config values + +/* eslint-disable import/no-default-export */ +export default async function({ readConfigFile }: FtrConfigProviderContext) { + const xpackFunctionalConfig = await readConfigFile(require.resolve('../functional/config.js')); + + // Find all folders in ./plugins since we treat all them as plugin folder + const allFiles = fs.readdirSync(resolve(__dirname, 'plugins')); + const plugins = allFiles.filter(file => + fs.statSync(resolve(__dirname, 'plugins', file)).isDirectory() + ); + + return { + // list paths to the files that contain your plugins tests + testFiles: [resolve(__dirname, './test_suites/resolver')], + + services, + pageObjects, + + servers: xpackFunctionalConfig.get('servers'), + + esTestCluster: xpackFunctionalConfig.get('esTestCluster'), + + kbnTestServer: { + ...xpackFunctionalConfig.get('kbnTestServer'), + serverArgs: [ + ...xpackFunctionalConfig.get('kbnTestServer.serverArgs'), + ...plugins.map(pluginDir => `--plugin-path=${resolve(__dirname, 'plugins', pluginDir)}`), + // Required to load new platform plugins via `--plugin-path` flag. + '--env.name=development', + '--xpack.endpoint.enabled=true', + ], + }, + uiSettings: xpackFunctionalConfig.get('uiSettings'), + // the apps section defines the urls that + // `PageObjects.common.navigateTo(appKey)` will use. + // Merge urls for your plugin with the urls defined in + // Kibana's config in order to use this helper + apps: { + ...xpackFunctionalConfig.get('apps'), + resolverTest: { + pathname: '/app/resolver_test', + }, + }, + + // choose where esArchiver should load archives from + esArchiver: { + directory: resolve(__dirname, 'es_archives'), + }, + + // choose where screenshots should be saved + screenshots: { + directory: resolve(__dirname, 'screenshots'), + }, + + junit: { + reportName: 'Chrome X-Pack UI Plugin Functional Tests', + }, + }; +} diff --git a/x-pack/test/plugin_functional/ftr_provider_context.d.ts b/x-pack/test/plugin_functional/ftr_provider_context.d.ts new file mode 100644 index 0000000000000..271f313d4bda9 --- /dev/null +++ b/x-pack/test/plugin_functional/ftr_provider_context.d.ts @@ -0,0 +1,11 @@ +/* + * 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 { GenericFtrProviderContext } from '@kbn/test/types/ftr'; +import { services } from './services'; +import { pageObjects } from './page_objects'; + +export type FtrProviderContext = GenericFtrProviderContext; diff --git a/x-pack/test/plugin_functional/page_objects.ts b/x-pack/test/plugin_functional/page_objects.ts new file mode 100644 index 0000000000000..a216b0f2cd47a --- /dev/null +++ b/x-pack/test/plugin_functional/page_objects.ts @@ -0,0 +1,6 @@ +/* + * 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 { pageObjects } from '../functional/page_objects'; diff --git a/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx b/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx index 2ce821d47fdd6..3ac955884b28b 100644 --- a/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx +++ b/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx @@ -60,5 +60,5 @@ const AppRoot: React.FC<{ } }, [embeddable, renderTarget]); - return
; + return
; }); diff --git a/x-pack/test/plugin_functional/services.ts b/x-pack/test/plugin_functional/services.ts new file mode 100644 index 0000000000000..5c807720b2867 --- /dev/null +++ b/x-pack/test/plugin_functional/services.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 { services } from '../functional/services'; diff --git a/x-pack/test/plugin_functional/test_suites/resolver/index.ts b/x-pack/test/plugin_functional/test_suites/resolver/index.ts new file mode 100644 index 0000000000000..a0735f216e309 --- /dev/null +++ b/x-pack/test/plugin_functional/test_suites/resolver/index.ts @@ -0,0 +1,27 @@ +/* + * 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 { FtrProviderContext } from '../../ftr_provider_context'; + +export default function({ getPageObjects, getService }: FtrProviderContext) { + const pageObjects = getPageObjects(['common']); + const testSubjects = getService('testSubjects'); + + describe('Resolver embeddable test app', function() { + this.tags('ciGroup7'); + + beforeEach(async function() { + await pageObjects.common.navigateToApp('resolverTest'); + }); + + it('renders a container div for the embeddable', async function() { + await testSubjects.existOrFail('resolverEmbeddableContainer'); + }); + it('renders resolver', async function() { + await testSubjects.existOrFail('resolverEmbeddable'); + }); + }); +} From 5dd5256d8a595681b6bff5d6085cc9560e71231a Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 2 Dec 2019 16:22:01 -0500 Subject: [PATCH 36/40] Fix x-pack functional tests script --- x-pack/scripts/functional_tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/scripts/functional_tests.js b/x-pack/scripts/functional_tests.js index 6efe35dd58e7b..18ab9bad52450 100644 --- a/x-pack/scripts/functional_tests.js +++ b/x-pack/scripts/functional_tests.js @@ -15,7 +15,7 @@ require('@kbn/test').runTestsCli([ require.resolve('../test/alerting_api_integration/spaces_only/config.ts'), require.resolve('../test/alerting_api_integration/security_and_spaces/config.ts'), require.resolve('../test/plugin_api_integration/config.js'), - require.resolve('../test/plugin_functional/config.js'), + require.resolve('../test/plugin_functional/config'), require.resolve('../test/kerberos_api_integration/config'), require.resolve('../test/kerberos_api_integration/anonymous_access.config'), require.resolve('../test/saml_api_integration/config'), From 485ed57b8a40261eecce1f5cfde7dc29d9709adb Mon Sep 17 00:00:00 2001 From: oatkiller Date: Tue, 3 Dec 2019 09:14:36 -0500 Subject: [PATCH 37/40] great use of our time --- x-pack/plugins/endpoint/public/plugin.ts | 5 ++--- x-pack/plugins/endpoint/server/routes/index.ts | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/endpoint/public/plugin.ts b/x-pack/plugins/endpoint/public/plugin.ts index 916d9bed09c6a..37cb9ee48872e 100644 --- a/x-pack/plugins/endpoint/public/plugin.ts +++ b/x-pack/plugins/endpoint/public/plugin.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Plugin } from 'kibana/public'; +import { Plugin, CoreStart } from 'kibana/public'; import { IEmbeddableStart } from 'src/plugins/embeddable/public'; import { ResolverEmbeddableFactory } from './embeddables/resolver'; @@ -26,8 +26,7 @@ export class EndpointPlugin > { public setup() {} - public start(...args: [unknown, EndpointPluginStartDependencies]) { - const [, plugins] = args; + public start(_core: CoreStart, plugins: EndpointPluginStartDependencies) { const resolverEmbeddableFactory = new ResolverEmbeddableFactory(); plugins.embeddable.registerEmbeddableFactory( resolverEmbeddableFactory.type, diff --git a/x-pack/plugins/endpoint/server/routes/index.ts b/x-pack/plugins/endpoint/server/routes/index.ts index c2b3ab8fa1658..8eab6cd384765 100644 --- a/x-pack/plugins/endpoint/server/routes/index.ts +++ b/x-pack/plugins/endpoint/server/routes/index.ts @@ -15,8 +15,7 @@ export function addRoutes(router: IRouter) { tags: ['access:resolver'], }, }, - async function greetingIndex(...passedArgs) { - const [, , response] = passedArgs; + async function greetingIndex(_context, _request, response) { return response.ok({ body: { hello: 'world' }, headers: { From 72a38af19d5928bb3755bd96acd0078d8cbe47c4 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Thu, 5 Dec 2019 09:00:19 -0500 Subject: [PATCH 38/40] change interface of renderApp in resolver_test plugin --- .../public/applications/resolver_test/index.tsx | 7 +++---- .../plugins/resolver_test/public/plugin.ts | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx b/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx index 3ac955884b28b..67149d94ff69c 100644 --- a/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx +++ b/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx @@ -6,7 +6,7 @@ import * as React from 'react'; import ReactDOM from 'react-dom'; -import { AppMountContext, AppMountParameters } from 'kibana/public'; +import { AppMountParameters } from 'kibana/public'; import { I18nProvider } from '@kbn/i18n/react'; import { IEmbeddable } from 'src/plugins/embeddable/public'; import { useEffect } from 'react'; @@ -15,10 +15,9 @@ import { useEffect } from 'react'; * This module will be loaded asynchronously to reduce the bundle size of your plugin's main bundle. */ export function renderApp( - ...args: [AppMountContext, AppMountParameters, Promise] + { element }: AppMountParameters, + embeddable: Promise ) { - const [, { element }, embeddable] = args; - ReactDOM.render( diff --git a/x-pack/test/plugin_functional/plugins/resolver_test/public/plugin.ts b/x-pack/test/plugin_functional/plugins/resolver_test/public/plugin.ts index 9bba05ab525ab..c7a81003a51dd 100644 --- a/x-pack/test/plugin_functional/plugins/resolver_test/public/plugin.ts +++ b/x-pack/test/plugin_functional/plugins/resolver_test/public/plugin.ts @@ -23,9 +23,9 @@ export class ResolverTestPlugin implements Plugin { title: i18n.translate('xpack.resolver_test.pluginTitle', { defaultMessage: 'Resolver Test', }), - mount: async (context, params) => { + mount: async (_context, params) => { const { renderApp } = await import('./applications/resolver_test'); - return renderApp(context, params, this.embeddablePromise); + return renderApp(params, this.embeddablePromise); }, }); } From bdd633d87025737701a457906e1077b6adf5b6b1 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Fri, 6 Dec 2019 09:47:01 -0500 Subject: [PATCH 39/40] remove tags from resolver route. --- x-pack/plugins/endpoint/server/routes/index.ts | 3 --- x-pack/test/api_integration/config.js | 6 ++---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/endpoint/server/routes/index.ts b/x-pack/plugins/endpoint/server/routes/index.ts index 8eab6cd384765..517ee2a853660 100644 --- a/x-pack/plugins/endpoint/server/routes/index.ts +++ b/x-pack/plugins/endpoint/server/routes/index.ts @@ -11,9 +11,6 @@ export function addRoutes(router: IRouter) { { path: '/api/endpoint/hello-world', validate: false, - options: { - tags: ['access:resolver'], - }, }, async function greetingIndex(_context, _request, response) { return response.ok({ diff --git a/x-pack/test/api_integration/config.js b/x-pack/test/api_integration/config.js index 6e35a6f31d79b..e5860fba80770 100644 --- a/x-pack/test/api_integration/config.js +++ b/x-pack/test/api_integration/config.js @@ -7,9 +7,7 @@ import { services } from './services'; export async function getApiIntegrationConfig({ readConfigFile }) { - const xPackFunctionalTestsConfig = await readConfigFile( - require.resolve('../functional/config.js') - ); + const xPackFunctionalTestsConfig = await readConfigFile(require.resolve('../functional/config.js')); return { testFiles: [require.resolve('./apis')], @@ -32,7 +30,7 @@ export async function getApiIntegrationConfig({ readConfigFile }) { ...xPackFunctionalTestsConfig.get('esTestCluster'), serverArgs: [ ...xPackFunctionalTestsConfig.get('esTestCluster.serverArgs'), - 'node.attr.name=apiIntegrationTestNode', + 'node.attr.name=apiIntegrationTestNode' ], }, }; From 14047360b7394fece9652999da534d91914cb2cc Mon Sep 17 00:00:00 2001 From: oatkiller Date: Fri, 6 Dec 2019 10:01:53 -0500 Subject: [PATCH 40/40] style nits, register embeddable in setup --- x-pack/plugins/endpoint/public/plugin.ts | 18 +++--- .../applications/resolver_test/index.tsx | 62 +++++++++---------- .../plugins/resolver_test/public/plugin.ts | 16 ++++- 3 files changed, 55 insertions(+), 41 deletions(-) diff --git a/x-pack/plugins/endpoint/public/plugin.ts b/x-pack/plugins/endpoint/public/plugin.ts index 37cb9ee48872e..21bf1b3cdea12 100644 --- a/x-pack/plugins/endpoint/public/plugin.ts +++ b/x-pack/plugins/endpoint/public/plugin.ts @@ -4,18 +4,18 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Plugin, CoreStart } from 'kibana/public'; -import { IEmbeddableStart } from 'src/plugins/embeddable/public'; +import { Plugin, CoreSetup } from 'kibana/public'; +import { IEmbeddableSetup } from 'src/plugins/embeddable/public'; import { ResolverEmbeddableFactory } from './embeddables/resolver'; export type EndpointPluginStart = void; export type EndpointPluginSetup = void; -export interface EndpointPluginSetupDependencies {} // eslint-disable-line @typescript-eslint/no-empty-interface - -export interface EndpointPluginStartDependencies { - embeddable: IEmbeddableStart; +export interface EndpointPluginSetupDependencies { + embeddable: IEmbeddableSetup; } +export interface EndpointPluginStartDependencies {} // eslint-disable-line @typescript-eslint/no-empty-interface + export class EndpointPlugin implements Plugin< @@ -24,9 +24,7 @@ export class EndpointPlugin EndpointPluginSetupDependencies, EndpointPluginStartDependencies > { - public setup() {} - - public start(_core: CoreStart, plugins: EndpointPluginStartDependencies) { + public setup(_core: CoreSetup, plugins: EndpointPluginSetupDependencies) { const resolverEmbeddableFactory = new ResolverEmbeddableFactory(); plugins.embeddable.registerEmbeddableFactory( resolverEmbeddableFactory.type, @@ -34,5 +32,7 @@ export class EndpointPlugin ); } + public start() {} + public stop() {} } diff --git a/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx b/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx index 67149d94ff69c..98baad6a18411 100644 --- a/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx +++ b/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx @@ -30,34 +30,34 @@ export function renderApp( }; } -const AppRoot: React.FC<{ - embeddable: Promise; -}> = React.memo(({ embeddable: embeddablePromise }) => { - const [embeddable, setEmbeddable] = React.useState(undefined); - const [renderTarget, setRenderTarget] = React.useState(null); - - useEffect(() => { - let reject; - Promise.race([ - new Promise((...args) => { - reject = args[1]; - }), - embeddablePromise, - ]).then(value => { - setEmbeddable(value); - }); - - return reject; - }, [embeddablePromise]); - - useEffect(() => { - if (embeddable && renderTarget) { - embeddable.render(renderTarget); - return () => { - embeddable.destroy(); - }; - } - }, [embeddable, renderTarget]); - - return
; -}); +const AppRoot = React.memo( + ({ embeddable: embeddablePromise }: { embeddable: Promise }) => { + const [embeddable, setEmbeddable] = React.useState(undefined); + const [renderTarget, setRenderTarget] = React.useState(null); + + useEffect(() => { + let cleanUp; + Promise.race([ + new Promise((_resolve, reject) => { + cleanUp = reject; + }), + embeddablePromise, + ]).then(value => { + setEmbeddable(value); + }); + + return cleanUp; + }, [embeddablePromise]); + + useEffect(() => { + if (embeddable && renderTarget) { + embeddable.render(renderTarget); + return () => { + embeddable.destroy(); + }; + } + }, [embeddable, renderTarget]); + + return
; + } +); diff --git a/x-pack/test/plugin_functional/plugins/resolver_test/public/plugin.ts b/x-pack/test/plugin_functional/plugins/resolver_test/public/plugin.ts index c7a81003a51dd..f063271f4b5dd 100644 --- a/x-pack/test/plugin_functional/plugins/resolver_test/public/plugin.ts +++ b/x-pack/test/plugin_functional/plugins/resolver_test/public/plugin.ts @@ -8,7 +8,21 @@ import { Plugin, CoreSetup } from 'kibana/public'; import { i18n } from '@kbn/i18n'; import { IEmbeddable, IEmbeddableStart } from '../../../../../../src/plugins/embeddable/public'; -export class ResolverTestPlugin implements Plugin { +export type ResolverTestPluginSetup = void; +export type ResolverTestPluginStart = void; +export interface ResolverTestPluginSetupDependencies {} // eslint-disable-line @typescript-eslint/no-empty-interface +export interface ResolverTestPluginStartDependencies { + embeddable: IEmbeddableStart; +} + +export class ResolverTestPlugin + implements + Plugin< + ResolverTestPluginSetup, + ResolverTestPluginStart, + ResolverTestPluginSetupDependencies, + ResolverTestPluginStartDependencies + > { private resolveEmbeddable!: ( value: IEmbeddable | undefined | PromiseLike | undefined ) => void;