-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Endpoint] Resolver harness without endpoint app #51994
Changes from all commits
447e095
2a15ab0
f8428a1
ed09f4c
654b8cd
c9eaa0c
f699a0d
4c2e079
b29b336
6134b31
325e8d1
22b2738
212c144
7910246
8d9fda0
0294f8e
e1cc28c
cde3717
4185228
599018e
0573352
f6b7ec6
eda5b36
bbb33ee
8e0f893
258eed6
e833e78
27dffa5
e599937
a2288a9
51f3d9e
719a648
7c045a7
e905f87
8b5e63d
5dd5256
485ed57
72a38af
bdd633d
1404736
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
} |
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'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You probably want to have a single const and export that so a caller can get the factory using it,
|
||
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.'); | ||
} | ||
} |
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'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a standard for importing stuff from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stacey-gammon might know the answer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now the recommendation is relative paths. There is some ongoing work/discussion about supporting a better alternative, but it isn't finished yet. Follow #40446 for progress. Eventually, we hope that the recommendation can be to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm importing using tsserver exclusively so its no bother to me. has good compatibility w/ IDEs i think |
||
|
||
export class ResolverEmbeddableFactory extends EmbeddableFactory { | ||
public readonly type = 'resolver'; | ||
|
||
public isEditable() { | ||
return true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you know this already, but just in case, when you bring back feature controls code, you'll want to grab this value from the capabilities service, e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pretty confused about that stuff tbh. I've read some of the docs on the site but I don't know how to set it up right. |
||
} | ||
|
||
public async create(initialInput: EmbeddableInput, parent?: IContainer) { | ||
return new ResolverEmbeddable(initialInput, parent); | ||
} | ||
|
||
public getDisplayName() { | ||
return i18n.translate('xpack.endpoint.resolver.displayNameTitle', { | ||
defaultMessage: 'Resolver', | ||
}); | ||
} | ||
} |
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'; |
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(); |
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() {} | ||
} |
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(); |
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() {} | ||
} |
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', | ||
}, | ||
}); | ||
} | ||
); | ||
} |
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')); | ||
}); | ||
} |
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' }); | ||
}); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stacey told me to alphabetize this