在我的Cassandra配置中,我启用了用户身份验证,并通过ssl与cqlsh连接。 我在使用gocql时遇到了问题,以下是我的代码:
cluster := gocql.NewCluster("127.0.0.1")
cluster.Authenticator = gocql.PasswordAuthenticator{
Username: "myuser",
Password: "mypassword",
}
cluster.SslOpts = &gocql.SslOptions {
CertPath: "/path/to/cert.pem",
}
当我尝试连接时,我收到以下错误:
gocql: unable to create session: connectionpool: unable to load X509 key pair: open : no such file or directory
在python中,我可以用以下内容来完成:
from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider
USER = 'username'
PASS = 'password'
ssl_opts = {'ca_certs': '/path/to/cert.pem',
'ssl_version': PROTOCOL_TLSv1
}
credentials = PlainTextAuthProvider(username = USER, password = PASS)
# define host, port, cqlsh protocaol version
cluster = Cluster(contact_points= HOST, protocol_version= CQLSH_PROTOCOL_VERSION, auth_provider = credentials, port = CASSANDRA_PORT)
答案 0 :(得分:1)
您正在添加没有私钥的证书,这是"没有这样的文件或目录"错误来自。
您的python代码正在添加CA;你应该对Go代码做同样的事情:
gocql.SslOptions {
CaPath: "/path/to/cert.pem",
}