Skip to content

Commit

Permalink
Merge pull request #1 from wkiser/http_auth
Browse files Browse the repository at this point in the history
Http auth
  • Loading branch information
wkiser committed Jun 19, 2014
2 parents 55e6f41 + 2475352 commit b91173e
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions elasticsearch/client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import weakref
import logging
from urlparse import urlsplit

from ..transport import Transport
from ..exceptions import NotFoundError, TransportError
Expand All @@ -13,6 +14,7 @@

logger = logging.getLogger('elasticsearch')


def _normalize_hosts(hosts):
"""
Helper function to transform hosts argument to
Expand All @@ -28,25 +30,17 @@ def _normalize_hosts(hosts):

out = []
# normalize hosts to dicts
for i, host in enumerate(hosts):
for host in hosts:
if isinstance(host, string_types):
host = host.strip('/')
# remove schema information
if '://' in host:
logger.warning(
"List of nodes should not include schema information (http://): %r.",
host
)
host = host[host.index('://') + 3:]

h = {"host": host}
if ':' in host:
# TODO: detect auth urls
host, port = host.rsplit(':', 1)
if port.isdigit():
port = int(port)
h = {"host": host, "port": port}
out.append(h)
url_components = urlsplit(host)
connection_args = {"host": url_components.hostname}
if url_components.port:
connection_args["port"] = url_components.port
if url_components.username:
connection_args["http_auth"] = "%s:%s" % (url_components.username, url_components.password or '')
if url_components.scheme == 'https':
connection_args["use_ssl"] = True
out.append(connection_args)
else:
out.append(host)
return out
Expand Down

0 comments on commit b91173e

Please sign in to comment.