-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
es_test_config.ts
83 lines (70 loc) · 2.56 KB
/
es_test_config.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import { kibanaPackageJson as pkg } from '@kbn/repo-info';
import Url from 'url';
import { systemIndicesSuperuser } from '../kbn';
class EsTestConfig {
getVersion() {
return process.env.TEST_ES_BRANCH || pkg.version;
}
getPort() {
return this.getUrlParts().port;
}
getUrl() {
return Url.format(this.getUrlParts());
}
getBuildFrom() {
return process.env.TEST_ES_FROM || 'snapshot';
}
getESServerlessImage() {
return process.env.TEST_ES_SERVERLESS_IMAGE;
}
getTransportPort() {
return process.env.TEST_ES_TRANSPORT_PORT || '9300-9400';
}
getUrlParts() {
// Allow setting one complete TEST_ES_URL for Es like https://elastic:changeme@myCloudInstance:9200
if (process.env.TEST_ES_URL) {
const testEsUrl = Url.parse(process.env.TEST_ES_URL);
if (!testEsUrl.port) {
throw new Error(
`process.env.TEST_ES_URL must contain port. given: ${process.env.TEST_ES_URL}`
);
}
return {
// have to remove the ":" off protocol
protocol: testEsUrl.protocol?.slice(0, -1),
hostname: testEsUrl.hostname,
port: parseInt(testEsUrl.port, 10),
username: testEsUrl.auth?.split(':')[0],
password: testEsUrl.auth?.split(':')[1],
auth: testEsUrl.auth,
};
}
const username = process.env.TEST_ES_USERNAME || systemIndicesSuperuser.username;
const password = process.env.TEST_ES_PASSWORD || systemIndicesSuperuser.password;
const port = process.env.TEST_ES_PORT ? parseInt(process.env.TEST_ES_PORT, 10) : 9220;
if (Number.isNaN(port)) {
throw new Error(
`process.env.TEST_ES_PORT must contain a valid port. given: ${process.env.TEST_ES_PORT}`
);
}
return {
// Allow setting any individual component(s) of the URL,
// or use default values (username and password from ../kbn/users.js)
protocol: process.env.TEST_ES_PROTOCOL || 'http',
hostname: process.env.TEST_ES_HOSTNAME || 'localhost',
port,
auth: `${username}:${password}`,
username,
password,
};
}
}
export const esTestConfig = new EsTestConfig();