-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Endpoint plugin and Resolver embeddable (#51994)
* Add functional tests for plugins to x-pack (so we can do a functional test of the Resolver embeddable) * Add Endpoint plugin * Add Resolver embeddable * Test that Resolver embeddable can be rendered
- Loading branch information
Showing
24 changed files
with
529 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"id": "endpoint", | ||
"version": "1.0.0", | ||
"kibanaVersion": "kibana", | ||
"configPath": ["xpack", "endpoint"], | ||
"requiredPlugins": ["embeddable"], | ||
"server": true, | ||
"ui": true | ||
} |
34 changes: 34 additions & 0 deletions
34
x-pack/plugins/endpoint/public/embeddables/resolver/embeddable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = '<div data-test-subj="resolverEmbeddable">Welcome from Resolver</div>'; | ||
} | ||
|
||
public reload(): void { | ||
throw new Error('Method not implemented.'); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
x-pack/plugins/endpoint/public/embeddables/resolver/factory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* 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 { | ||
EndpointPlugin, | ||
EndpointPluginStart, | ||
EndpointPluginSetup, | ||
EndpointPluginStartDependencies, | ||
EndpointPluginSetupDependencies, | ||
} from './plugin'; | ||
|
||
export const plugin: PluginInitializer< | ||
EndpointPluginSetup, | ||
EndpointPluginStart, | ||
EndpointPluginSetupDependencies, | ||
EndpointPluginStartDependencies | ||
> = () => new EndpointPlugin(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* 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 { IEmbeddableSetup } from 'src/plugins/embeddable/public'; | ||
import { ResolverEmbeddableFactory } from './embeddables/resolver'; | ||
|
||
export type EndpointPluginStart = void; | ||
export type EndpointPluginSetup = void; | ||
export interface EndpointPluginSetupDependencies { | ||
embeddable: IEmbeddableSetup; | ||
} | ||
|
||
export interface EndpointPluginStartDependencies {} // eslint-disable-line @typescript-eslint/no-empty-interface | ||
|
||
export class EndpointPlugin | ||
implements | ||
Plugin< | ||
EndpointPluginSetup, | ||
EndpointPluginStart, | ||
EndpointPluginSetupDependencies, | ||
EndpointPluginStartDependencies | ||
> { | ||
public setup(_core: CoreSetup, plugins: EndpointPluginSetupDependencies) { | ||
const resolverEmbeddableFactory = new ResolverEmbeddableFactory(); | ||
plugins.embeddable.registerEmbeddableFactory( | ||
resolverEmbeddableFactory.type, | ||
resolverEmbeddableFactory | ||
); | ||
} | ||
|
||
public start() {} | ||
|
||
public stop() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { schema } from '@kbn/config-schema'; | ||
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 const plugin: PluginInitializer< | ||
EndpointPluginStart, | ||
EndpointPluginSetup, | ||
EndpointPluginStartDependencies, | ||
EndpointPluginSetupDependencies | ||
> = () => new EndpointPlugin(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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 type EndpointPluginStart = void; | ||
export type EndpointPluginSetup = void; | ||
export interface EndpointPluginSetupDependencies {} // eslint-disable-line @typescript-eslint/no-empty-interface | ||
|
||
export interface EndpointPluginStartDependencies {} // eslint-disable-line @typescript-eslint/no-empty-interface | ||
|
||
export class EndpointPlugin | ||
implements | ||
Plugin< | ||
EndpointPluginStart, | ||
EndpointPluginSetup, | ||
EndpointPluginStartDependencies, | ||
EndpointPluginSetupDependencies | ||
> { | ||
public setup(core: CoreSetup) { | ||
const router = core.http.createRouter(); | ||
addRoutes(router); | ||
} | ||
|
||
public start() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* 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 } from 'kibana/server'; | ||
|
||
export function addRoutes(router: IRouter) { | ||
router.get( | ||
{ | ||
path: '/api/endpoint/hello-world', | ||
validate: false, | ||
}, | ||
async function greetingIndex(_context, _request, response) { | ||
return response.ok({ | ||
body: { hello: 'world' }, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 plugin', function() { | ||
loadTestFile(require.resolve('./resolver')); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 api', function() { | ||
it('should respond 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' }); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.