Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 x-pack/plugins/beats_management/common/domain_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface ConfigurationBlock {

export interface CMBeat {
id: string;
enrollment_token: string;
access_token: string;
verified_on?: string;
type: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const BeatsTableType: TableType = {
name: 'Tags',
render: (value: string, beat: CMPopulatedBeat) => (
<EuiFlexGroup wrap responsive={true}>
{beat.full_tags.map(tag => (
{(beat.full_tags || []).map(tag => (
<EuiBadge key={tag.id} color={tag.color ? tag.color : 'primary'}>
{tag.id}
</EuiBadge>
Expand All @@ -87,7 +87,7 @@ export const BeatsTableType: TableType = {
sortable: true,
},
],
controlDefinitions: (data: any) => ({
controlDefinitions: (data: any[]) => ({
actions: [
{
name: 'Disenroll Selected',
Expand All @@ -107,7 +107,9 @@ export const BeatsTableType: TableType = {
field: 'full_tags',
name: 'Tags',
options: uniq(
flatten(data.map((item: any) => item.full_tags)).map((tag: any) => ({ value: tag.id })),
flatten(data.map((item: any) => item.full_tags || [])).map((tag: any) => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't full_tags a required prop on CMPopulatedBeats? Shouldn't it default to an [] wherever it's being instantiated? Or am I showing my lack of TypeScript expertise by asking this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, but we are not loading those tags yet, this needs to be done yet in a future PR

value: tag.id,
})),
'value'
),
},
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/beats_management/public/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React from 'react';
import { BASE_PATH } from '../common/constants';
import { compose } from './lib/compose/memory';
import { compose } from './lib/compose/kibana';
import { FrontendLibs } from './lib/lib';

// import * as euiVars from '@elastic/eui/dist/eui_theme_k6_light.json';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface CMBeatsAdapter {
getAll(): Promise<CMBeat[]>;
removeTagsFromBeats(removals: BeatsTagAssignment[]): Promise<BeatsRemovalReturn[]>;
assignTagsToBeats(assignments: BeatsTagAssignment[]): Promise<CMAssignmentReturn[]>;
getBeatWithToken(enrollmentToken: string): Promise<CMBeat | null>;
}

export interface BeatsTagAssignment {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export class MemoryBeatsAdapter implements CMBeatsAdapter {
public async getAll() {
return this.beatsDB.map<CMBeat>((beat: any) => omit(beat, ['access_token']));
}

public async getBeatWithToken(enrollmentToken: string): Promise<CMBeat | null> {
return this.beatsDB.map<CMBeat>((beat: any) => omit(beat, ['access_token']))[0];
}
public async removeTagsFromBeats(removals: BeatsTagAssignment[]): Promise<BeatsRemovalReturn[]> {
const beatIds = removals.map(r => r.beatId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,30 @@ export class RestBeatsAdapter implements CMBeatsAdapter {
return await this.REST.get<CMBeat>(`/api/beats/agent/${id}`);
}

public async getBeatWithToken(enrollmentToken: string): Promise<CMBeat | null> {
const beat = await this.REST.get<CMBeat>(`/api/beats/agent/unknown/${enrollmentToken}`);
return beat;
}

public async getAll(): Promise<CMBeat[]> {
return await this.REST.get<CMBeat[]>('/api/beats/agents');
return (await this.REST.get<{ beats: CMBeat[] }>('/api/beats/agents')).beats;
}

public async removeTagsFromBeats(removals: BeatsTagAssignment[]): Promise<BeatsRemovalReturn[]> {
return await this.REST.post<BeatsRemovalReturn[]>(`/api/beats/agents_tags/removals`, {
removals,
});
return (await this.REST.post<{ removals: BeatsRemovalReturn[] }>(
`/api/beats/agents_tags/removals`,
{
removals,
}
)).removals;
}

public async assignTagsToBeats(assignments: BeatsTagAssignment[]): Promise<CMAssignmentReturn[]> {
return await this.REST.post<CMAssignmentReturn[]>(`/api/beats/agents_tags/assignments`, {
assignments,
});
return (await this.REST.post<{ assignments: CMAssignmentReturn[] }>(
`/api/beats/agents_tags/assignments`,
{
assignments,
}
)).assignments;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ export class RestTagsAdapter implements CMTagsAdapter {
constructor(private readonly REST: RestAPIAdapter) {}

public async getTagsWithIds(tagIds: string[]): Promise<BeatTag[]> {
return await this.REST.get<BeatTag[]>(`/api/beats/tags/${tagIds.join(',')}`);
return (await this.REST.get<{ tags: BeatTag[] }>(`/api/beats/tags/${tagIds.join(',')}`)).tags;
}

public async getAll(): Promise<BeatTag[]> {
return await this.REST.get<BeatTag[]>(`/api/beats/tags`);
return (await this.REST.get<{ tags: BeatTag[] }>(`/api/beats/tags`)).tags;
}

public async upsertTag(tag: BeatTag): Promise<BeatTag | null> {
return await this.REST.put<BeatTag>(`/api/beats/tag/{tag}`, {
return (await this.REST.put<{ tag: BeatTag }>(`/api/beats/tag/{tag}`, {
configuration_blocks: tag.configuration_blocks,
});
})).tag;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
export interface TokenEnrollmentData {
token: string | null;
expires_on: string;
}

export interface CMTokensAdapter {
createEnrollmentToken(): Promise<TokenEnrollmentData>;
createEnrollmentToken(): Promise<string>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { CMTokensAdapter, TokenEnrollmentData } from './adapter_types';
import { CMTokensAdapter } from './adapter_types';

export class MemoryTokensAdapter implements CMTokensAdapter {
public async createEnrollmentToken(): Promise<TokenEnrollmentData> {
return {
token: '2jnwkrhkwuehriauhweair',
expires_on: new Date().toJSON(),
};
public async createEnrollmentToken(): Promise<string> {
return '2jnwkrhkwuehriauhweair';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
*/

import { RestAPIAdapter } from '../rest_api/adapter_types';
import { CMTokensAdapter, TokenEnrollmentData } from './adapter_types';
import { CMTokensAdapter } from './adapter_types';

export class RestTokensAdapter implements CMTokensAdapter {
constructor(private readonly REST: RestAPIAdapter) {}

public async createEnrollmentToken(): Promise<TokenEnrollmentData> {
const tokens = await this.REST.post<TokenEnrollmentData[]>('/api/beats/enrollment_tokens');
public async createEnrollmentToken(): Promise<string> {
const tokens = (await this.REST.post<{ tokens: string[] }>('/api/beats/enrollment_tokens'))
.tokens;
return tokens[0];
}
}
57 changes: 9 additions & 48 deletions x-pack/plugins/beats_management/public/pages/main/beats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,19 @@
import {
// @ts-ignore typings for EuiBadge not present in current version
EuiBadge,
EuiButton,
EuiButtonEmpty,
EuiFlexItem,
EuiModal,
EuiModalBody,
EuiModalFooter,
EuiModalHeader,
EuiModalHeaderTitle,
EuiOverlayMask,
} from '@elastic/eui';

import React from 'react';
import { BeatTag, CMBeat, CMPopulatedBeat } from '../../../common/domain_types';
import { BeatsTagAssignment } from '../../../server/lib/adapters/beats/adapter_types';
import { BeatsTableType, Table } from '../../components/table';
import { FrontendLibs } from '../../lib/lib';
import { BeatsActionArea } from './beats_action_area';

interface BeatsPageProps {
libs: FrontendLibs;
location: any;
}

interface BeatsPageState {
Expand All @@ -35,45 +29,7 @@ interface BeatsPageState {
}

export class BeatsPage extends React.PureComponent<BeatsPageProps, BeatsPageState> {
public static ActionArea = ({ match, history }: { match: any; history: any }) => (
<div>
<EuiButtonEmpty
onClick={() => {
window.alert('This will later go to more general beats install instructions.');
window.location.href = '#/home/tutorial/dockerMetrics';
}}
>
Learn how to install beats
</EuiButtonEmpty>
<EuiButton
size="s"
color="primary"
onClick={() => {
history.push('/beats/enroll/foobar');
}}
>
Enroll Beats
</EuiButton>

{match.params.enrollmentToken != null && (
<EuiOverlayMask>
<EuiModal onClose={() => history.push('/beats')} style={{ width: '800px' }}>
<EuiModalHeader>
<EuiModalHeaderTitle>Enroll Beats</EuiModalHeaderTitle>
</EuiModalHeader>

<EuiModalBody>
Enrollment UI here for enrollment token of: {match.params.enrollmentToken}
</EuiModalBody>

<EuiModalFooter>
<EuiButtonEmpty onClick={() => history.push('/beats')}>Cancel</EuiButtonEmpty>
</EuiModalFooter>
</EuiModal>
</EuiOverlayMask>
)}
</div>
);
public static ActionArea = BeatsActionArea;
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

constructor(props: BeatsPageProps) {
super(props);

Expand All @@ -85,13 +41,18 @@ export class BeatsPage extends React.PureComponent<BeatsPageProps, BeatsPageStat

this.loadBeats();
}
public componentDidUpdate(prevProps: any) {
if (this.props.location !== prevProps.location) {
this.loadBeats();
}
}
public render() {
return (
<Table
actionHandler={this.handleBeatsActions}
assignmentOptions={this.state.tags}
assignmentTitle="Set tags"
items={this.state.beats}
items={this.state.beats || []}
ref={this.state.tableRef}
type={BeatsTableType}
/>
Expand Down
Loading