import { format as formatUrl } from 'url' ; import fs from 'fs' ; import { Client , HttpConnection , Transport } from '@elastic/elasticsearch' ; import { CA_CERT_PATH } from '@kbn/dev-utils' ; import type { TransportRequestParams , TransportRequestOptions , TransportResult , } from '@elastic/elasticsearch' ; import { FtrProviderContext } from '../ftr_provider_context' ; export function clusterClientProvider ( { getService } ) { const config = getService ( 'config' ) ; class KibanaTransport extends Transport { request ( params , options ? ) { const opts = options || { } ; if ( opts . meta === undefined ) { opts . meta = true ; } return super . request ( params , opts ) as Promise < TransportResult < any , any > > ; } } if ( process . env . TEST_CLOUD ) { return new Client ( { nodes : [ formatUrl ( config . get ( 'servers.elasticsearch' ) ) ] , requestTimeout : config . get ( 'timeouts.esRequestTimeout' ) , Transport : KibanaTransport , Connection : HttpConnection , } ) ; } else { return new Client ( { tls : { ca : fs . readFileSync ( CA_CERT_PATH , 'utf-8' ) , } , nodes : [ formatUrl ( config . get ( 'servers.elasticsearch' ) ) ] , requestTimeout : config . get ( 'timeouts.esRequestTimeout' ) , Transport : KibanaTransport , Connection : HttpConnection , } ) ; } }