66import requests
77from requests .exceptions import ConnectionError
88
9+ from elastichq .common .utils import string_to_bool
910from elastichq .model import ClusterModel
1011from elastichq .service .persistence import ClusterDBService
1112from ..globals import CONNECTIONS , LOG , REQUEST_TIMEOUT
12- from ..vendor .elasticsearch import Elasticsearch
13+ from ..vendor .elasticsearch import Elasticsearch , RequestsHttpConnection
1314from ..vendor .elasticsearch .connections import ConnectionNotFoundException
1415
1516
@@ -54,6 +55,8 @@ def create_connection(self, ip, port, scheme='http', username=None, password=Non
5455 :return:
5556 """
5657 try :
58+ verify_certs = string_to_bool (verify_certs )
59+ enable_ssl = string_to_bool (enable_ssl )
5760 LOG .info ('Verify: ' + str (verify_certs ))
5861 LOG .info ('Cert File: ' + str (ca_certs ))
5962
@@ -76,7 +79,7 @@ def create_connection(self, ip, port, scheme='http', username=None, password=Non
7679 if verify_certs is False :
7780 LOG .info ("Verify Certs is False" )
7881 response = requests .get (scheme + "://" + ip + ":" + port , auth = (username , password ),
79- timeout = REQUEST_TIMEOUT , verify = verify_certs ,
82+ timeout = REQUEST_TIMEOUT , verify = False ,
8083 cert = client_cert_credentials )
8184 else :
8285 LOG .info ("Verify Certs is True" )
@@ -93,7 +96,7 @@ def create_connection(self, ip, port, scheme='http', username=None, password=Non
9396 if verify_certs is False :
9497 LOG .info ("Verify Certs is False" )
9598 response = requests .get (scheme + "://" + ip + ":" + port , timeout = REQUEST_TIMEOUT ,
96- verify = verify_certs , cert = client_cert_credentials )
99+ verify = False , cert = client_cert_credentials )
97100 else :
98101 LOG .info ("Verify Certs is True" )
99102 response = requests .get (scheme + "://" + ip + ":" + port , timeout = REQUEST_TIMEOUT ,
@@ -103,7 +106,7 @@ def create_connection(self, ip, port, scheme='http', username=None, password=Non
103106 response = requests .get (scheme + "://" + ip + ":" + port , timeout = REQUEST_TIMEOUT )
104107
105108 if response .status_code == 401 :
106- message = "Unable to create connection! Server returned 401 - UNAUTHORIZED: " + scheme + "://" + ip + \
109+ message = "Unable to create connection! Server returned 401 - UNAUTHORIZED: " + scheme + "://" + ip + \
107110 ":" + port
108111 raise ConnectionNotAuthorized (message = message )
109112
@@ -112,20 +115,38 @@ def create_connection(self, ip, port, scheme='http', username=None, password=Non
112115 # SAVE to Connection Pools
113116 if is_basic_auth is True :
114117 if enable_ssl :
115- conn = Elasticsearch (hosts = [scheme + "://" + ip + ":" + port ], maxsize = 5 ,
116- use_ssl = True , verify_certs = verify_certs , ca_certs = ca_certs ,
117- version = content .get ('version' ).get ('number' ), http_auth = (username , password ),
118- client_cert = client_cert , client_key = client_key )
118+ if verify_certs is False :
119+ LOG .info ("Verify Certs is False" )
120+ conn = Elasticsearch (hosts = [scheme + "://" + ip + ":" + port ], maxsize = 5 ,
121+ use_ssl = True , verify_certs = False ,
122+ version = content .get ('version' ).get ('number' ),
123+ http_auth = (username , password ), connection_class = RequestsHttpConnection )
124+ else :
125+ LOG .info ("Verify Certs is True" )
126+ conn = Elasticsearch (hosts = [scheme + "://" + ip + ":" + port ], maxsize = 5 ,
127+ use_ssl = True , verify_certs = ca_certs , ca_certs = ca_certs ,
128+ version = content .get ('version' ).get ('number' ),
129+ http_auth = (username , password ),
130+ client_cert = client_cert , client_key = client_key )
131+
119132 else :
120133 conn = Elasticsearch (hosts = [scheme + "://" + ip + ":" + port ], maxsize = 5 ,
121134 version = content .get ('version' ).get ('number' ), http_auth = (username , password ))
122135
123136 else :
124137 if enable_ssl :
125- conn = Elasticsearch (hosts = [scheme + "://" + ip + ":" + port ], maxsize = 5 ,
126- use_ssl = True , verify_certs = verify_certs , ca_certs = ca_certs ,
127- version = content .get ('version' ).get ('number' ),
128- client_cert = client_cert , client_key = client_key )
138+ if verify_certs is False :
139+ LOG .info ("Verify Certs is False" )
140+ conn = Elasticsearch (hosts = [scheme + "://" + ip + ":" + port ], maxsize = 5 ,
141+ use_ssl = True , verify_certs = False ,
142+ version = content .get ('version' ).get ('number' ),
143+ connection_class = RequestsHttpConnection )
144+ else :
145+ LOG .info ("Verify Certs is False" )
146+ conn = Elasticsearch (hosts = [scheme + "://" + ip + ":" + port ], maxsize = 5 ,
147+ use_ssl = True , verify_certs = ca_certs , ca_certs = ca_certs ,
148+ version = content .get ('version' ).get ('number' ),
149+ client_cert = client_cert , client_key = client_key )
129150 else :
130151 conn = Elasticsearch (hosts = [scheme + "://" + ip + ":" + port ], maxsize = 5 ,
131152 version = content .get ('version' ).get ('number' ))
@@ -178,7 +199,7 @@ def get_connection(self, cluster_name, create_if_missing=True):
178199 Interface for cluster connection pool object. If a connection does not exist, it will attempt to create it,
179200 using what is stored in the database. If it cannot find the connection
180201 or cannot create one from the database, it will throw a ConnectionNotFoundException
181- :param cluster_name:
202+ :param cluster_name:
182203 :param create_if_missing: Will create the connection in the connection pool AND the persistence layer if it
183204 does not exist.
184205 :return:
0 commit comments