Legacy ES client: use config.httpAuth instead of config.hosts.auth (#91276)

* Use httpAuth instead of host.auth

* NIT
This commit is contained in:
Pierre Gayvallet 2021-02-15 18:34:46 +01:00 committed by GitHub
parent 8ed1c3ca3e
commit f1f206b2c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 9 deletions

View file

@ -99,7 +99,6 @@ test('parses fully specified config', () => {
"apiVersion": "v7.0.0",
"hosts": Array [
Object {
"auth": "elastic:changeme",
"headers": Object {
"x-elastic-product-origin": "kibana",
"xsrf": "something",
@ -111,7 +110,6 @@ test('parses fully specified config', () => {
"query": null,
},
Object {
"auth": "elastic:changeme",
"headers": Object {
"x-elastic-product-origin": "kibana",
"xsrf": "something",
@ -123,7 +121,6 @@ test('parses fully specified config', () => {
"query": null,
},
Object {
"auth": "elastic:changeme",
"headers": Object {
"x-elastic-product-origin": "kibana",
"xsrf": "something",
@ -135,6 +132,7 @@ test('parses fully specified config', () => {
"query": null,
},
],
"httpAuth": "elastic:changeme",
"keepAlive": true,
"log": [Function],
"pingTimeout": 12345,

View file

@ -106,11 +106,14 @@ export function parseElasticsearchClientConfig(
esClientConfig.sniffInterval = getDurationAsMs(config.sniffInterval);
}
const needsAuth = auth !== false && config.username && config.password;
if (needsAuth) {
esClientConfig.httpAuth = `${config.username}:${config.password}`;
}
if (Array.isArray(config.hosts)) {
const needsAuth = auth !== false && config.username && config.password;
esClientConfig.hosts = config.hosts.map((nodeUrl: string) => {
const uri = url.parse(nodeUrl);
const httpsURI = uri.protocol === 'https:';
const httpURI = uri.protocol === 'http:';
@ -126,10 +129,6 @@ export function parseElasticsearchClientConfig(
},
};
if (needsAuth) {
host.auth = `${config.username}:${config.password}`;
}
return host;
});
}