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

[7.x] [Endpoint] Adding Endpoint to 7.x #57867

Merged
merged 26 commits into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c6d1274
Add Endpoint plugin and Resolver embeddable (#51994)
oatkiller Dec 6, 2019
d3c2959
[Endpoint] Register endpoint app (#53527)
kevinlog Dec 20, 2019
bab46fb
[Endpoint] add react router to endpoint app (#53808)
kevinlog Jan 2, 2020
7b3b8b3
EMT-issue-65: add endpoint list api (#53861)
nnamdifrankie Jan 7, 2020
2cfa0c4
EMT-65:always return accurate endpoint count (#54423)
nnamdifrankie Jan 10, 2020
8e245a3
Resolver component w/ sample data (#53619)
Jan 14, 2020
1dfa7bc
Resolver test plugin not using mount context. (#54933)
Jan 15, 2020
ec6cc64
Resolver nonlinear zoom (#54936)
dplumlee Jan 15, 2020
c2d6b22
[Endpoint] add Redux saga Middleware and app Store (#53906)
paul-tavares Jan 16, 2020
6696019
Resolver is overflow: hidden to prevent obscured elements from showin…
Jan 16, 2020
ade4523
[Endpoint] Fix saga to start only after store is created and stopped …
paul-tavares Jan 21, 2020
258809b
Resolver zoom, pan, and center controls (#55221)
peluja1012 Jan 21, 2020
699e844
[Endpoint] FIX: Increase tests `sleep` default duration back to 100ms…
paul-tavares Jan 22, 2020
6027287
[Endpoint] EMT-65: make endpoint data types common, restructure (#54772)
nnamdifrankie Jan 27, 2020
b9c6c7b
Basic Functionality Alert List (#55800)
dplumlee Jan 29, 2020
0e9579b
[Endpoint] Add Endpoint Details route (#55746)
pzl Jan 30, 2020
9425ac8
[Endpoint] EMT-67: add kql support for endpoint list (#56328)
nnamdifrankie Feb 4, 2020
959a693
[Endpoint] ERT-82 ERT-83 ERT-84: Alert list API with pagination (#56538)
madirey Feb 6, 2020
e74f1e5
Add Test to Verify Endpoint App Landing Page (#57129)
charlie-pichette Feb 7, 2020
0b94abe
fixes render bug in alert list (#57152)
dplumlee Feb 10, 2020
a42da00
Resolver: Animate camera, add sidebar (#55590)
Feb 14, 2020
2adb98d
[Endpoint] Task/basic endpoint list (#55623)
parkiino Feb 14, 2020
5bf1134
[Endpoint] Policy List UI route and initial view (#56918)
paul-tavares Feb 14, 2020
08a7ea6
Add ApplicationService app status management (#50223)
pgayvallet Jan 12, 2020
1ff6799
Implements `getStartServices` on server-side (#55156)
pgayvallet Jan 20, 2020
ac24b5e
[ui/utils/query_string]: Remove unused methods & migrate apps to quer…
alexwizp Feb 12, 2020
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
87 changes: 72 additions & 15 deletions test/functional/page_objects/common_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
const defaultTryTimeout = config.get('timeouts.try');
const defaultFindTimeout = config.get('timeouts.find');

interface NavigateProps {
appConfig: {};
ensureCurrentUrl: boolean;
shouldLoginIfPrompted: boolean;
shouldAcceptAlert: boolean;
useActualUrl: boolean;
}

class CommonPage {
/**
* Navigates the browser window to provided URL
Expand Down Expand Up @@ -115,6 +123,34 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
return currentUrl;
}

private async navigate(navigateProps: NavigateProps) {
const {
appConfig,
ensureCurrentUrl,
shouldLoginIfPrompted,
shouldAcceptAlert,
useActualUrl,
} = navigateProps;
const appUrl = getUrl.noAuth(config.get('servers.kibana'), appConfig);

await retry.try(async () => {
if (useActualUrl) {
log.debug(`navigateToActualUrl ${appUrl}`);
await browser.get(appUrl);
} else {
await CommonPage.navigateToUrlAndHandleAlert(appUrl, shouldAcceptAlert);
}

const currentUrl = shouldLoginIfPrompted
? await this.loginIfPrompted(appUrl)
: await browser.getCurrentUrl();

if (ensureCurrentUrl && !currentUrl.includes(appUrl)) {
throw new Error(`expected ${currentUrl}.includes(${appUrl})`);
}
});
}

/**
* Navigates browser using the pathname from the appConfig and subUrl as the hash
* @param appName As defined in the apps config, e.g. 'home'
Expand All @@ -137,23 +173,44 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
hash: useActualUrl ? subUrl : `/${appName}/${subUrl}`,
};

const appUrl = getUrl.noAuth(config.get('servers.kibana'), appConfig);

await retry.try(async () => {
if (useActualUrl) {
log.debug(`navigateToActualUrl ${appUrl}`);
await browser.get(appUrl);
} else {
await CommonPage.navigateToUrlAndHandleAlert(appUrl, shouldAcceptAlert);
}
await this.navigate({
appConfig,
ensureCurrentUrl,
shouldLoginIfPrompted,
shouldAcceptAlert,
useActualUrl,
});
}

const currentUrl = shouldLoginIfPrompted
? await this.loginIfPrompted(appUrl)
: await browser.getCurrentUrl();
/**
* Navigates browser using the pathname from the appConfig and subUrl as the extended path.
* This was added to be able to test an application that uses browser history over hash history.
* @param appName As defined in the apps config, e.g. 'home'
* @param subUrl The route after the appUrl, e.g. 'tutorial_directory/sampleData'
* @param args additional arguments
*/
public async navigateToUrlWithBrowserHistory(
appName: string,
subUrl?: string,
{
basePath = '',
ensureCurrentUrl = true,
shouldLoginIfPrompted = true,
shouldAcceptAlert = true,
useActualUrl = true,
} = {}
) {
const appConfig = {
// subUrl following the basePath, assumes no hashes. Ex: 'app/endpoint/management'
pathname: `${basePath}${config.get(['apps', appName]).pathname}${subUrl}`,
};

if (ensureCurrentUrl && !currentUrl.includes(appUrl)) {
throw new Error(`expected ${currentUrl}.includes(${appUrl})`);
}
await this.navigate({
appConfig,
ensureCurrentUrl,
shouldLoginIfPrompted,
shouldAcceptAlert,
useActualUrl,
});
}

Expand Down
3 changes: 2 additions & 1 deletion x-pack/.i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"xpack.transform": "legacy/plugins/transform",
"xpack.upgradeAssistant": "legacy/plugins/upgrade_assistant",
"xpack.uptime": "legacy/plugins/uptime",
"xpack.watcher": "plugins/watcher"
"xpack.watcher": "plugins/watcher",
"xpack.endpoint": "plugins/endpoint"
},
"translations": [
"plugins/translations/translations/zh-CN.json",
Expand Down
121 changes: 121 additions & 0 deletions x-pack/plugins/endpoint/common/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* 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.
*/

/**
* A deep readonly type that will make all children of a given object readonly recursively
*/
export type Immutable<T> = T extends undefined | null | boolean | string | number
? T
: T extends Array<infer U>
? ImmutableArray<U>
: T extends Map<infer K, infer V>
? ImmutableMap<K, V>
: T extends Set<infer M>
? ImmutableSet<M>
: ImmutableObject<T>;

export type ImmutableArray<T> = ReadonlyArray<Immutable<T>>;
export type ImmutableMap<K, V> = ReadonlyMap<Immutable<K>, Immutable<V>>;
export type ImmutableSet<T> = ReadonlySet<Immutable<T>>;
export type ImmutableObject<T> = { readonly [K in keyof T]: Immutable<T[K]> };

export class EndpointAppConstants {
static ALERT_INDEX_NAME = 'my-index';
static ENDPOINT_INDEX_NAME = 'endpoint-agent*';
}

export interface AlertResultList {
/**
* The alerts restricted by page size.
*/
alerts: AlertData[];

/**
* The total number of alerts on the page.
*/
total: number;

/**
* The size of the requested page.
*/
request_page_size: number;

/**
* The index of the requested page, starting at 0.
*/
request_page_index: number;

/**
* The offset of the requested page, starting at 0.
*/
result_from_index: number;
}

export interface EndpointResultList {
/* the endpoints restricted by the page size */
endpoints: EndpointMetadata[];
/* the total number of unique endpoints in the index */
total: number;
/* the page size requested */
request_page_size: number;
/* the page index requested */
request_page_index: number;
}

export interface AlertData {
'@timestamp': Date;
agent: {
id: string;
version: string;
};
event: {
action: string;
};
file_classification: {
malware_classification: {
score: number;
};
};
host: {
hostname: string;
ip: string;
os: {
name: string;
};
};
thread: {};
}

export interface EndpointMetadata {
event: {
created: Date;
};
endpoint: {
policy: {
id: string;
};
};
agent: {
version: string;
id: string;
};
host: {
id: string;
hostname: string;
ip: string[];
mac: string[];
os: {
name: string;
full: string;
version: string;
};
};
}

/**
* The PageId type is used for the payload when firing userNavigatedToPage actions
*/
export type PageId = 'alertsPage' | 'managementPage' | 'policyListPage';
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": ["features", "embeddable"],
"server": true,
"ui": true
}
15 changes: 15 additions & 0 deletions x-pack/plugins/endpoint/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"author": "Elastic",
"name": "endpoint",
"version": "0.0.0",
"private": true,
"license": "Elastic-License",
"scripts": {},
"dependencies": {
"react-redux": "^7.1.0"
},
"devDependencies": {
"@types/react-redux": "^7.1.0",
"redux-devtools-extension": "^2.13.8"
}
}
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 styled from 'styled-components';

export const TruncateText = styled.div`
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
`;
65 changes: 65 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,65 @@
/*
* 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 { CoreStart, AppMountParameters } from 'kibana/public';
import { I18nProvider, FormattedMessage } from '@kbn/i18n/react';
import { Route, BrowserRouter, Switch } from 'react-router-dom';
import { Provider } from 'react-redux';
import { Store } from 'redux';
import { appStoreFactory } from './store';
import { AlertIndex } from './view/alerts';
import { ManagementList } from './view/managing';
import { PolicyList } from './view/policy';

/**
* This module will be loaded asynchronously to reduce the bundle size of your plugin's main bundle.
*/
export function renderApp(coreStart: CoreStart, { appBasePath, element }: AppMountParameters) {
coreStart.http.get('/api/endpoint/hello-world');

const store = appStoreFactory(coreStart);

ReactDOM.render(<AppRoot basename={appBasePath} store={store} />, element);

return () => {
ReactDOM.unmountComponentAtNode(element);
};
}

interface RouterProps {
basename: string;
store: Store;
}

const AppRoot: React.FunctionComponent<RouterProps> = React.memo(({ basename, store }) => (
<Provider store={store}>
<I18nProvider>
<BrowserRouter basename={basename}>
<Switch>
<Route
exact
path="/"
render={() => (
<h1 data-test-subj="welcomeTitle">
<FormattedMessage id="xpack.endpoint.welcomeTitle" defaultMessage="Hello World" />
</h1>
)}
/>
<Route path="/management" component={ManagementList} />
<Route path="/alerts" component={AlertIndex} />
<Route path="/policy" exact component={PolicyList} />
<Route
render={() => (
<FormattedMessage id="xpack.endpoint.notFound" defaultMessage="Page Not Found" />
)}
/>
</Switch>
</BrowserRouter>
</I18nProvider>
</Provider>
));
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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 * from './saga';
Loading