-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
Copy pathstatus.ts
62 lines (57 loc) · 1.82 KB
/
status.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import Boom from 'boom';
import {
getLogSourceStatusRequestParamsRT,
getLogSourceStatusSuccessResponsePayloadRT,
LOG_SOURCE_STATUS_PATH,
} from '../../../common/http_api/log_sources';
import { createValidationFunction } from '../../../common/runtime_types';
import { InfraIndexType } from '../../graphql/types';
import { InfraBackendLibs } from '../../lib/infra_types';
export const initLogSourceStatusRoutes = ({
framework,
sourceStatus,
fields,
}: InfraBackendLibs) => {
framework.registerRoute(
{
method: 'get',
path: LOG_SOURCE_STATUS_PATH,
validate: {
params: createValidationFunction(getLogSourceStatusRequestParamsRT),
},
},
framework.router.handleLegacyErrors(async (requestContext, request, response) => {
const { sourceId } = request.params;
try {
const logIndexNames = await sourceStatus.getLogIndexNames(requestContext, sourceId);
const logIndexFields =
logIndexNames.length > 0
? await fields.getFields(requestContext, sourceId, InfraIndexType.LOGS)
: [];
return response.ok({
body: getLogSourceStatusSuccessResponsePayloadRT.encode({
data: {
logIndexFields,
logIndexNames,
},
}),
});
} catch (error) {
if (Boom.isBoom(error)) {
throw error;
}
return response.customError({
statusCode: error.statusCode ?? 500,
body: {
message: error.message ?? 'An unexpected error occurred',
},
});
}
})
);
};