6
6
import requests
7
7
from requests .exceptions import ConnectionError
8
8
9
+ from elastichq .common .utils import string_to_bool
9
10
from elastichq .model import ClusterModel
10
11
from elastichq .service .persistence import ClusterDBService
11
12
from ..globals import CONNECTIONS , LOG , REQUEST_TIMEOUT
12
- from ..vendor .elasticsearch import Elasticsearch
13
+ from ..vendor .elasticsearch import Elasticsearch , RequestsHttpConnection
13
14
from ..vendor .elasticsearch .connections import ConnectionNotFoundException
14
15
15
16
@@ -54,6 +55,8 @@ def create_connection(self, ip, port, scheme='http', username=None, password=Non
54
55
:return:
55
56
"""
56
57
try :
58
+ verify_certs = string_to_bool (verify_certs )
59
+ enable_ssl = string_to_bool (enable_ssl )
57
60
LOG .info ('Verify: ' + str (verify_certs ))
58
61
LOG .info ('Cert File: ' + str (ca_certs ))
59
62
@@ -76,7 +79,7 @@ def create_connection(self, ip, port, scheme='http', username=None, password=Non
76
79
if verify_certs is False :
77
80
LOG .info ("Verify Certs is False" )
78
81
response = requests .get (scheme + "://" + ip + ":" + port , auth = (username , password ),
79
- timeout = REQUEST_TIMEOUT , verify = verify_certs ,
82
+ timeout = REQUEST_TIMEOUT , verify = False ,
80
83
cert = client_cert_credentials )
81
84
else :
82
85
LOG .info ("Verify Certs is True" )
@@ -93,7 +96,7 @@ def create_connection(self, ip, port, scheme='http', username=None, password=Non
93
96
if verify_certs is False :
94
97
LOG .info ("Verify Certs is False" )
95
98
response = requests .get (scheme + "://" + ip + ":" + port , timeout = REQUEST_TIMEOUT ,
96
- verify = verify_certs , cert = client_cert_credentials )
99
+ verify = False , cert = client_cert_credentials )
97
100
else :
98
101
LOG .info ("Verify Certs is True" )
99
102
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
103
106
response = requests .get (scheme + "://" + ip + ":" + port , timeout = REQUEST_TIMEOUT )
104
107
105
108
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 + \
107
110
":" + port
108
111
raise ConnectionNotAuthorized (message = message )
109
112
@@ -112,20 +115,38 @@ def create_connection(self, ip, port, scheme='http', username=None, password=Non
112
115
# SAVE to Connection Pools
113
116
if is_basic_auth is True :
114
117
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
+
119
132
else :
120
133
conn = Elasticsearch (hosts = [scheme + "://" + ip + ":" + port ], maxsize = 5 ,
121
134
version = content .get ('version' ).get ('number' ), http_auth = (username , password ))
122
135
123
136
else :
124
137
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 )
129
150
else :
130
151
conn = Elasticsearch (hosts = [scheme + "://" + ip + ":" + port ], maxsize = 5 ,
131
152
version = content .get ('version' ).get ('number' ))
@@ -178,7 +199,7 @@ def get_connection(self, cluster_name, create_if_missing=True):
178
199
Interface for cluster connection pool object. If a connection does not exist, it will attempt to create it,
179
200
using what is stored in the database. If it cannot find the connection
180
201
or cannot create one from the database, it will throw a ConnectionNotFoundException
181
- :param cluster_name:
202
+ :param cluster_name:
182
203
:param create_if_missing: Will create the connection in the connection pool AND the persistence layer if it
183
204
does not exist.
184
205
:return:
0 commit comments