From 9299846458e2d9b8522dcd9c5aa7b7da383b32cf Mon Sep 17 00:00:00 2001 From: oatkiller Date: Thu, 7 Nov 2019 08:09:16 -0500 Subject: [PATCH] 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', + }, + }); +}