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

Beats/update #21702

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ae0f496
[ML] Fixing issue with historical job audit messages (#21718)
jgowdyelastic Aug 7, 2018
dc0b707
Add proper aria-label for close inspector (#21719)
timroes Aug 7, 2018
4cf3308
[Beats Management] Initial scaffolding for plugin (#18977)
ycombinator May 11, 2018
88dcee6
[Beats Management] Install Beats index template on plugin init (#19072)
ycombinator May 15, 2018
cc7759f
[Beats Management] APIs: Create enrollment tokens (#19018)
ycombinator May 15, 2018
7468f99
Fixing name of test file (#19100)
ycombinator May 16, 2018
4193a51
[Beats Management] APIs: Enroll beat (#19056)
ycombinator May 16, 2018
29c9876
[Beats Management] APIs: List beats (#19086)
ycombinator May 16, 2018
88a0e56
[Beats Management] APIs: Verify beats (#19103)
ycombinator May 17, 2018
75cf004
Fixing assertions (#19194)
ycombinator May 18, 2018
3d8ca8a
[Beats Management] APIs: Update beat (#19148)
ycombinator May 21, 2018
66eb24c
[Beats Management] APIs: take auth tokens via headers (#19210)
ycombinator May 22, 2018
02ee43c
[Beats Management] APIs: Create configuration block (#19270)
ycombinator May 22, 2018
c5cbf11
Revert implementation of `POST /api/beats/configuration_blocks` API (…
ycombinator May 23, 2018
fbfbeba
[Beats Management] APIs: Create or update tag (#19342)
ycombinator May 23, 2018
1d766e3
[Beats Management] Prevent timing attacks when checking auth tokens (…
ycombinator May 25, 2018
d2ec2b7
[Beats Management] APIs: Assign tag(s) to beat(s) (#19431)
ycombinator May 31, 2018
29e8cf2
[Beats Management] APIs: Remove tag(s) from beat(s) (#19440)
ycombinator May 31, 2018
7338f13
[Beats Management] Move to Ingest UI arch and initial TS effort (#20039)
mattapperson Jun 26, 2018
c4d0776
[Beats Management] Move tokens to use JWT, add more complete test sui…
mattapperson Jul 6, 2018
f0d8c97
[Beats Management] add more tests, update types, break out ES into it…
mattapperson Jul 12, 2018
d2aa659
[Beats Management] add get beat endpoint (#20603)
mattapperson Jul 13, 2018
afdca74
fix bad rebase
mattapperson Jul 13, 2018
94be8ff
[Beats Management] [WIP] Create public resources for management plugi…
justinkambic Jul 17, 2018
d632dca
Beats/initial ui (#20994)
mattapperson Jul 26, 2018
4025917
add getAll method to tags adapter (#21287)
mattapperson Jul 26, 2018
87a8991
Beats/real adapters (#21481)
mattapperson Aug 2, 2018
1369e68
[Beats Management] Add BeatsTable/Bulk Action Search Component (#21182)
justinkambic Aug 3, 2018
93dac60
Beats/basic use cases (#21660)
mattapperson Aug 3, 2018
1e8415d
add update on client side, expand update on server to allow for parti…
mattapperson Aug 6, 2018
d7d6839
remove double beat lookup
mattapperson Aug 6, 2018
e9dab95
fix tests
mattapperson Aug 6, 2018
ad79998
only return active beats
mattapperson Aug 6, 2018
8d1030a
disenroll now working
mattapperson Aug 6, 2018
013b5cc
fig getAll query
mattapperson Aug 6, 2018
f07e713
re-enrolling a beat will now work
mattapperson Aug 6, 2018
c27491e
fix types
mattapperson Aug 7, 2018
c5fc941
Merge branch 'feature/x-pack/management/beats' into beats/update
mattapperson Aug 7, 2018
f7c01fe
fix types
mattapperson Aug 7, 2018
f8faae9
update deps
mattapperson Aug 7, 2018
e270774
update kibana API for version
mattapperson Aug 7, 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 src/ui/public/flyout/flyout_session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class FlyoutSession extends EventEmitter {
export function openFlyout(
flyoutChildren: React.ReactNode,
flyoutProps: {
closeButtonAriaLabel?: string;
onClose?: () => void;
'data-test-subj'?: string;
} = {}
Expand Down
1 change: 1 addition & 0 deletions src/ui/public/inspector/inspector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function open(adapters: Adapters, options: InspectorOptions = {}): InspectorSess

return openFlyout(<InspectorPanel views={views} adapters={adapters} title={options.title} />, {
'data-test-subj': 'inspectorPanel',
closeButtonAriaLabel: 'Close Inspector',
});
}

Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/beats_management/common/domain_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface ConfigurationBlock {
export interface CMBeat {
id: string;
enrollment_token: string;
active: boolean;
access_token: string;
verified_on?: string;
type: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function ControlBar(props: ControlBarProps) {
selectionCount,
showAssignmentOptions,
} = props;

const filters = controlDefinitions.filters.length === 0 ? null : controlDefinitions.filters;
return selectionCount !== 0 && showAssignmentOptions ? (
<AssignmentOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class Table extends React.Component<BeatsTableProps, BeatsTableState> {
}

public render() {

const {
actionHandler,
assignmentOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { EuiBadge, EuiFlexGroup, EuiIcon, EuiLink } from '@elastic/eui';
import { flatten, uniq } from 'lodash';
import moment from 'moment';
import React from 'react';

import { TABLE_CONFIG } from '../../../common/constants';
import { BeatTag, CMPopulatedBeat, ConfigurationBlock } from '../../../common/domain_types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CMBeat } from '../../../../common/domain_types';

export interface CMBeatsAdapter {
get(id: string): Promise<CMBeat | null>;
update(id: string, beatData: Partial<CMBeat>): Promise<boolean>;
getAll(): Promise<CMBeat[]>;
removeTagsFromBeats(removals: BeatsTagAssignment[]): Promise<BeatsRemovalReturn[]>;
assignTagsToBeats(assignments: BeatsTagAssignment[]): Promise<CMAssignmentReturn[]>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ export class MemoryBeatsAdapter implements CMBeatsAdapter {
return this.beatsDB.find(beat => beat.id === id) || null;
}

public async update(id: string, beatData: Partial<CMBeat>): Promise<boolean> {
const index = this.beatsDB.findIndex(beat => beat.id === id);

if (index === -1) {
return false;
}

this.beatsDB[index] = { ...this.beatsDB[index], ...beatData };
return true;
}

public async getAll() {
return this.beatsDB.map<CMBeat>((beat: any) => omit(beat, ['access_token']));
}
Expand All @@ -35,6 +46,12 @@ export class MemoryBeatsAdapter implements CMBeatsAdapter {
const beatIds = removals.map(r => r.beatId);

const response = this.beatsDB.filter(beat => beatIds.includes(beat.id)).map(beat => {
const tagData = removals.find(r => r.beatId === beat.id);
if (tagData) {
if (beat.tags) {
beat.tags = beat.tags.filter(tag => tag !== tagData.tag);
}
}
const removalsForBeat = removals.filter(r => r.beatId === beat.id);
if (removalsForBeat.length) {
removalsForBeat.forEach((assignment: BeatsTagAssignment) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export class RestBeatsAdapter implements CMBeatsAdapter {
return (await this.REST.get<{ beats: CMBeat[] }>('/api/beats/agents')).beats;
}

public async update(id: string, beatData: Partial<CMBeat>): Promise<boolean> {
await this.REST.put<{ success: true }>(`/api/beats/agent/${id}`, beatData);
return true;
}

public async removeTagsFromBeats(removals: BeatsTagAssignment[]): Promise<BeatsRemovalReturn[]> {
return (await this.REST.post<{ removals: BeatsRemovalReturn[] }>(
`/api/beats/agents_tags/removals`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {

export class KibanaFrameworkAdapter implements FrameworkAdapter {
public appState: object;
public kbnVersion?: string;

private management: any;
private adapterService: KibanaAdapterServiceProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import { RestAPIAdapter } from './adapter_types';
let globalAPI: AxiosInstance;

export class AxiosRestAPIAdapter implements RestAPIAdapter {
constructor(
private readonly kbnVersion: string,
private readonly xsrfToken: string,
private readonly basePath: string
) {}
constructor(private readonly xsrfToken: string, private readonly basePath: string) {}

public async get<ResponseData>(url: string): Promise<ResponseData> {
return await this.REST.get(url).then(resp => resp.data);
Expand Down Expand Up @@ -48,7 +44,7 @@ export class AxiosRestAPIAdapter implements RestAPIAdapter {
Accept: 'application/json',
credentials: 'same-origin',
'Content-Type': 'application/json',
'kbn-version': this.kbnVersion,
'kbn-version': this.xsrfToken,
'kbn-xsrf': this.xsrfToken,
},
});
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/beats_management/public/lib/compose/kibana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import { RestTokensAdapter } from '../adapters/tokens/rest_tokens_adapter';
import { FrontendDomainLibs, FrontendLibs } from '../lib';

export function compose(): FrontendLibs {
const kbnVersion = (window as any).__KBN__.version;
const api = new AxiosRestAPIAdapter(kbnVersion, chrome.getXsrfToken(), chrome.getBasePath());
const api = new AxiosRestAPIAdapter(chrome.getXsrfToken(), chrome.getBasePath());

const tags = new RestTagsAdapter(api);
const tokens = new RestTokensAdapter(api);
Expand Down
16 changes: 11 additions & 5 deletions x-pack/plugins/beats_management/public/pages/main/beats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,16 @@ export class BeatsPage extends React.PureComponent<BeatsPageProps, BeatsPageStat
this.loadBeats();
};

// TODO: call delete endpoint
private deleteSelected = async () => {
// const selected = this.getSelectedBeats();
// await this.props.libs.beats.delete(selected);
const selected = this.getSelectedBeats();
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

for (const beat of selected) {
await this.props.libs.beats.update(beat.id, { active: false });
}
// because the compile code above has a very minor race condition, we wait,
// the max race condition time is really 10ms but doing 100 to be safe
setTimeout(async () => {
await this.loadBeats();
}, 100);
};

private async loadBeats() {
Expand Down Expand Up @@ -110,7 +116,7 @@ export class BeatsPage extends React.PureComponent<BeatsPageProps, BeatsPageStat
<EuiFlexItem key={tag.id}>
<EuiBadge
color={tag.color}
iconType={hasMatches ? 'cross' : null}
iconType={hasMatches ? 'cross' : undefined}
onClick={
hasMatches
? () => this.removeTagsFromBeats(selectedBeats, tag)
Expand Down Expand Up @@ -143,7 +149,7 @@ export class BeatsPage extends React.PureComponent<BeatsPageProps, BeatsPageStat
this.loadBeats();
};

private getSelectedBeats = () => {
private getSelectedBeats = (): CMPopulatedBeat[] => {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

return this.state.tableRef.current.state.selection;
};
}
1 change: 1 addition & 0 deletions x-pack/plugins/beats_management/public/pages/main/tags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/


// @ts-ignore EuiToolTip has no typings in current version
import { EuiButtonEmpty, EuiFlexGroup, EuiFlexItem, EuiIcon, EuiToolTip } from '@elastic/eui';
import React from 'react';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { CMBeat } from '../../../../common/domain_types';
import { FrameworkUser } from '../framework/adapter_types';

export interface CMBeatsAdapter {
insert(beat: CMBeat): Promise<void>;
update(beat: CMBeat): Promise<void>;
insert(user: FrameworkUser, beat: CMBeat): Promise<void>;
update(user: FrameworkUser, beat: CMBeat): Promise<void>;
get(user: FrameworkUser, id: string): Promise<CMBeat | null>;
getAll(user: FrameworkUser): Promise<CMBeat[]>;
getWithIds(user: FrameworkUser, beatIds: string[]): Promise<CMBeat[]>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ import { flatten, get as _get, omit } from 'lodash';
import { INDEX_NAMES } from '../../../../common/constants';
import { CMBeat } from '../../../../common/domain_types';
import { DatabaseAdapter } from '../database/adapter_types';
import { BackendFrameworkAdapter } from '../framework/adapter_types';

import { FrameworkUser } from '../framework/adapter_types';
import { BeatsTagAssignment, CMBeatsAdapter } from './adapter_types';

export class ElasticsearchBeatsAdapter implements CMBeatsAdapter {
private database: DatabaseAdapter;
private framework: BackendFrameworkAdapter;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the inclusion of the user: FrameworkUser parameters for these endpoints make the framework field obsolete?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


constructor(database: DatabaseAdapter, framework: BackendFrameworkAdapter) {
constructor(database: DatabaseAdapter) {
this.database = database;
this.framework = framework;
}

public async get(user: FrameworkUser, id: string) {
Expand All @@ -37,13 +35,13 @@ export class ElasticsearchBeatsAdapter implements CMBeatsAdapter {
return _get<CMBeat>(response, '_source.beat');
}

public async insert(beat: CMBeat) {
public async insert(user: FrameworkUser, beat: CMBeat) {
const body = {
beat,
type: 'beat',
};

await this.database.create(this.framework.internalUser, {
await this.database.index(user, {
body,
id: `beat:${beat.id}`,
index: INDEX_NAMES.BEATS,
Expand All @@ -52,7 +50,7 @@ export class ElasticsearchBeatsAdapter implements CMBeatsAdapter {
});
}

public async update(beat: CMBeat) {
public async update(user: FrameworkUser, beat: CMBeat) {
const body = {
beat,
type: 'beat',
Expand All @@ -65,7 +63,7 @@ export class ElasticsearchBeatsAdapter implements CMBeatsAdapter {
refresh: 'wait_for',
type: '_doc',
};
await this.database.index(this.framework.internalUser, params);
await this.database.index(user, params);
}

public async getWithIds(user: FrameworkUser, beatIds: string[]) {
Expand Down Expand Up @@ -115,11 +113,12 @@ export class ElasticsearchBeatsAdapter implements CMBeatsAdapter {
const params = {
index: INDEX_NAMES.BEATS,
q: 'type:beat',
size: 10000,
type: '_doc',
};
const response = await this.database.search(user, params);

const beats = _get<any>(response, 'hits.hits', []);

return beats.map((beat: any) => omit(beat._source.beat, ['access_token']));
}

Expand All @@ -129,16 +128,15 @@ export class ElasticsearchBeatsAdapter implements CMBeatsAdapter {
): Promise<BeatsTagAssignment[]> {
const body = flatten(
removals.map(({ beatId, tag }) => {
const script =
'' +
'def beat = ctx._source.beat; ' +
'if (beat.tags != null) { ' +
' beat.tags.removeAll([params.tag]); ' +
'}';
const script = `
def beat = ctx._source.beat;
if (beat.tags != null) {
beat.tags.removeAll([params.tag]);
}`;

return [
{ update: { _id: `beat:${beatId}` } },
{ script: { source: script, params: { tag } } },
{ script: { source: script.replace(' ', ''), params: { tag } } },
];
})
);
Expand All @@ -162,19 +160,18 @@ export class ElasticsearchBeatsAdapter implements CMBeatsAdapter {
): Promise<BeatsTagAssignment[]> {
const body = flatten(
assignments.map(({ beatId, tag }) => {
const script =
'' +
'def beat = ctx._source.beat; ' +
'if (beat.tags == null) { ' +
' beat.tags = []; ' +
'} ' +
'if (!beat.tags.contains(params.tag)) { ' +
' beat.tags.add(params.tag); ' +
'}';
const script = `
def beat = ctx._source.beat;
if (beat.tags == null) {
beat.tags = [];
}
if (!beat.tags.contains(params.tag)) {
beat.tags.add(params.tag);
}`;

return [
{ update: { _id: `beat:${beatId}` } },
{ script: { source: script, params: { tag } } },
{ script: { source: script.replace(' ', ''), params: { tag } } },
];
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export class MemoryBeatsAdapter implements CMBeatsAdapter {
return this.beatsDB.find(beat => beat.id === id) || null;
}

public async insert(beat: CMBeat) {
public async insert(user: FrameworkUser, beat: CMBeat) {
this.beatsDB.push(beat);
}

public async update(beat: CMBeat) {
public async update(user: FrameworkUser, beat: CMBeat) {
const beatIndex = this.beatsDB.findIndex(b => b.id === beat.id);

this.beatsDB[beatIndex] = {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/beats_management/server/lib/compose/kibana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ export function compose(server: any): CMServerLibs {
const tokens = new CMTokensDomain(new ElasticsearchTokensAdapter(database, framework), {
framework,
});
const beats = new CMBeatsDomain(new ElasticsearchBeatsAdapter(database, framework), {
const beats = new CMBeatsDomain(new ElasticsearchBeatsAdapter(database), {
tags,
tokens,
framework,
});

const domainLibs: CMDomainLibs = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function compose({
const beats = new CMBeatsDomain(new MemoryBeatsAdapter(beatsDB), {
tags,
tokens,
framework,
});

const domainLibs: CMDomainLibs = {
Expand Down
Loading