Skip to content

Instantly share code, notes, and snippets.

@iSignal
Last active May 11, 2022 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iSignal/1c8cb0741e54650acc7672ca1a9d2e2f to your computer and use it in GitHub Desktop.
Save iSignal/1c8cb0741e54650acc7672ca1a9d2e2f to your computer and use it in GitHub Desktop.
# pip install yb-cassandra-driver to be able to import cassandra.cluster
from cassandra.cluster import Cluster, Session
from ssl import SSLContext, PROTOCOL_TLS, CERT_REQUIRED
import os
import sys
hostname = sys.argv[1]
ssl_context = SSLContext(PROTOCOL_TLS)
ssl_context.load_verify_locations(cafile=os.getenv('SSL_CERTFILE'))
ssl_context.verify_mode = CERT_REQUIRED
ssl_context.check_hostname = True
ssl_options = {'server_hostname': hostname}
cluster = Cluster([hostname], ssl_context=ssl_context, ssl_options=ssl_options)
session = cluster.connect()
print(session.execute("SELECT * FROM system.local;").one())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment