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

[BeatsCM] Cleanup and refactor #26425

Closed
wants to merge 53 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
f9c2c5e
update security check from master merge
mattapperson Nov 7, 2018
bcd96e7
aditional cleanup
mattapperson Nov 7, 2018
a0d6dd2
update types
mattapperson Nov 7, 2018
902b72d
put the default config where it’s supposed to go
mattapperson Nov 8, 2018
cd15eb6
pages first pass
mattapperson Nov 8, 2018
3509065
wip
mattapperson Nov 12, 2018
583101b
tags container started
mattapperson Nov 12, 2018
1ab6951
router is now on fleek
mattapperson Nov 13, 2018
ac02408
fixed toast on beats page
mattapperson Nov 13, 2018
13da819
cleanup
mattapperson Nov 13, 2018
c9ea1c4
more cleanup
mattapperson Nov 14, 2018
6621b47
lots more cleanup
mattapperson Nov 14, 2018
bb54341
push settings to the UI cleanly and re-add check for default user roles
mattapperson Nov 14, 2018
c7f58e9
cleanup beat routes
mattapperson Nov 14, 2018
e5d0763
add route overide, fix UI access to plugin settings
mattapperson Nov 14, 2018
04b8aa8
management sections now always render
mattapperson Nov 14, 2018
e91a5f6
Kibana adapter is fully typed
mattapperson Nov 16, 2018
1f65822
add aditional typing and validation to the ClientFramework adapter
mattapperson Nov 16, 2018
9a1655e
remove some io-ts as function type is broken
mattapperson Nov 16, 2018
494f2e2
remove more io-ts
mattapperson Nov 16, 2018
643fdfa
slightly more reliable UI hooks
mattapperson Nov 16, 2018
197a88a
Routing works
mattapperson Nov 17, 2018
4ae22f8
Merge branch '6.x' of github.com:elastic/kibana into refactors/lib-ad…
mattapperson Nov 17, 2018
733a20a
routing now works again
mattapperson Nov 17, 2018
f19cd2e
All styles are now in userland vs adapter
mattapperson Nov 17, 2018
7b0b22d
assert user data for runtime
mattapperson Nov 17, 2018
98f27ce
remove duplicate comments
mattapperson Nov 17, 2018
fd656c0
progress
mattapperson Nov 20, 2018
92033b6
initial enroll flow working again
mattapperson Nov 20, 2018
986a2a5
walkthrough finished
mattapperson Nov 20, 2018
8cdf8ff
enrolled_beats page now loading
mattapperson Nov 20, 2018
deb9c12
upgrade routing
mattapperson Nov 21, 2018
507cdc2
remove console.log
mattapperson Nov 21, 2018
f3ab87a
cleanup
mattapperson Nov 21, 2018
cafb583
cleanup comments
mattapperson Nov 21, 2018
0dd9788
ignore 404 for getting all tags, just return empty
mattapperson Nov 22, 2018
8da0cae
add (currently failing) tests for the file based client route system
mattapperson Nov 22, 2018
ad9caaf
finished route builder upgrades with tests
mattapperson Nov 22, 2018
a8dcd2a
Routing now fully functional
mattapperson Nov 27, 2018
0ee0e21
progress
mattapperson Nov 28, 2018
a87b7e2
fix containers
mattapperson Nov 29, 2018
4a64e1c
reconnect KQL query bar
mattapperson Nov 29, 2018
559b87f
connect tags list to container state
mattapperson Nov 29, 2018
80368a0
fix links out of tags page
mattapperson Nov 29, 2018
d42b31c
cleanup
mattapperson Nov 29, 2018
6a7d6f5
added breadcrumbs and toggle k7design
mattapperson Nov 30, 2018
d48ddc6
UI tweak
mattapperson Nov 30, 2018
1d9c5f9
Merge branch '6.x' of github.com:elastic/kibana into refactors/lib-ad…
mattapperson Nov 30, 2018
05bdabc
fix import order
mattapperson Nov 30, 2018
edadcba
Merge branch '6.x' of github.com:elastic/kibana into refactors/lib-ad…
mattapperson Nov 30, 2018
3bf8e1c
Merge branch '6.x' of github.com:elastic/kibana into refactors/lib-ad…
mattapperson Dec 3, 2018
ba4b69a
Merge branch '6.x' of github.com:elastic/kibana into refactors/lib-ad…
mattapperson Dec 4, 2018
bad8e0a
Merge branch '6.x' of github.com:elastic/kibana into refactors/lib-ad…
mattapperson Dec 4, 2018
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"@kbn/pm": "1.0.0",
"@kbn/test-subj-selector": "0.2.1",
"@kbn/ui-framework": "1.0.0",
"@types/chalk": "^2.2.0",
"JSONStream": "1.1.1",
"abortcontroller-polyfill": "^1.1.9",
"angular": "1.6.9",
Expand Down
2 changes: 2 additions & 0 deletions x-pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"icalendar": "0.7.1",
"inline-style": "^2.0.0",
"intl": "^1.2.5",
"io-ts": "^1.4.1",
"isomorphic-fetch": "2.2.1",
"joi": "^13.5.2",
"jquery": "^3.3.1",
Expand Down Expand Up @@ -258,6 +259,7 @@
"typescript-fsa-reducers": "^0.4.5",
"ui-select": "0.19.4",
"unbzip2-stream": "1.0.9",
"unstated": "^2.1.1",
"uuid": "3.0.1",
"venn.js": "0.2.9",
"xregexp": "3.2.0"
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/beats_management/common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
export { PLUGIN } from './plugin';
export { INDEX_NAMES } from './index_names';
export { UNIQUENESS_ENFORCING_TYPES, ConfigurationBlockTypes } from './configuration_blocks';
export const BASE_PATH = '/management/beats_management/';
export const BASE_PATH = '/management/beats_management';
export { TABLE_CONFIG } from './table';
export { REQUIRED_ROLES, LICENSES, REQUIRED_LICENSES } from './security';
1 change: 1 addition & 0 deletions x-pack/plugins/beats_management/common/constants/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
export const PLUGIN = {
ID: 'beats_management',
};
export const CONFIG_PREFIX = 'xpack.beats';
10 changes: 10 additions & 0 deletions x-pack/plugins/beats_management/common/constants/security.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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 const REQUIRED_ROLES = ['beats_admin'];
export const REQUIRED_LICENSES = ['standard', 'gold', 'trial', 'platinum'];
export const LICENSES = ['oss', 'standard', 'gold', 'trial', 'platinum'];
export type LicenseType = 'oss' | 'trial' | 'standard' | 'basic' | 'gold' | 'platinum';
9 changes: 5 additions & 4 deletions x-pack/plugins/beats_management/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@
import Joi from 'joi';
import { resolve } from 'path';
import { PLUGIN } from './common/constants';
import { CONFIG_PREFIX } from './common/constants/plugin';
import { initServerWithKibana } from './server/kibana.index';
import { KibanaLegacyServer } from './server/lib/adapters/framework/adapter_types';

const DEFAULT_ENROLLMENT_TOKENS_TTL_S = 10 * 60; // 10 minutes

export const config = Joi.object({
enabled: Joi.boolean().default(true),
encryptionKey: Joi.string(),
defaultUserRoles: Joi.array()
.items(Joi.string())
.default(['superuser']),
encryptionKey: Joi.string().default('xpack_beats_default_encryptionKey'),
enrollmentTokensTtlInSeconds: Joi.number()
.integer()
.min(1)
.max(10 * 60 * 14) // No more then 2 weeks for security reasons
.default(DEFAULT_ENROLLMENT_TOKENS_TTL_S),
}).default();
export const configPrefix = 'xpack.beats';

export function beats(kibana: any) {
return new kibana.Plugin({
Expand All @@ -33,8 +34,8 @@ export function beats(kibana: any) {
managementSections: ['plugins/beats_management'],
},
config: () => config,
configPrefix,
init(server: any) {
configPrefix: CONFIG_PREFIX,
init(server: KibanaLegacyServer) {
initServerWithKibana(server);
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import {
// @ts-ignore typings for EuiBasicTable not present in current version
EuiBasicTable,
EuiButton,
EuiFlexGroup,
EuiFlexItem,
EuiLoadingSpinner,
Expand All @@ -15,37 +14,42 @@ import {
EuiSelect,
EuiTitle,
} from '@elastic/eui';
import { FormattedMessage, InjectedIntl, injectI18n } from '@kbn/i18n/react';
import { FormattedMessage } from '@kbn/i18n/react';
import { capitalize } from 'lodash';
import React from 'react';
import { RouteComponentProps } from 'react-router';
import { CMBeat } from '../../../common/domain_types';
import { AppURLState } from '../../app';
import { URLStateProps, withUrlState } from '../../containers/with_url_state';
import { FrontendLibs } from '../../lib/lib';
import { CMBeat } from '../../common/domain_types';

interface BeatsProps extends URLStateProps<AppURLState>, RouteComponentProps<any> {
match: any;
libs: FrontendLibs;
intl: InjectedIntl;
interface ComponentProps {
/** Such as kibanas basePath, for use to generate command */
frameworkBasePath?: string;
enrollmentToken?: string;
getBeatWithToken(token: string): Promise<CMBeat | null>;
createEnrollmentToken(): Promise<void>;
onBeatEnrolled(enrolledBeat: CMBeat): void;
}
export class EnrollBeat extends React.Component<BeatsProps, any> {

interface ComponentState {
enrolledBeat: CMBeat | null;
hasPolledForBeat: boolean;
command: string;
beatType: string;
}

export class EnrollBeat extends React.Component<ComponentProps, ComponentState> {
private pinging = false;
constructor(props: BeatsProps) {
constructor(props: ComponentProps) {
super(props);

this.state = {
enrolledBeat: null,
hasPolledForBeat: false,
command: 'sudo filebeat',
beatType: 'filebeat',
};
}
public pingForBeatWithToken = async (
libs: FrontendLibs,
token: string
): Promise<CMBeat | void> => {
public pingForBeatWithToken = async (token: string): Promise<CMBeat | void> => {
try {
const beats = await libs.beats.getBeatWithToken(token);
const beats = await this.props.getBeatWithToken(token);
if (!beats) {
throw new Error('no beats');
}
Expand All @@ -54,69 +58,34 @@ export class EnrollBeat extends React.Component<BeatsProps, any> {
if (this.pinging) {
const timeout = (ms: number) => new Promise(res => setTimeout(res, ms));
await timeout(5000);
return await this.pingForBeatWithToken(libs, token);
return await this.pingForBeatWithToken(token);
}
}
};
public async componentDidMount() {
if (!this.props.urlState.enrollmentToken) {
const enrollmentToken = await this.props.libs.tokens.createEnrollmentToken();
this.props.setUrlState({
enrollmentToken,
});
if (!this.props.enrollmentToken) {
await this.props.createEnrollmentToken();
}
}
public waitForToken = async (token: string) => {
if (this.pinging) {
public waitForTokenToEnrollBeat = async () => {
if (this.pinging || !this.props.enrollmentToken) {
return;
}
this.pinging = true;
const enrolledBeat = (await this.pingForBeatWithToken(this.props.libs, token)) as CMBeat;
const enrolledBeat = (await this.pingForBeatWithToken(this.props.enrollmentToken)) as CMBeat;

this.setState({
enrolledBeat,
});
this.props.onBeatEnrolled(enrolledBeat);
this.pinging = false;
};
public render() {
if (!this.props.urlState.enrollmentToken) {
if (!this.props.enrollmentToken) {
return null;
}
if (this.props.urlState.enrollmentToken && !this.state.enrolledBeat) {
this.waitForToken(this.props.urlState.enrollmentToken);
}
const { goTo, intl } = this.props;

const actions = [];

switch (this.props.location.pathname) {
case '/overview/initial/beats':
actions.push({
goTo: '/overview/initial/tag',
name: intl.formatMessage({
id: 'xpack.beatsManagement.enrollBeat.continueButtonLabel',
defaultMessage: 'Continue',
}),
});
break;
case '/overview/beats/enroll':
actions.push({
goTo: '/overview/beats/enroll',
name: intl.formatMessage({
id: 'xpack.beatsManagement.enrollBeat.enrollAnotherBeatButtonLabel',
defaultMessage: 'Enroll another Beat',
}),
newToken: true,
});
actions.push({
goTo: '/overview/beats',
name: intl.formatMessage({
id: 'xpack.beatsManagement.enrollBeat.doneButtonLabel',
defaultMessage: 'Done',
}),
clearToken: true,
});
break;
if (this.props.enrollmentToken && !this.state.enrolledBeat) {
this.waitForTokenToEnrollBeat();
}

return (
Expand Down Expand Up @@ -229,10 +198,7 @@ export class EnrollBeat extends React.Component<BeatsProps, any> {
/>
{`//`}
{window.location.host}
{this.props.libs.framework.baseURLPath
? this.props.libs.framework.baseURLPath
: ''}{' '}
{this.props.urlState.enrollmentToken}
{this.props.frameworkBasePath} {this.props.enrollmentToken}
</div>
</div>
<br />
Expand Down Expand Up @@ -309,38 +275,9 @@ export class EnrollBeat extends React.Component<BeatsProps, any> {
/>
<br />
<br />
{actions.map(action => (
<EuiButton
key={action.name}
size="s"
color="primary"
style={{ marginLeft: 10 }}
onClick={async () => {
if (action.clearToken) {
this.props.setUrlState({ enrollmentToken: '' });
}

if (action.newToken) {
const enrollmentToken = await this.props.libs.tokens.createEnrollmentToken();

this.props.setUrlState({ enrollmentToken });
return this.setState({
enrolledBeat: null,
});
}
goTo(action.goTo);
}}
>
{action.name}
</EuiButton>
))}
</EuiModalBody>
)}
</React.Fragment>
);
}
}

export const EnrollBeatPageUi = withUrlState<BeatsProps>(EnrollBeat);

export const EnrollBeatPage = injectI18n(EnrollBeatPageUi);
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

export type FlatObject<T> = { [Key in keyof T]: string };
import styled from 'styled-components';

export interface AppURLState {
beatsKBar?: string;
tagsKBar?: string;
enrollmentToken?: string;
createdTag?: string;
}
export const Background = styled.div`
flex-grow: 1;
height: 100vh;
background: #f5f5f5;
`;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {
EuiEmptyPrompt,
EuiFlexGroup,
EuiFlexItem,
EuiModal,
EuiOverlayMask,
EuiPage,
EuiPageBody,
EuiPageContent,
Expand All @@ -21,13 +19,11 @@ import {
interface LayoutProps {
title: string;
actionSection?: React.ReactNode;
modalRender?: () => React.ReactNode;
modalClosePath?: string;
}

export const NoDataLayout: React.SFC<LayoutProps> = withRouter<any>(
({ actionSection, title, modalRender, modalClosePath, children, history }) => {
const modalContent = modalRender && modalRender();
({ actionSection, title, modalClosePath, children, history }) => {
return (
<EuiPage>
<EuiPageBody>
Expand All @@ -44,18 +40,6 @@ export const NoDataLayout: React.SFC<LayoutProps> = withRouter<any>(
</EuiFlexItem>
</EuiFlexGroup>
</EuiPageBody>
{modalContent && (
<EuiOverlayMask>
<EuiModal
onClose={() => {
history.push(modalClosePath);
}}
style={{ width: '640px' }}
>
{modalContent}
</EuiModal>
</EuiOverlayMask>
)}
</EuiPage>
);
}
Expand Down
Loading