2019-11-20 16:56:23 +01:00
|
|
|
/*
|
2021-01-20 02:52:56 +01:00
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
|
* or more contributor license agreements. Licensed under the Elastic License
|
2021-02-04 03:12:39 +01:00
|
|
|
* 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.
|
2019-11-20 16:56:23 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
import { format as formatUrl } from 'url';
|
2020-05-07 15:57:34 +02:00
|
|
|
import fs from 'fs';
|
2019-11-20 16:56:23 +01:00
|
|
|
import { Client } from '@elastic/elasticsearch';
|
2020-05-07 15:57:34 +02:00
|
|
|
import { CA_CERT_PATH } from '@kbn/dev-utils';
|
2021-03-25 09:47:16 +01:00
|
|
|
import type { KibanaClient } from '@elastic/elasticsearch/api/kibana';
|
2019-11-20 16:56:23 +01:00
|
|
|
|
|
|
|
import { FtrProviderContext } from '../ftr_provider_context';
|
|
|
|
|
2021-03-25 09:47:16 +01:00
|
|
|
/*
|
|
|
|
registers Kibana-specific @elastic/elasticsearch client instance.
|
|
|
|
*/
|
|
|
|
export function ElasticsearchProvider({ getService }: FtrProviderContext): KibanaClient {
|
2019-11-20 16:56:23 +01:00
|
|
|
const config = getService('config');
|
|
|
|
|
2020-07-27 23:10:33 +02:00
|
|
|
if (process.env.TEST_CLOUD) {
|
|
|
|
return new Client({
|
|
|
|
nodes: [formatUrl(config.get('servers.elasticsearch'))],
|
|
|
|
requestTimeout: config.get('timeouts.esRequestTimeout'),
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return new Client({
|
|
|
|
ssl: {
|
|
|
|
ca: fs.readFileSync(CA_CERT_PATH, 'utf-8'),
|
|
|
|
},
|
|
|
|
nodes: [formatUrl(config.get('servers.elasticsearch'))],
|
|
|
|
requestTimeout: config.get('timeouts.esRequestTimeout'),
|
|
|
|
});
|
|
|
|
}
|
2019-11-20 16:56:23 +01:00
|
|
|
}
|