From 2faeba4efe824be113cdeb666b7593a4e1c87708 Mon Sep 17 00:00:00 2001 From: acidvegas Date: Wed, 28 Feb 2024 13:42:30 -0500 Subject: [PATCH] Fix for missing auth headers in sniff_callback --- elasticsearch/_sync/client/_base.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/elasticsearch/_sync/client/_base.py b/elasticsearch/_sync/client/_base.py index ea08f7f62..ec179c28e 100644 --- a/elasticsearch/_sync/client/_base.py +++ b/elasticsearch/_sync/client/_base.py @@ -15,6 +15,7 @@ # specific language governing permissions and limitations # under the License. +import base64 import re import warnings from typing import ( @@ -166,13 +167,23 @@ def _sniffed_node_callback( def sniff_callback( transport: Transport, sniff_options: SniffOptions ) -> List[NodeConfig]: + # Dynamically resolve authentication headers based on the client's configuration. + auth_headers = resolve_auth_headers( + headers=None, + http_auth=transport.http_auth, + api_key=transport.api_key, + basic_auth=transport.basic_auth, + bearer_auth=transport.bearer_auth, + ) + for _ in transport.node_pool.all(): try: meta, node_infos = transport.perform_request( "GET", "/_nodes/_all/http", headers={ - "accept": "application/vnd.elasticsearch+json; compatible-with=8" + **auth_headers, # Include the resolved authentication headers + "accept": "application/vnd.elasticsearch+json; compatible-with=8", }, request_timeout=( sniff_options.sniff_timeout