Skip to content

Commit

Permalink
Add a stub endpoint plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
oatkiller committed Nov 14, 2019
1 parent ab9aa3e commit 9299846
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 0 deletions.
8 changes: 8 additions & 0 deletions x-pack/plugins/endpoint/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "endpoint",
"version": "1.0.0",
"kibanaVersion": "kibana",
"configPath": ["x-pack", "endpoint"],
"server": true,
"ui": true
}
26 changes: 26 additions & 0 deletions x-pack/plugins/endpoint/public/applications/endpoint/index.tsx
Original file line number Diff line number Diff line change
@@ -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(<AppRoot />, element);

return function() {
ReactDOM.unmountComponentAtNode(element);
};
}

const AppRoot = React.memo(function Root() {
return <h1>Welcome to Endpoint</h1>;
});
15 changes: 15 additions & 0 deletions x-pack/plugins/endpoint/public/index.ts
Original file line number Diff line number Diff line change
@@ -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();
27 changes: 27 additions & 0 deletions x-pack/plugins/endpoint/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -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() {}
}
16 changes: 16 additions & 0 deletions x-pack/plugins/endpoint/server/index.ts
Original file line number Diff line number Diff line change
@@ -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();
}
18 changes: 18 additions & 0 deletions x-pack/plugins/endpoint/server/plugin.ts
Original file line number Diff line number Diff line change
@@ -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() {}
}
27 changes: 27 additions & 0 deletions x-pack/plugins/endpoint/server/routes/index.ts
Original file line number Diff line number Diff line change
@@ -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',
},
});
}

0 comments on commit 9299846

Please sign in to comment.