在 Node.js 中使用 cassandra-driver 通过 SSL 连接到 Cassandra Apache [英] Connect to Cassandra Apache with SSL using cassandra-driver in Node.js

查看:15
本文介绍了在 Node.js 中使用 cassandra-driver 通过 SSL 连接到 Cassandra Apache的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试连接到我的 Cassandra,但我可能配置错误.我在本地主机上运行它.Cassandra 已生成证书并添加.在 cqlsh 中,标志 --ssl 没有错误.我的片段代码是

I try connect to my Cassandra but I have probably wrongly configured. I run it on localhost. Cassandra has generated certificated and add on. In cqlsh there are no errors with flag --ssl. My fragment code is

var tls = require('tls');
var fs = require('fs');
var options = {
	key : fs.readFileSync('client-key.pem'),
	cert : fs.readFileSync('client-cert.pem'),
	ca : [fs.readFileSync('server-cert.pem')]
};
var client = new cassandra.Client({
		contactPoints : ['127.0.0.1'],
		authProvider : new cassandra.auth.PlainTextAuthProvider('cassandra', 'cassandra'),
		sslOptions : tls.connect(options)
	});

我做错了什么?请帮忙!

what I'm doing wrong? Please help!

推荐答案

您必须在 sslOption 属性中指定一个 Object 实例才能在驱动程序上启用 ssl.

You must specify an Object instance in sslOption property to enable ssl on the driver.

使用您的代码示例:

var fs = require('fs');
var sslOptions = {
  key : fs.readFileSync('client-key.pem'),
  cert : fs.readFileSync('client-cert.pem'),
  ca : [fs.readFileSync('server-cert.pem')]
};
var client = new cassandra.Client({
  contactPoints : ['127.0.0.1'],
  authProvider : new cassandra.auth.PlainTextAuthProvider('cassandra', 'cassandra'),
  sslOptions : sslOptions
});

如果你不使用客户端证书,你可以只使用一个空的对象实例:

If you do not use client certificates, you can just use an empty object instance:

var client = new cassandra.Client({
  contactPoints : ['127.0.0.1'],
  authProvider : new cassandra.auth.PlainTextAuthProvider('cassandra', 'cassandra'),
  sslOptions : {}
});

它将使用 Node.js tls 模块中指定的默认值.

And it will use the defaults specified in the Node.js tls module.

这篇关于在 Node.js 中使用 cassandra-driver 通过 SSL 连接到 Cassandra Apache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆