diff --git a/x-pack/plugins/beats_management/common/constants/security.ts b/x-pack/plugins/beats_management/common/constants/security.ts index 4d72e3c9f2ac7..c80b036dddf83 100644 --- a/x-pack/plugins/beats_management/common/constants/security.ts +++ b/x-pack/plugins/beats_management/common/constants/security.ts @@ -6,5 +6,5 @@ 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'; +export const LICENSES = ['oss', 'basic', 'standard', 'gold', 'trial', 'platinum']; +export type LicenseType = 'oss' | 'basic' | 'trial' | 'standard' | 'basic' | 'gold' | 'platinum'; diff --git a/x-pack/plugins/beats_management/public/components/enroll_beats.tsx b/x-pack/plugins/beats_management/public/components/enroll_beats.tsx index dba4e243e16d3..5189a887a41fd 100644 --- a/x-pack/plugins/beats_management/public/components/enroll_beats.tsx +++ b/x-pack/plugins/beats_management/public/components/enroll_beats.tsx @@ -42,7 +42,7 @@ export class EnrollBeat extends React.Component this.state = { enrolledBeat: null, hasPolledForBeat: false, - command: 'sudo filebeat', + command: 'sudo {{beatType}}', beatType: 'filebeat', }; } @@ -144,17 +144,15 @@ export class EnrollBeat extends React.Component value={this.state.command} options={[ { - value: `sudo ${this.state.beatType}`, + value: `sudo {{beatType}}`, text: 'DEB / RPM', }, { - value: `PS C:\\Program Files\\${capitalize(this.state.beatType)}> ${ - this.state.beatType - }.exe`, + value: `PS C:\\Program Files\\{{beatTypeInCaps}}> {{beatType}}.exe`, text: 'Windows', }, { - value: `./${this.state.beatType}`, + value: `./{{beatType}}`, text: 'MacOS', }, ]} @@ -188,17 +186,13 @@ export class EnrollBeat extends React.Component className="euiFieldText euiFieldText--fullWidth" style={{ textAlign: 'left' }} > - - {`//`} - {window.location.host} - {this.props.frameworkBasePath} {this.props.enrollmentToken} + {`$ ${this.state.command + .replace('{{beatType}}', this.state.beatType) + .replace('{{beatTypeInCaps}}', capitalize(this.state.beatType))} enroll ${ + window.location.protocol + }://${window.location.host} ${this.props.frameworkBasePath} ${ + this.props.enrollmentToken + }`}
diff --git a/x-pack/plugins/beats_management/public/lib/adapters/framework/kibana_framework_adapter.ts b/x-pack/plugins/beats_management/public/lib/adapters/framework/kibana_framework_adapter.ts index 33cf335b0cf77..534bc3b77010e 100644 --- a/x-pack/plugins/beats_management/public/lib/adapters/framework/kibana_framework_adapter.ts +++ b/x-pack/plugins/beats_management/public/lib/adapters/framework/kibana_framework_adapter.ts @@ -89,7 +89,10 @@ export class KibanaFrameworkAdapter implements FrameworkAdapter { license: { type: xpackInfo ? xpackInfo.getLicense().type : 'oss', expired: xpackInfo ? !xpackInfo.getLicense().isActive : false, - expiry_date_in_millis: xpackInfo ? xpackInfo.getLicense().expiryDateInMillis : 0, + expiry_date_in_millis: + xpackInfo.getLicense().expiryDateInMillis !== undefined + ? xpackInfo.getLicense().expiryDateInMillis + : -1, }, security: { enabled: xpackInfo diff --git a/x-pack/plugins/beats_management/public/router.tsx b/x-pack/plugins/beats_management/public/router.tsx index febf5d73ed096..e2d8fffced0d2 100644 --- a/x-pack/plugins/beats_management/public/router.tsx +++ b/x-pack/plugins/beats_management/public/router.tsx @@ -45,8 +45,12 @@ export class AppRouter extends Component { public async componentWillMount() { if (this.state.loadingStatus === 'loading') { - await this.props.beatsContainer.reload(); - await this.props.tagsContainer.reload(); + try { + await this.props.beatsContainer.reload(); + await this.props.tagsContainer.reload(); + } catch (e) { + // TODO in a furture version we will better manage this "error" in a returned arg + } const countOfEverything = this.props.beatsContainer.state.list.length + this.props.tagsContainer.state.list.length; diff --git a/x-pack/plugins/beats_management/server/lib/adapters/database/kibana_database_adapter.ts b/x-pack/plugins/beats_management/server/lib/adapters/database/kibana_database_adapter.ts index 9a9424fc54e4e..fe7d45d0cf0ee 100644 --- a/x-pack/plugins/beats_management/server/lib/adapters/database/kibana_database_adapter.ts +++ b/x-pack/plugins/beats_management/server/lib/adapters/database/kibana_database_adapter.ts @@ -32,7 +32,7 @@ export class KibanaDatabaseAdapter implements DatabaseAdapter { } public async putTemplate(user: FrameworkUser, params: DatabasePutTemplateParams): Promise { const callES = this.getCallType(user); - const result = await callES('indices.putTemplate', params); + const result: { acknowledged: boolean } = await callES('indices.putTemplate', params); return result; } diff --git a/x-pack/plugins/beats_management/server/lib/adapters/tokens/elasticsearch_tokens_adapter.ts b/x-pack/plugins/beats_management/server/lib/adapters/tokens/elasticsearch_tokens_adapter.ts index 53038651cc4c5..625628fa6647a 100644 --- a/x-pack/plugins/beats_management/server/lib/adapters/tokens/elasticsearch_tokens_adapter.ts +++ b/x-pack/plugins/beats_management/server/lib/adapters/tokens/elasticsearch_tokens_adapter.ts @@ -61,12 +61,17 @@ export class ElasticsearchTokensAdapter implements CMTokensAdapter { ]) ); - await this.database.bulk(user, { + const result = await this.database.bulk(user, { body, index: INDEX_NAMES.BEATS, refresh: 'wait_for', type: '_doc', }); + + if (result.errors) { + throw new Error(result.items[0].result); + } + return tokens; } } diff --git a/x-pack/plugins/beats_management/server/lib/framework.ts b/x-pack/plugins/beats_management/server/lib/framework.ts index 3a79afa1c1ef7..849129f6c2efa 100644 --- a/x-pack/plugins/beats_management/server/lib/framework.ts +++ b/x-pack/plugins/beats_management/server/lib/framework.ts @@ -6,15 +6,16 @@ import Boom from 'boom'; import { difference } from 'lodash'; -import { FrameworkRouteHandler } from './adapters/framework/adapter_types'; -import { FrameworkRequest } from './adapters/framework/adapter_types'; import { BackendFrameworkAdapter, + FrameworkRequest, FrameworkResponse, + FrameworkRouteHandler, FrameworkRouteOptions, } from './adapters/framework/adapter_types'; export class BackendFrameworkLib { + public log = this.adapter.log; public exposeStaticDir = this.adapter.exposeStaticDir; public internalUser = this.adapter.internalUser; constructor(private readonly adapter: BackendFrameworkAdapter) { diff --git a/x-pack/plugins/beats_management/server/lib/types.ts b/x-pack/plugins/beats_management/server/lib/types.ts index d9f2a922ebb34..ce18830da174b 100644 --- a/x-pack/plugins/beats_management/server/lib/types.ts +++ b/x-pack/plugins/beats_management/server/lib/types.ts @@ -6,7 +6,6 @@ import { DatabaseAdapter } from './adapters/database/adapter_types'; import { FrameworkUser } from './adapters/framework/adapter_types'; - import { CMBeatsDomain } from './beats'; import { BackendFrameworkLib } from './framework'; import { CMTagsDomain } from './tags'; @@ -27,3 +26,13 @@ export enum BeatEnrollmentStatus { ExpiredEnrollmentToken = 'Expired enrollment token', InvalidEnrollmentToken = 'Invalid enrollment token', } + +export interface AsyncResponse { + error: { + code: number | string; + message: string; + }; +} +export interface AsyncResponse { + data: DataType; +} diff --git a/x-pack/plugins/beats_management/server/management_server.ts b/x-pack/plugins/beats_management/server/management_server.ts index 679f8f3423867..dca0bff015198 100644 --- a/x-pack/plugins/beats_management/server/management_server.ts +++ b/x-pack/plugins/beats_management/server/management_server.ts @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ +import { INDEX_NAMES } from '../common/constants/index_names'; import { CMServerLibs } from './lib/types'; import { createGetBeatConfigurationRoute } from './rest_api/beats/configuration'; import { createBeatEnrollmentRoute } from './rest_api/beats/enroll'; @@ -19,10 +20,10 @@ import { createSetTagRoute } from './rest_api/tags/set'; import { createTokensRoute } from './rest_api/tokens/create'; import { beatsIndexTemplate } from './utils/index_templates'; -export const initManagementServer = (libs: CMServerLibs) => { +export const initManagementServer = async (libs: CMServerLibs) => { if (libs.database) { - libs.database.putTemplate(libs.framework.internalUser, { - name: '.management-beats', + await libs.database.putTemplate(libs.framework.internalUser, { + name: INDEX_NAMES.BEATS, body: beatsIndexTemplate, }); } diff --git a/x-pack/plugins/beats_management/server/rest_api/tokens/create.ts b/x-pack/plugins/beats_management/server/rest_api/tokens/create.ts index 1b70bd3b3ad8f..1a2a5fd561f94 100644 --- a/x-pack/plugins/beats_management/server/rest_api/tokens/create.ts +++ b/x-pack/plugins/beats_management/server/rest_api/tokens/create.ts @@ -4,12 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ +import Boom from 'boom'; import Joi from 'joi'; import { get } from 'lodash'; import { REQUIRED_LICENSES } from 'x-pack/plugins/beats_management/common/constants'; import { FrameworkRequest } from '../../lib/adapters/framework/adapter_types'; import { CMServerLibs } from '../../lib/types'; -import { wrapEsError } from '../../utils/error_wrappers'; // TODO: write to Kibana audit log file const DEFAULT_NUM_TOKENS = 1; @@ -35,8 +35,8 @@ export const createTokensRoute = (libs: CMServerLibs) => ({ const tokens = await libs.tokens.createEnrollmentTokens(request.user, numTokens); return { tokens }; } catch (err) { - // TODO move this to kibana route thing in adapter - return wrapEsError(err); + libs.framework.log(err.message); + return Boom.internal(); } }, });