MCPcopy Create free account
hub / github.com/apache/cassandra-python-driver / _handle_startup_response

Method _handle_startup_response

cassandra/connection.py:1415–1476  ·  view source on GitHub ↗
(self, startup_response, did_authenticate=False)

Source from the content-addressed store, hash-verified

1413
1414 @defunct_on_error
1415 def _handle_startup_response(self, startup_response, did_authenticate=False):
1416 if self.is_defunct:
1417 return
1418
1419 if isinstance(startup_response, ReadyMessage):
1420 if self.authenticator:
1421 log.warning("An authentication challenge was not sent, "
1422 "this is suspicious because the driver expects "
1423 "authentication (configured authenticator = %s)",
1424 self.authenticator.__class__.__name__)
1425
1426 log.debug("Got ReadyMessage on new connection (%s) from %s", id(self), self.endpoint)
1427 self._enable_compression()
1428
1429 if ProtocolVersion.has_checksumming_support(self.protocol_version):
1430 self._enable_checksumming()
1431
1432 self.connected_event.set()
1433 elif isinstance(startup_response, AuthenticateMessage):
1434 log.debug("Got AuthenticateMessage on new connection (%s) from %s: %s",
1435 id(self), self.endpoint, startup_response.authenticator)
1436
1437 if self.authenticator is None:
1438 log.error("Failed to authenticate to %s. If you are trying to connect to a DSE cluster, "
1439 "consider using TransitionalModePlainTextAuthProvider "
1440 "if DSE authentication is configured with transitional mode" % (self.host,))
1441 raise AuthenticationFailed('Remote end requires authentication')
1442
1443 self._enable_compression()
1444 if ProtocolVersion.has_checksumming_support(self.protocol_version):
1445 self._enable_checksumming()
1446
1447 if isinstance(self.authenticator, dict):
1448 log.debug("Sending credentials-based auth response on %s", self)
1449 cm = CredentialsMessage(creds=self.authenticator)
1450 callback = partial(self._handle_startup_response, did_authenticate=True)
1451 self.send_msg(cm, self.get_request_id(), cb=callback)
1452 else:
1453 log.debug("Sending SASL-based auth response on %s", self)
1454 self.authenticator.server_authenticator_class = startup_response.authenticator
1455 initial_response = self.authenticator.initial_response()
1456 initial_response = "" if initial_response is None else initial_response
1457 self.send_msg(AuthResponseMessage(initial_response), self.get_request_id(),
1458 self._handle_auth_response)
1459 elif isinstance(startup_response, ErrorMessage):
1460 log.debug("Received ErrorMessage on new connection (%s) from %s: %s",
1461 id(self), self.endpoint, startup_response.summary_msg())
1462 if did_authenticate:
1463 raise AuthenticationFailed(
1464 "Failed to authenticate to %s: %s" %
1465 (self.endpoint, startup_response.summary_msg()))
1466 else:
1467 raise ConnectionException(
1468 "Failed to initialize new connection to %s: %s"
1469 % (self.endpoint, startup_response.summary_msg()))
1470 elif isinstance(startup_response, ConnectionShutdown):
1471 log.debug("Connection to %s was closed during the startup handshake", (self.endpoint))
1472 raise startup_response

Callers

nothing calls this directly

Calls 12

_enable_compressionMethod · 0.95
_enable_checksummingMethod · 0.95
send_msgMethod · 0.95
get_request_idMethod · 0.95
CredentialsMessageClass · 0.90
AuthResponseMessageClass · 0.90
ConnectionExceptionClass · 0.85
ProtocolErrorClass · 0.85
summary_msgMethod · 0.80
initial_responseMethod · 0.45

Tested by

no test coverage detected