@@ -40,6 +40,21 @@ def _ssl_options_cert_validation_enabled(ssl_options):
4040 return bool (ssl_options .get ('ca_certs' ) or ssl_options .get ('check_hostname' , False ))
4141
4242
43+ def _safe_getattr (obj , name , default = None ):
44+ try :
45+ return object .__getattribute__ (obj , name )
46+ except AttributeError :
47+ return default
48+
49+
50+ def _ssl_context_cert_validation_enabled (ssl_context ):
51+ if isinstance (ssl_context , ssl .SSLContext ):
52+ return ssl_context .verify_mode == ssl .CERT_REQUIRED
53+
54+ from OpenSSL import SSL
55+ return ssl_context .get_verify_mode () != SSL .VERIFY_NONE
56+
57+
4358class MonitorReporter (Thread ):
4459
4560 def __init__ (self , interval_sec , session ):
@@ -146,16 +161,32 @@ def _get_startup_data(self):
146161 except AttributeError :
147162 compression_type = 'NONE'
148163
164+ connection = cc ._connection
165+ connection_ssl_context = _safe_getattr (connection , 'ssl_context' , None )
166+ connection_ssl_options = _safe_getattr (connection , 'ssl_options' , None )
167+ endpoint = _safe_getattr (connection , 'endpoint' , None )
168+ endpoint_ssl_options = _safe_getattr (endpoint , 'ssl_options' , None )
169+
170+ ssl_context = (connection_ssl_context
171+ if connection_ssl_context is not None
172+ else self ._session .cluster .ssl_context )
173+ ssl_options = (connection_ssl_options
174+ if connection_ssl_options is not None
175+ else self ._session .cluster .ssl_options )
176+ ssl_options_explicit = bool (_safe_getattr (connection , '_ssl_options_explicit' , False ))
177+ ssl_enabled = (ssl_context is not None or
178+ ssl_options is not None or
179+ endpoint_ssl_options is not None or
180+ ssl_options_explicit )
181+
149182 cert_validation = None
150183 try :
151- if self ._session .cluster .ssl_context is not None :
152- if isinstance (self ._session .cluster .ssl_context , ssl .SSLContext ):
153- cert_validation = self ._session .cluster .ssl_context .verify_mode == ssl .CERT_REQUIRED
154- else : # pyopenssl
155- from OpenSSL import SSL
156- cert_validation = self ._session .cluster .ssl_context .get_verify_mode () != SSL .VERIFY_NONE
157- elif self ._session .cluster .ssl_options is not None :
158- cert_validation = _ssl_options_cert_validation_enabled (self ._session .cluster .ssl_options )
184+ if ssl_context is not None :
185+ cert_validation = _ssl_context_cert_validation_enabled (ssl_context )
186+ elif ssl_options is not None :
187+ cert_validation = _ssl_options_cert_validation_enabled (ssl_options )
188+ elif endpoint_ssl_options is not None :
189+ cert_validation = _ssl_options_cert_validation_enabled (endpoint_ssl_options )
159190 except Exception as e :
160191 log .debug ('Unable to get the cert validation: {}' .format (e ))
161192
@@ -193,8 +224,7 @@ def _get_startup_data(self):
193224 'compression' : compression_type .upper () if compression_type else 'NONE' ,
194225 'reconnectionPolicy' : insights_registry .serialize (self ._session .cluster .reconnection_policy ),
195226 'sslConfigured' : {
196- 'enabled' : (self ._session .cluster .ssl_context is not None or
197- self ._session .cluster .ssl_options is not None ),
227+ 'enabled' : ssl_enabled ,
198228 'certValidation' : cert_validation
199229 },
200230 'authProvider' : {
0 commit comments