forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_version.ts
50 lines (46 loc) · 1.38 KB
/
get_version.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
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { Elasticsearch, Kibana } from '../create_apm_users';
import { AbortError } from './call_kibana';
import { callKibana, isAxiosError } from './call_kibana';
export async function getKibanaVersion({
elasticsearch,
kibana,
}: {
elasticsearch: Omit<Elasticsearch, 'node'>;
kibana: Kibana;
}) {
try {
const res: { version: { number: number } } = await callKibana({
elasticsearch,
kibana,
options: {
method: 'GET',
url: `/api/status`,
},
});
return res.version.number;
} catch (e) {
if (isAxiosError(e)) {
switch (e.response?.status) {
case 401:
throw new AbortError(
`Could not access Kibana with the provided credentials. Username: "${e.config?.auth?.username}". Password: "${e.config?.auth?.password}"`
);
case 404:
throw new AbortError(
`Could not get version on ${e.config?.url} (Code: 404)`
);
default:
throw new AbortError(
`Cannot access Kibana on ${e.config?.baseURL}. Please specify Kibana with: "--kibana-url <url>"`
);
}
}
throw e;
}
}