Skip to content
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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
447e095
Add a stub endpoint plugin
Nov 7, 2019
2a15ab0
Fix config path for endpoint plugin
Nov 15, 2019
f8428a1
Remove useless config schema definition from public endpoint plugin
Nov 15, 2019
ed09f4c
Prefix endpoint route w/ `api`
Nov 15, 2019
654b8cd
added api smoketest for resolver
Nov 15, 2019
c9eaa0c
i18n for stub Endpoint application
Nov 18, 2019
f699a0d
Track translations in endpoint plugin
Nov 18, 2019
4c2e079
Add translations too?
Nov 18, 2019
b29b336
Only enable endpoint in x-pack api integration tests
Nov 18, 2019
6134b31
Add basic functional test
Nov 19, 2019
325e8d1
remove unused import
Nov 19, 2019
22b2738
Move page object access into beforeEach
Nov 19, 2019
212c144
Remove access to services and page objects before test has started
Nov 19, 2019
7910246
Select ci group 7 for functional tests
Nov 19, 2019
8d9fda0
More tags. everyone gets tags
Nov 19, 2019
0294f8e
i18n id conforms guidelines,remove API test ci tag
Nov 19, 2019
e1cc28c
remove useless endpoint.enabled flag in API integration tests
Nov 19, 2019
cde3717
Make an attempt/guess at registering plugin features
Nov 20, 2019
4185228
Remove useless translation file
Nov 21, 2019
599018e
Alphabetize x-pack/.i18nrc.json
Nov 21, 2019
0573352
code formatting changes
Nov 21, 2019
f6b7ec6
fix formatting of x-pack/.i18nrc.json
Nov 21, 2019
eda5b36
trying to fix lint
Nov 21, 2019
bbb33ee
fixing typecheck
Dec 2, 2019
8e0f893
first attempt at rendering an embeddable
Nov 26, 2019
258eed6
rework the embeddable harness w/ new cool react skills
Dec 2, 2019
e833e78
Cleanup Endpoint plugin definitions
Dec 2, 2019
27dffa5
Cleanup Resolver test messages
Dec 2, 2019
e599937
Remove Endpoint app functional tests
Dec 2, 2019
a2288a9
Don't enable endpoint plugin in functional tests
Dec 2, 2019
51f3d9e
Remove Endpoint plugin feature registration
Dec 2, 2019
719a648
Remove endpoint app
Dec 2, 2019
7c045a7
Enable endpoint plugin in api integration tests
Dec 2, 2019
e905f87
Remove unused type
Dec 2, 2019
8b5e63d
Add functional tests for plugins to x-pack
Dec 2, 2019
5dd5256
Fix x-pack functional tests script
Dec 2, 2019
485ed57
great use of our time
Dec 3, 2019
72a38af
change interface of renderApp in resolver_test plugin
Dec 5, 2019
bdd633d
remove tags from resolver route.
Dec 6, 2019
1404736
style nits, register embeddable in setup
Dec 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions x-pack/.i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Copy link
Contributor Author

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

"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",
Expand Down
9 changes: 9 additions & 0 deletions x-pack/plugins/endpoint/kibana.json
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 x-pack/plugins/endpoint/public/embeddables/resolver/embeddable.tsx
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';
Copy link
Contributor

Choose a reason for hiding this comment

The 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,

context.embeddable.getEmbeddableFactory(RESOLVER_EMBEDDABLE).create()

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 x-pack/plugins/endpoint/public/embeddables/resolver/factory.ts
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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a standard for importing stuff from kibana v. doing a relative path import?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stacey-gammon might know the answer

Copy link
Contributor

Choose a reason for hiding this comment

The 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 src/plugins/..., which can work, but using that now can also kill your jest tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
Copy link
Contributor

Choose a reason for hiding this comment

The 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. return capabilities.endpoint.save as boolean; https://www.elastic.co/guide/en/kibana/7.5/development-plugin-feature-registration.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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',
});
}
}
8 changes: 8 additions & 0 deletions x-pack/plugins/endpoint/public/embeddables/resolver/index.ts
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';
21 changes: 21 additions & 0 deletions x-pack/plugins/endpoint/public/index.ts
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();
38 changes: 38 additions & 0 deletions x-pack/plugins/endpoint/public/plugin.ts
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() {}
}
26 changes: 26 additions & 0 deletions x-pack/plugins/endpoint/server/index.ts
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();
30 changes: 30 additions & 0 deletions x-pack/plugins/endpoint/server/plugin.ts
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() {}
}
24 changes: 24 additions & 0 deletions x-pack/plugins/endpoint/server/routes/index.ts
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',
},
});
}
);
}
1 change: 1 addition & 0 deletions x-pack/scripts/functional_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
require.resolve('../test/kerberos_api_integration/config'),
require.resolve('../test/kerberos_api_integration/anonymous_access.config'),
require.resolve('../test/saml_api_integration/config'),
Expand Down
13 changes: 13 additions & 0 deletions x-pack/test/api_integration/apis/endpoint/index.ts
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'));
});
}
29 changes: 29 additions & 0 deletions x-pack/test/api_integration/apis/endpoint/resolver.ts
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' });
});
});
}
1 change: 1 addition & 0 deletions x-pack/test/api_integration/apis/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
}
1 change: 1 addition & 0 deletions x-pack/test/api_integration/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Loading