forked from thibaultcha/lua-cassandra
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssl.lua
More file actions
55 lines (44 loc) · 1.44 KB
/
Copy pathssl.lua
File metadata and controls
55 lines (44 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
------------------------------------------
-- Single host module with SSL connections
-- Required modules: LuaSocket, LuaSec
------------------------------------------
local cassandra = require "cassandra"
local client = assert(cassandra.new {
ssl = true,
verify = true, -- optionally, verify the server certificate
cafile = "/path/to/node-certificate.pem" -- optionally, the CA in PEM format
})
assert(client:connect())
--------------------------------------
-- Cluster module with SSL connections
--------------------------------------
http {
lua_shared_dict cassandra 1m;
server {
...
location / {
# this will be used to verify the server certificate
lua_ssl_trusted_certificate "/path/to/node-certificate.pem";
content_by_lua_block {
local Cluster = require "resty.cassandra.cluster"
local cluster, err = Cluster.new {
shm = "cassandra", -- defined in http block
contact_points = {"127.0.0.1", "127.0.0.2"},
keyspace = "my_keyspace",
ssl = true,
verify = true
}
if not cluster then
ngx.log(ngx.ERR, "could not create cluster: ", err)
ngx.exit(500)
end
local ok, err = cluster:refresh() -- automatically called upon first query
if not ok then
ngx.log(ngx.ERR, "could not connect to cluster: ", err)
ngx.exit(500)
end
ngx.say("SSL connection: OK")
}
}
}
}