Skip to content

Commit e4e0522

Browse files
authored
Merge pull request #48 from spectriclabs/dev
Dev -> Master
2 parents aa0cb3c + baf0c0d commit e4e0522

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

Diff for: elastic_datashader/elastic.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
import copy
44
import struct
55
import time
6+
import urllib
67
from dateutil.relativedelta import relativedelta
78

89
from datashader.utils import lnglat_to_meters
910
from elasticsearch import Elasticsearch
1011
from elasticsearch_dsl import AttrDict, Search
1112

13+
import elastic_transport
1214
import pynumeral
1315
import yaml
1416

@@ -45,15 +47,27 @@ def scan(search, use_scroll=False, size=10000):
4547
else:
4648
_search = None
4749

50+
def hosts_url_to_nodeconfig(elasticsearch_hosts: str):
51+
node_configs = []
52+
for host in elasticsearch_hosts.split(","):
53+
nodeconfig = elastic_transport.client_utils.url_to_node_config(host)
54+
nodeconfig.verify_certs = False
55+
# check if host has username and password and override the basic auth due to elastic bug
56+
# https://github.com/elastic/elastic-transport-python/issues/141
57+
parsed_url = urllib.parse.urlparse(host)
58+
if parsed_url.username and parsed_url.password:
59+
nodeconfig.headers = nodeconfig.headers.copy()
60+
nodeconfig.headers["authorization"] = elastic_transport.client_utils.basic_auth_to_header((parsed_url.username, parsed_url.password))
61+
node_configs.append(nodeconfig)
62+
return node_configs
4863

4964
def verify_datashader_indices(elasticsearch_hosts: str):
5065
"""Verify the ES indices exist
5166
5267
:param elasticsearch_hosts:
5368
"""
5469
es = Elasticsearch(
55-
elasticsearch_hosts.split(","),
56-
verify_certs=False,
70+
hosts_url_to_nodeconfig(elasticsearch_hosts),
5771
timeout=120
5872
)
5973

@@ -182,8 +196,7 @@ def get_search_base(
182196
x_opaque_id = params.get("x-opaque-id")
183197
# Connect to Elasticsearch
184198
es = Elasticsearch(
185-
elastic_hosts.split(","),
186-
verify_certs=False,
199+
hosts_url_to_nodeconfig(elastic_hosts),
187200
timeout=900,
188201
headers=get_es_headers(headers, user, x_opaque_id),
189202
)

0 commit comments

Comments
 (0)