Skip to content

Commit 727a051

Browse files
committed
Fix Insights fail to serialize the startup message when the SSL Context is from PyOpenSSL
1 parent a629eae commit 727a051

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Bug Fixes
2323
* Reconnect attempts persist after downed node removed from peers (PYTHON-1181)
2424
* Connection fails to validate ssl certificate hostname when SSLContext.check_hostname is set (PYTHON-1186)
2525
* ResponseFuture._set_result crashes on connection error when used with PrepareMessage (PYTHON-1187)
26+
* Insights fail to serialize the startup message when the SSL Context is from PyOpenSSL (PYTHON-1192)
2627

2728
Others
2829
------

cassandra/datastax/insights/reporter.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,23 @@ def _get_startup_data(self):
135135
'ignored': host_distances_counter[HostDistance.IGNORED]
136136
}
137137

138-
compression_type = cc._connection._compression_type if cc._connection else 'NONE'
138+
try:
139+
compression_type = cc._connection._compression_type
140+
except AttributeError:
141+
compression_type = 'NONE'
139142

140-
if self._session.cluster.ssl_context:
141-
cert_validation = self._session.cluster.ssl_context.verify_mode == ssl.CERT_REQUIRED
142-
elif self._session.cluster.ssl_options:
143-
cert_validation = self._session.cluster.ssl_options.get('cert_reqs') == ssl.CERT_REQUIRED
144-
else:
145-
cert_validation = None
143+
cert_validation = None
144+
try:
145+
if self._session.cluster.ssl_context:
146+
if isinstance(self._session.cluster.ssl_context, ssl.SSLContext):
147+
cert_validation = self._session.cluster.ssl_context.verify_mode == ssl.CERT_REQUIRED
148+
else: # pyopenssl
149+
from OpenSSL import SSL
150+
cert_validation = self._session.cluster.ssl_context.get_verify_mode() != SSL.VERIFY_NONE
151+
elif self._session.cluster.ssl_options:
152+
cert_validation = self._session.cluster.ssl_options.get('cert_reqs') == ssl.CERT_REQUIRED
153+
except Exception as e:
154+
log.debug('Unable to get the cert validation: {}'.format(e))
146155

147156
uname_info = platform.uname()
148157

@@ -157,7 +166,7 @@ def _get_startup_data(self):
157166
},
158167
},
159168
'data': {
160-
'driverName': 'DataStax Enterprise Python Driver',
169+
'driverName': 'DataStax Python Driver',
161170
'driverVersion': sys.modules['cassandra'].__version__,
162171
'clientId': str(self._session.cluster.client_id),
163172
'sessionId': str(self._session.session_id),

0 commit comments

Comments
 (0)