Skip to content

bugfix for host parsing in host sniff #387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions elasticsearch/transport.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
import re
from itertools import chain

from .connection import Urllib3HttpConnection
Expand All @@ -8,6 +9,10 @@
ConnectionTimeout, ImproperlyConfigured


# get ip/port from "HOSTNAME/IP:PORT"
ADDRESS_RE = re.compile(r'((?P<hostname>[\.0-9A-Za-z-_]+)/|/?)(?P<ip>[\.:0-9a-f]*):(?P<port>[0-9]+)\]?$')


def get_host_info(node_info, host):
"""
Simple callback that takes the node info from `/_cluster/nodes` and a
Expand Down Expand Up @@ -222,18 +227,16 @@ def _get_host_info(self, host_info):
address_key = self.connection_class.transport_schema + '_address'
host = {}
address = host_info.get(address_key, '')
if '/' in address:
host['host'], address = address.split('/', 1)

# malformed address
if ':' not in address:
address_match = ADDRESS_RE.search(address)
if address_match is None:
return None

ip, port = address.rsplit(':', 1)
else:
address_match = address_match.groupdict()

# use the ip if not overridden by publish_host
host.setdefault('host', ip)
host['port'] = int(port)
host['host'] = address_match['hostname'] or address_match['ip']
host['port'] = int(address_match['port'])

return self.host_info_callback(host_info, host)

Expand Down