Log token errors to the server (#27170)
This commit is contained in:
parent
6dd6f2f200
commit
ce7265c554
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<DataType = any> {
|
||||
error: {
|
||||
code: number | string;
|
||||
message: string;
|
||||
};
|
||||
}
|
||||
export interface AsyncResponse<DataType = any> {
|
||||
data: DataType;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue