-
Notifications
You must be signed in to change notification settings - Fork 8k
/
register_settings_route.js
69 lines (60 loc) · 1.94 KB
/
register_settings_route.js
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
63
64
65
66
67
68
69
/*
* 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 { callWithRequestFactory } from '../../../lib/call_with_request_factory';
import { isEsErrorFactory } from '../../../lib/is_es_error_factory';
import { wrapEsError, wrapUnknownError } from '../../../lib/error_wrappers';
import { licensePreRoutingFactory } from'../../../lib/license_pre_routing_factory';
function getIndexNamesFromPayload(payload) {
return payload.indexNames || [];
}
function formatHits(hits) {
return hits.map(hit => {
return {
health: hit.health,
status: hit.status,
name: hit.index,
uuid: hit.uuid,
primary: hit.pri,
replica: hit.rep,
documents: hit["docs.count"],
documents_deleted: hit["docs.deleted"],
size: hit["store.size"],
primary_size: hit["pri.store.size"],
};
});
}
async function fetchSettings(callWithRequest, indexNames) {
const params = {
format: 'json',
index: indexNames
};
return await callWithRequest('settings', params);
}
export function registerSettingsRoute(server) {
const isEsError = isEsErrorFactory(server);
const licensePreRouting = licensePreRoutingFactory(server);
server.route({
path: '/api/index_management/indices/settings',
method: 'POST',
handler: async (request) => {
const callWithRequest = callWithRequestFactory(server, request);
const indexNames = getIndexNamesFromPayload(request.payload);
try {
const hits = await fetchSettings(callWithRequest, indexNames);
const response = formatHits(hits);
return response;
} catch (err) {
if (isEsError(err)) {
throw wrapEsError(err);
}
throw wrapUnknownError(err);
}
},
config: {
pre: [ licensePreRouting ]
}
});
}