Skip to content

Commit

Permalink
[BeatsCM] Backport bug fixes (#27249)
Browse files Browse the repository at this point in the history
* [BeatsCM] Fix check for expiry_date_in_millis to allow for non-expiry (#27198)

* Fix check for expiry_date_in_millis to allow for non-expiry

* fix typo

* [BeatsCM] fix incorrect beat name in enroll command, remove translation of command (#27036)

* [Beats CM] Add basic license type (#26935)

* wrap non error in a try/catch (#26898)

* Log token errors to the server (#27170)
  • Loading branch information
mattapperson committed Dec 14, 2018
1 parent 2bd3e94 commit 41b1ce2
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 33 deletions.
4 changes: 2 additions & 2 deletions x-pack/plugins/beats_management/common/constants/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
28 changes: 11 additions & 17 deletions x-pack/plugins/beats_management/public/components/enroll_beats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class EnrollBeat extends React.Component<ComponentProps, ComponentState>
this.state = {
enrolledBeat: null,
hasPolledForBeat: false,
command: 'sudo filebeat',
command: 'sudo {{beatType}}',
beatType: 'filebeat',
};
}
Expand Down Expand Up @@ -144,17 +144,15 @@ export class EnrollBeat extends React.Component<ComponentProps, ComponentState>
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',
},
]}
Expand Down Expand Up @@ -188,17 +186,13 @@ export class EnrollBeat extends React.Component<ComponentProps, ComponentState>
className="euiFieldText euiFieldText--fullWidth"
style={{ textAlign: 'left' }}
>
<FormattedMessage
id="xpack.beatsManagement.enrollBeat.stateCommandEnrollLocationProtocolTitle"
defaultMessage="$ {stateCommand} enroll {locationProtocol}"
values={{
stateCommand: this.state.command,
locationProtocol: window.location.protocol,
}}
/>
{`//`}
{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
}`}
</div>
</div>
<br />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions x-pack/plugins/beats_management/public/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ export class AppRouter extends Component<RouterProps, RouterState> {

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class KibanaDatabaseAdapter implements DatabaseAdapter {
}
public async putTemplate(user: FrameworkUser, params: DatabasePutTemplateParams): Promise<any> {
const callES = this.getCallType(user);
const result = await callES('indices.putTemplate', params);
const result: { acknowledged: boolean } = await callES('indices.putTemplate', params);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
5 changes: 3 additions & 2 deletions x-pack/plugins/beats_management/server/lib/framework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 10 additions & 1 deletion x-pack/plugins/beats_management/server/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -27,3 +26,13 @@ export enum BeatEnrollmentStatus {
ExpiredEnrollmentToken = 'Expired enrollment token',
InvalidEnrollmentToken = 'Invalid enrollment token',
}

export interface AsyncResponse<DataType = any> {
error: {
code: number | string;
message: string;
};
}
export interface AsyncResponse<DataType = any> {
data: DataType;
}
7 changes: 4 additions & 3 deletions x-pack/plugins/beats_management/server/management_server.ts
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.
*/

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';
Expand All @@ -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,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
},
});

0 comments on commit 41b1ce2

Please sign in to comment.