-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
index.ts
73 lines (62 loc) · 1.96 KB
/
index.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
/*
* 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 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 or the Server
* Side Public License, v 1.
*/
import { join } from 'path';
import { accessSync, constants } from 'fs';
import { TypeOf, schema } from '@kbn/config-schema';
import { REPO_ROOT } from '../repo_root';
const isString = (v: any): v is string => typeof v === 'string';
const CONFIG_PATHS = [
process.env.KBN_PATH_CONF && join(process.env.KBN_PATH_CONF, 'kibana.yml'),
process.env.KIBANA_PATH_CONF && join(process.env.KIBANA_PATH_CONF, 'kibana.yml'),
process.env.CONFIG_PATH, // deprecated
join(REPO_ROOT, 'config/kibana.yml'),
].filter(isString);
const CONFIG_DIRECTORIES = [
process.env.KBN_PATH_CONF,
process.env.KIBANA_PATH_CONF,
join(REPO_ROOT, 'config'),
'/etc/kibana',
].filter(isString);
const DATA_PATHS = [
process.env.DATA_PATH, // deprecated
join(REPO_ROOT, 'data'),
'/var/lib/kibana',
].filter(isString);
function findFile(paths: string[]) {
const availablePath = paths.find((configPath) => {
try {
accessSync(configPath, constants.R_OK);
return true;
} catch (e) {
// Check the next path
}
});
return availablePath || paths[0];
}
/**
* Get the path of kibana.yml
* @internal
*/
export const getConfigPath = () => findFile(CONFIG_PATHS);
/**
* Get the directory containing configuration files
* @internal
*/
export const getConfigDirectory = () => findFile(CONFIG_DIRECTORIES);
/**
* Get the directory containing runtime data
* @internal
*/
export const getDataPath = () => findFile(DATA_PATHS);
export type PathConfigType = TypeOf<typeof config.schema>;
export const config = {
path: 'path',
schema: schema.object({
data: schema.string({ defaultValue: () => getDataPath() }),
}),
};