mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Adds an integrity check to make sure the required index and aliases are present before creating, updating or deleting annotations.
This commit is contained in:
parent
91f05f4d93
commit
d8bb369f7e
1 changed files with 22 additions and 2 deletions
|
@ -4,14 +4,24 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import Boom from 'boom';
|
||||
import _ from 'lodash';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
|
||||
import { callWithRequestFactory } from '../client/call_with_request_factory';
|
||||
import { isAnnotationsFeatureAvailable } from '../lib/check_annotations';
|
||||
import { wrapError } from '../client/errors';
|
||||
import { annotationServiceProvider } from '../models/annotation_service';
|
||||
|
||||
import { ANNOTATION_USER_UNKNOWN } from '../../common/constants/annotations';
|
||||
|
||||
function getAnnotationsFeatureUnavailableErrorMessage() {
|
||||
return Boom.badRequest(
|
||||
i18n.translate('xpack.ml.routes.annotations.annotationsFeatureUnavailableErrorMessage', {
|
||||
defaultMessage: 'Index and aliases required for the annotations feature have not been created.',
|
||||
})
|
||||
);
|
||||
}
|
||||
export function annotationRoutes(server, commonRouteConfig) {
|
||||
server.route({
|
||||
method: 'POST',
|
||||
|
@ -30,7 +40,12 @@ export function annotationRoutes(server, commonRouteConfig) {
|
|||
server.route({
|
||||
method: 'PUT',
|
||||
path: '/api/ml/annotations/index',
|
||||
handler(request) {
|
||||
async handler(request) {
|
||||
const annotationsFeatureAvailable = await isAnnotationsFeatureAvailable(server);
|
||||
if (annotationsFeatureAvailable === false) {
|
||||
return getAnnotationsFeatureUnavailableErrorMessage();
|
||||
}
|
||||
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const { indexAnnotation } = annotationServiceProvider(callWithRequest);
|
||||
const username = _.get(request, 'auth.credentials.username', ANNOTATION_USER_UNKNOWN);
|
||||
|
@ -45,7 +60,12 @@ export function annotationRoutes(server, commonRouteConfig) {
|
|||
server.route({
|
||||
method: 'DELETE',
|
||||
path: '/api/ml/annotations/delete/{annotationId}',
|
||||
handler(request) {
|
||||
async handler(request) {
|
||||
const annotationsFeatureAvailable = await isAnnotationsFeatureAvailable(server);
|
||||
if (annotationsFeatureAvailable === false) {
|
||||
return getAnnotationsFeatureUnavailableErrorMessage();
|
||||
}
|
||||
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const annotationId = request.params.annotationId;
|
||||
const { deleteAnnotation } = annotationServiceProvider(callWithRequest);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue