Skip to content

Commit

Permalink
Merge pull request #7 from thibaultCha/feature/ssl
Browse files Browse the repository at this point in the history
[feature] TLS support for luasocket + nginx cosocket API
  • Loading branch information
thibaultcha committed Jul 9, 2015
2 parents b80ebd4 + 35fb85d commit f689162
Show file tree
Hide file tree
Showing 16 changed files with 267 additions and 28 deletions.
3 changes: 2 additions & 1 deletion doc/examples/authentication.lua.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ <h2>Examples</h2>
<li><a href="../examples/basic.lua.html">basic.lua</a></li>
<li><a href="../examples/batch.lua.html">batch.lua</a></li>
<li><a href="../examples/pagination.lua.html">pagination.lua</a></li>
<li><a href="../examples/ssl.lua.html">ssl.lua</a></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
Expand Down Expand Up @@ -78,7 +79,7 @@ <h2>authentication.lua</h2>
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-07-07 16:23:47 </i>
<i style="float:right;">Last updated 2015-07-10 00:32:25 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
3 changes: 2 additions & 1 deletion doc/examples/basic.lua.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ <h2>Examples</h2>
<li><strong>basic.lua</strong></li>
<li><a href="../examples/batch.lua.html">batch.lua</a></li>
<li><a href="../examples/pagination.lua.html">pagination.lua</a></li>
<li><a href="../examples/ssl.lua.html">ssl.lua</a></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
Expand Down Expand Up @@ -100,7 +101,7 @@ <h2>basic.lua</h2>
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-07-07 16:23:47 </i>
<i style="float:right;">Last updated 2015-07-10 00:32:25 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
3 changes: 2 additions & 1 deletion doc/examples/batch.lua.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ <h2>Examples</h2>
<li><a href="../examples/basic.lua.html">basic.lua</a></li>
<li><strong>batch.lua</strong></li>
<li><a href="../examples/pagination.lua.html">pagination.lua</a></li>
<li><a href="../examples/ssl.lua.html">ssl.lua</a></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
Expand Down Expand Up @@ -80,7 +81,7 @@ <h2>batch.lua</h2>
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-07-07 16:23:47 </i>
<i style="float:right;">Last updated 2015-07-10 00:32:25 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
3 changes: 2 additions & 1 deletion doc/examples/pagination.lua.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ <h2>Examples</h2>
<li><a href="../examples/basic.lua.html">basic.lua</a></li>
<li><a href="../examples/batch.lua.html">batch.lua</a></li>
<li><strong>pagination.lua</strong></li>
<li><a href="../examples/ssl.lua.html">ssl.lua</a></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
Expand Down Expand Up @@ -90,7 +91,7 @@ <h2>pagination.lua</h2>
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-07-07 16:23:47 </i>
<i style="float:right;">Last updated 2015-07-10 00:32:25 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
57 changes: 57 additions & 0 deletions doc/examples/ssl.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
--------
-- Example of SSL enabled connection using luasocket

local cassandra = require "cassandra"
local PasswordAuthenticator = require "cassandra.authenticators.PasswordAuthenticator"

local session = cassandra:new()
local auth = PasswordAuthenticator("cassandra", "cassandra")

local ok, err = session:connect({"x.x.x.x", "y.y.y.y"}, nil, {
authenticator = auth,
ssl = true,
ssl_verify = true,
ca_file = "/path/to/your/ca-certificate.pem"
})
if not ok then
print(err.message)
end

local res, err = session:execute("SELECT * FROM system_auth.users")

--------
-- Example of SSL enabled connection from nginx

worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
server {
listen 8080;
location / {
lua_ssl_trusted_certificate "/path/to/your/ca-certificate.pem";
default_type text/html;
content_by_lua '
local cassandra = require "cassandra"
local PasswordAuthenticator = require "cassandra.authenticators.PasswordAuthenticator"

local session = cassandra:new()
local auth = PasswordAuthenticator("cassandra", "cassandra")

local ok, err = session:connect({"x.x.x.x", "y.y.y.y"}, nil, {
authenticator = auth,
ssl = true,
ssl_verify = true
})
if not ok then
ngx.log(ngx.ERR, err.message)
end

local res, err = session:execute("SELECT * FROM system_auth.users")
';
}
}
}

128 changes: 128 additions & 0 deletions doc/examples/ssl.lua.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>lua-cassandra documentation</title>
<link rel="stylesheet" href="../ldoc_pale.css" type="text/css" />
</head>
<body>

<div id="container">

<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->


<div id="main">


<!-- Menu -->

<div id="navigation">
<br/>
<h1>lua-cassandra</h1>

<ul>
<li><a href="../index.html">Index</a></li>
</ul>



<h2>Examples</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../examples/authentication.lua.html">authentication.lua</a></li>
<li><a href="../examples/basic.lua.html">basic.lua</a></li>
<li><a href="../examples/batch.lua.html">batch.lua</a></li>
<li><a href="../examples/pagination.lua.html">pagination.lua</a></li>
<li><strong>ssl.lua</strong></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../modules/Cassandra.html">Cassandra</a></li>
<li><a href="../modules/PasswordAuthenticator.html">PasswordAuthenticator</a></li>
<li><a href="../modules/BatchStatement.html">BatchStatement</a></li>
<li><a href="../modules/Error.html">Error</a></li>
<li><a href="../modules/Session.html">Session</a></li>
</ul>
<h2>Manual</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../manual/README.md.html">README</a></li>
</ul>

</div>

<div id="content">

<h2>ssl.lua</h2>
<pre>
<span class="comment">--------
</span><span class="comment">-- Example of SSL enabled connection using luasocket
</span>
<span class="keyword">local</span> cassandra = <span class="global">require</span> <span class="string">"cassandra"</span>
<span class="keyword">local</span> PasswordAuthenticator = <span class="global">require</span> <span class="string">"cassandra.authenticators.PasswordAuthenticator"</span>

<span class="keyword">local</span> session = cassandra:new()
<span class="keyword">local</span> auth = PasswordAuthenticator(<span class="string">"cassandra"</span>, <span class="string">"cassandra"</span>)

<span class="keyword">local</span> ok, err = session:connect({<span class="string">"x.x.x.x"</span>, <span class="string">"y.y.y.y"</span>}, <span class="keyword">nil</span>, {
authenticator = auth,
ssl = <span class="keyword">true</span>,
ssl_verify = <span class="keyword">true</span>,
ca_file = <span class="string">"/path/to/your/ca-certificate.pem"</span>
})
<span class="keyword">if</span> <span class="keyword">not</span> ok <span class="keyword">then</span>
<span class="global">print</span>(err.message)
<span class="keyword">end</span>

<span class="keyword">local</span> res, err = session:execute(<span class="string">"SELECT * FROM system_auth.users"</span>)

<span class="comment">--------
</span><span class="comment">-- Example of SSL enabled connection from nginx
</span>
worker_processes <span class="number">1</span>;
error_log logs/error.log;
events {
worker_connections <span class="number">1024</span>;
}
http {
server {
listen <span class="number">8080</span>;
location / {
lua_ssl_trusted_certificate <span class="string">"/path/to/your/ca-certificate.pem"</span>;
default_type text/html;
content_by_lua <span class="string">'
local cassandra = require "cassandra"
local PasswordAuthenticator = require "cassandra.authenticators.PasswordAuthenticator"

local session = cassandra:new()
local auth = PasswordAuthenticator("cassandra", "cassandra")

local ok, err = session:connect({"x.x.x.x", "y.y.y.y"}, nil, {
authenticator = auth,
ssl = true,
ssl_verify = true
})
if not ok then
ngx.log(ngx.ERR, err.message)
end

local res, err = session:execute("SELECT * FROM system_auth.users")
'</span>;
}
}
}</pre>


</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-07-10 00:32:25 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>
7 changes: 6 additions & 1 deletion doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ <h2>Examples</h2>
<li><a href="examples/basic.lua.html">basic.lua</a></li>
<li><a href="examples/batch.lua.html">batch.lua</a></li>
<li><a href="examples/pagination.lua.html">pagination.lua</a></li>
<li><a href="examples/ssl.lua.html">ssl.lua</a></li>
</ul>

</div>
Expand Down Expand Up @@ -105,13 +106,17 @@ <h2>Examples</h2>
<td class="name" nowrap><a href="examples/pagination.lua.html">pagination.lua</a></td>
<td class="summary"></td>
</tr>
<tr>
<td class="name" nowrap><a href="examples/ssl.lua.html">ssl.lua</a></td>
<td class="summary"></td>
</tr>
</table>

</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-07-07 16:23:47 </i>
<i style="float:right;">Last updated 2015-07-10 00:32:25 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
3 changes: 2 additions & 1 deletion doc/manual/README.md.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ <h2>Examples</h2>
<li><a href="../examples/basic.lua.html">basic.lua</a></li>
<li><a href="../examples/batch.lua.html">batch.lua</a></li>
<li><a href="../examples/pagination.lua.html">pagination.lua</a></li>
<li><a href="../examples/ssl.lua.html">ssl.lua</a></li>
</ul>

</div>
Expand Down Expand Up @@ -135,7 +136,7 @@ <h2>Usage</h2>
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-07-07 16:23:47 </i>
<i style="float:right;">Last updated 2015-07-10 00:32:25 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
3 changes: 2 additions & 1 deletion doc/modules/BatchStatement.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ <h2>Examples</h2>
<li><a href="../examples/basic.lua.html">basic.lua</a></li>
<li><a href="../examples/batch.lua.html">batch.lua</a></li>
<li><a href="../examples/pagination.lua.html">pagination.lua</a></li>
<li><a href="../examples/ssl.lua.html">ssl.lua</a></li>
</ul>

</div>
Expand Down Expand Up @@ -114,7 +115,7 @@ <h3>Parameters:</h3>
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-07-07 16:23:47 </i>
<i style="float:right;">Last updated 2015-07-10 00:32:25 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
3 changes: 2 additions & 1 deletion doc/modules/Error.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ <h2>Examples</h2>
<li><a href="../examples/basic.lua.html">basic.lua</a></li>
<li><a href="../examples/batch.lua.html">batch.lua</a></li>
<li><a href="../examples/pagination.lua.html">pagination.lua</a></li>
<li><a href="../examples/ssl.lua.html">ssl.lua</a></li>
</ul>

</div>
Expand Down Expand Up @@ -115,7 +116,7 @@ <h3>Fields:</h3>
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-07-07 16:23:47 </i>
<i style="float:right;">Last updated 2015-07-10 00:32:25 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
3 changes: 2 additions & 1 deletion doc/modules/PasswordAuthenticator.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ <h2>Examples</h2>
<li><a href="../examples/basic.lua.html">basic.lua</a></li>
<li><a href="../examples/batch.lua.html">batch.lua</a></li>
<li><a href="../examples/pagination.lua.html">pagination.lua</a></li>
<li><a href="../examples/ssl.lua.html">ssl.lua</a></li>
</ul>

</div>
Expand Down Expand Up @@ -77,7 +78,7 @@ <h3>Usage:</h3>
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-07-07 16:23:47 </i>
<i style="float:right;">Last updated 2015-07-10 00:32:25 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
3 changes: 2 additions & 1 deletion doc/modules/cassandra.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ <h2>Examples</h2>
<li><a href="../examples/basic.lua.html">basic.lua</a></li>
<li><a href="../examples/batch.lua.html">batch.lua</a></li>
<li><a href="../examples/pagination.lua.html">pagination.lua</a></li>
<li><a href="../examples/ssl.lua.html">ssl.lua</a></li>
</ul>

</div>
Expand Down Expand Up @@ -161,7 +162,7 @@ <h3>Parameters:</h3>
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-07-07 16:23:47 </i>
<i style="float:right;">Last updated 2015-07-10 00:32:25 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
Loading

0 comments on commit f689162

Please sign in to comment.