Browse Source

lua-ssllabs 0.2-0

* moved conatants tables DEFAULTS and ERRORS out of functions
* shortened function bool_to_paramter
* rewrote the api_requests function
* added two new public functions  and
* some code cleanup and typo fixes
* updates the documentation
master v0.2-0
Sebastian 3 years ago
parent
commit
dff0f70561
Signed by: imo GPG Key ID: AFA10CBFE4391C0C
  1. 5
      .gitignore
  2. 10
      CHANGELOG.md
  3. 4
      README.md
  4. 10
      docs/config.ld
  5. 27
      docs/examples/demo.lua.html
  6. 164
      docs/index.html
  7. 23
      examples/demo.lua
  8. 0
      rocks/lua-ssllabs-0.1-0.rockspec
  9. 8
      rocks/lua-ssllabs-0.1-1.rockspec
  10. 30
      rocks/lua-ssllabs-0.2-0.rockspec
  11. 182
      src/ssllabs/init.lua

5
.gitignore

@ -0,0 +1,5 @@
*.src.rock
/lua
/lua_modules
.luarocks
luarocks

10
CHANGELOG.md

@ -1,4 +1,12 @@
2018-07-16 - lua-ssllabs 0.2-0 - Sebastian Hübner <sh@kokolor.es>
2019-02-01 - lua-ssllabs 0.2-0 - Sebastian Hübner <sh@kokolor.es>
* moved conatants tables DEFAULTS and ERRORS out of functions
* shortened function bool_to_paramter
* rewrote the api_requests function
* added two new public functions `ssllabs.from_cache()` and `ssllabs.new_assessment()`
* some code cleanup and typo fixes
* updates the documentation
2018-07-16 - lua-ssllabs 0.1-2 - Sebastian Hübner <sh@kokolor.es>
* added check_options functions which check the parameters
* fixed a bug with default values in analyse function

4
README.md

@ -9,4 +9,6 @@ The documentation was created with [ldoc](https://github.com/stevedonovan/LDoc).
## Dependencies
lua (>=5.1), [lua-requests](https://github.com/JakobGreen/lua-requests)
* lua (>=5.1)
* lua-cjson (== 2.1.0-1)
* [lua-requests](https://github.com/JakobGreen/lua-requests)

10
docs/config.ld

@ -1,12 +1,12 @@
project = 'lua-ssllabs'
description = 'Lua module for the Qualys SSL Labs Server Test'
title = 'lua-ssllabs documentation'
description = 'Lua module for the Qualys SSL Labs Server Test'
use_markdown_titles = true
dir = 'docs'
package = 'ssllabs'
dir = '../docs'
file = '../src'
format = 'discount'
sort_modules = true
kind_names = {module='Libraries'}
kind_names = { topic = 'Manual', script = 'Programs' }
examples = {
'examples/demo.lua'
'../examples/demo.lua'
}

27
docs/examples/demo.lua.html

@ -33,7 +33,7 @@
<ul class="nowrap">
<li><strong>demo.lua</strong></li>
</ul>
<h2>Libraries</h2>
<h2>Modules</h2>
<ul class="nowrap">
<li><a href="../index.html">ssllabs</a></li>
</ul>
@ -49,27 +49,32 @@
<span class="keyword">local</span> ssll = <span class="global">require</span>(<span class="string">'ssllabs'</span>)
<span class="comment">-- define options for API call
</span><span class="keyword">local</span> opts = {
host = <span class="string">'example.com'</span>,
publish = <span class="keyword">true</span>,
startNew = <span class="keyword">false</span>
}
<span class="keyword">local</span> <span class="keyword">function</span> sleep(n)
<span class="global">os</span>.execute(<span class="string">'sleep '</span> .. <span class="global">tonumber</span>(n))
<span class="keyword">end</span>
<span class="keyword">local</span> opts = {
host = <span class="string">'edolas.world'</span>,
publish = <span class="keyword">false</span>,
startNew = <span class="keyword">false</span>
}
<span class="comment">-- start new assessment for host 'httpbin.com' and publish the result on the public board
</span><span class="keyword">local</span> resp = ssll.analyze(opts)
</span><span class="keyword">local</span> resp, err, msg = ssll.analyze(opts)
<span class="keyword">if</span> err <span class="keyword">then</span> <span class="global">print</span>(msg) <span class="keyword">end</span>
<span class="comment">-- if status is not READY or ERROR
</span><span class="keyword">if</span> resp.status ~= <span class="string">'READY'</span> <span class="keyword">and</span> resp.status ~= <span class="string">'ERROR'</span> <span class="keyword">then</span>
<span class="comment">-- remove startNew option, to prevent assessment looping
</span> opts.startNew = <span class="keyword">false</span>
<span class="comment">-- check every 30s if assessment is ready or failed
</span> <span class="keyword">repeat</span>
<span class="global">print</span>(test)
<span class="comment">-- get progress displayed per endpoint during assessment
</span> <span class="keyword">for</span> _, v <span class="keyword">in</span> <span class="global">ipairs</span>(resp.endpoints) <span class="keyword">do</span>
<span class="global">print</span>(<span class="global">string</span>.format(<span class="string">'%s progess: %d'</span>, v.ipAddress, v.progress <span class="keyword">or</span> <span class="number">0</span>))
<span class="global">print</span>(<span class="global">string</span>.format(<span class="string">'%s progess: %d%%'</span>, v.ipAddress, v.progress <span class="keyword">or</span> <span class="number">0</span>))
<span class="keyword">end</span>
sleep(<span class="number">30</span>)
resp = ssll.analyze(opts)
@ -92,7 +97,7 @@
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2018-07-16 17:36:29 </i>
<i style="float:right;">Last updated 2019-02-01 09:40:10 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>

164
docs/index.html

@ -33,7 +33,7 @@
</ul>
<h2>Libraries</h2>
<h2>Modules</h2>
<ul class="nowrap">
<li><strong>ssllabs</strong></li>
</ul>
@ -53,7 +53,7 @@
</p>
<h3>Info:</h3>
<ul>
<li><strong>Copyright</strong>: 2018</li>
<li><strong>Copyright</strong>: 2019</li>
<li><strong>License</strong>: MIT</li>
<li><strong>Author</strong>: Sebastian Huebner</li>
</ul>
@ -71,6 +71,14 @@
<td class="summary">Invoke assessment and check progress.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#from_cache">from_cache (host[, maxAge])</a></td>
<td class="summary">Retrieve cached assessment report.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#new_assessment">new_assessment (opts)</a></td>
<td class="summary">Start new assessment.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#get_endpoint_data">get_endpoint_data (opts)</a></td>
<td class="summary">Retrieve detailed endpoint information.</td>
</tr>
@ -103,9 +111,15 @@
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
<a href="https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#info">Info table</a>
<li>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a> or <span class="type">nil</span></span>
<a href="https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#info">Info table</a> / In case of error nil</li>
<li>
<span class="types"><span class="type">number</span></span>
error status code</li>
<li>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
error status message</li>
</ol>
@ -135,7 +149,7 @@
</li>
<li><span class="parameter">publish</span>
<span class="types"><span class="type">bool</span></span>
if set to <code>&apos;on&apos;</code> or <code>true</code> the result will be published ont he public result boards.
if set to <code>&apos;on&apos;</code> or <code>true</code> the result will be published on the public result boards.
(<em>default</em> false)
</li>
<li><span class="parameter">startNew</span>
@ -161,16 +175,22 @@
<li><span class="parameter">ignoreMismatch</span>
<span class="types"><span class="type">bool</span></span>
set to <code>on</code> to proceed with assessments even when the server certificate doesn't match the assessment hostname. Please note that this parameter is ignored if a cached report is returned.
(<em>default</em> 'off')
(<em>default</em> false)
</li>
</li></ul>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
<a href="https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#host">Host table</a>
<li>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a> or <span class="type">nil</span></span>
<a href="https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#host">Host table</a></li>
<li>
<span class="types"><span class="type">nil</span> or <span class="type">number</span></span>
error status code</li>
<li>
<span class="types"><span class="type">nil</span> or <a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
error status message</li>
</ol>
@ -184,6 +204,104 @@
})</pre>
</ul>
</dd>
<dt>
<a name = "from_cache"></a>
<strong>from_cache (host[, maxAge])</strong>
</dt>
<dd>
Retrieve cached assessment report.
Short for <code>ssllabs.analyze({host = host, fromCache = true})</code>.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">host</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
hostname
</li>
<li><span class="parameter">maxAge</span>
<span class="types"><span class="type">number</span></span>
maximum report age, in hours, if retrieving from cache (<code>fromCache</code> parameter set).
(<em>optional</em>)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a> or <span class="type">nil</span></span>
<a href="https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#host">Host table</a></li>
<li>
<span class="types"><span class="type">nil</span> or <span class="type">number</span></span>
error status code</li>
<li>
<span class="types"><span class="type">nil</span> or <a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
error status message</li>
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">local</span> result = ssllabs.from_cache(<span class="string">'example.com'</span>, <span class="number">36</span>)</pre>
</ul>
</dd>
<dt>
<a name = "new_assessment"></a>
<strong>new_assessment (opts)</strong>
</dt>
<dd>
Start new assessment.
Short for <code>ssllabs.analyze({host = host, startNew = true})</code>.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">opts</span> options table with arguments
<ul>
<li><span class="parameter">host</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
hostname
</li>
<li><span class="parameter">publish</span>
<span class="types"><span class="type">bool</span></span>
if set to <code>&apos;on&apos;</code> or <code>true</code> the result will be published on the public result boards.
(<em>default</em> false)
</li>
<li><span class="parameter">ignoreMismatch</span>
<span class="types"><span class="type">bool</span></span>
set to <code>on</code> to proceed with assessments even when the server certificate doesn't match the assessment hostname. Please note that this parameter is ignored if a cached report is returned.
(<em>default</em> false)
</li>
</li></ul>
</ul>
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a> or <span class="type">nil</span></span>
<a href="https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#host">Host table</a></li>
<li>
<span class="types"><span class="type">nil</span> or <span class="type">number</span></span>
error status code</li>
<li>
<span class="types"><span class="type">nil</span> or <a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
error status message</li>
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">local</span> result = ssllabs.new_assessment({
host = <span class="string">'example.com'</span>,
publish = <span class="keyword">true</span>,
ignoreMismatch = <span class="keyword">false</span>
})</pre>
</ul>
</dd>
<dt>
<a name = "get_endpoint_data"></a>
@ -218,9 +336,15 @@
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
<a href="https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#endpoint">Endpoint table</a>
<li>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a> or <span class="type">nil</span></span>
<a href="https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#endpoint">Endpoint table</a></li>
<li>
<span class="types"><span class="type">nil</span> or <span class="type">number</span></span>
error status code</li>
<li>
<span class="types"><span class="type">nil</span> or <a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
error status message</li>
</ol>
@ -242,9 +366,15 @@
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a></span>
<a href="https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#statuscodes">StatusCode table</a>
<li>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.6">table</a> or <span class="type">nil</span></span>
<a href="https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#statuscodes">StatusCode table</a></li>
<li>
<span class="types"><span class="type">nil</span> or <span class="type">number</span></span>
error status code</li>
<li>
<span class="types"><span class="type">nil</span> or <a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
error status message</li>
</ol>
@ -286,7 +416,7 @@
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2018-07-16 17:36:29 </i>
<i style="float:right;">Last updated 2019-02-01 09:40:10 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>

23
examples/demo.lua

@ -2,28 +2,33 @@
package.path = './src/?.lua;./src/?/init.lua;' .. package.path
local ssll = require('ssllabs')
-- define options for API call
local opts = {
host = 'p.kokolor.es',
publish = true,
startNew = false,
maxAge = 36
}
local function sleep(n)
os.execute('sleep ' .. tonumber(n))
end
local opts = {
host = 'edolas.world',
publish = false,
startNew = false
}
-- start new assessment for host 'httpbin.com' and publish the result on the public board
local resp = ssll.analyze(opts)
local resp, err, msg = ssll.analyze(opts)
if err then print(msg) end
-- if status is not READY or ERROR
if resp.status ~= 'READY' and resp.status ~= 'ERROR' then
-- remove startNew option, to prevent assessment looping
opts.startNew = false
-- check every 30s if assessment is ready or failed
repeat
print(test)
-- get progress displayed per endpoint during assessment
for _, v in ipairs(resp.endpoints) do
print(string.format('%s progess: %d', v.ipAddress, v.progress or 0))
print(string.format('%s progess: %d%%', v.ipAddress, v.progress or 0))
end
sleep(30)
resp = ssll.analyze(opts)

0
lua-ssllabs-0.1-0.rockspec → rocks/lua-ssllabs-0.1-0.rockspec

8
lua-ssllabs-0.1-1.rockspec → rocks/lua-ssllabs-0.1-1.rockspec

@ -2,14 +2,12 @@ package = "lua-ssllabs"
version = "0.1-1"
source = {
url = "git://github.com/imolein/lua-ssllabs.git",
tag = "v0.1-1"
tag = "v0.2-0"
}
description = {
summary = "Lua module for the Qualys SSL Labs Server Test.",
detailed = [[
A little lua library which provide an easy-to-use interface
for the Qualys SSL Labs Server Test API (v3).
]],
detailed = "A little lua library which provide an easy-to-use interface" ..
"for the Qualys SSL Labs Server Test API (v3).",
homepage = "https://git.kokolor.es/imo/lua-ssllabs",
license = "MIT"
}

30
rocks/lua-ssllabs-0.2-0.rockspec

@ -0,0 +1,30 @@
rockspec_format = "3.0"
package = "lua-ssllabs"
version = "0.2-0"
source = {
url = "git://github.com/imolein/lua-ssllabs.git",
tag = "v0.2-0"
}
description = {
summary = "Lua module for the Qualys SSL Labs Server Test.",
detailed = "A little lua library which provide an easy-to-use interface" ..
"for the Qualys SSL Labs Server Test API (v3).",
homepage = "https://git.kokolor.es/imo/lua-ssllabs",
license = "MIT",
issues_url = "https://github.com/imolein/lua-ssllabs/issues",
maintainer = "Sebastian Huebner <sh@kokolor.es>",
labels = { "web", "ssllabs" }
}
dependencies = {
"lua >= 5.1, < 5.4",
"lua-cjson == 2.1.0-1",
"lua-requests"
}
build = {
type = "builtin",
copy_directories = { "docs" },
modules = {
ssllabs = "src/ssllabs/init.lua"
}
}

182
src/ssllabs/init.lua

@ -1,67 +1,60 @@
--- Lua module for the Qualys SSL Labs Server Test
--
-- @author Sebastian Huebner
-- @copyright 2018
-- @copyright 2019
-- @license MIT
-- @module ssllabs
local requests = require('requests')
local ssllabs = {
_VERSION = 'lua-ssllabs 0.1-2',
_VERSION = 'lua-ssllabs 0.2-0',
_DESCRIPTION = 'Lua module for the Qualys SSL Labs Server Test',
_URL = 'https://git.kokolor.es/imo/lua-ssllabs',
_LICENCE = [[
MIT Licence
Copyright (c) 2018 Sebastian Huebner
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
]]
_LICENCE = 'MIT'
}
local API = 'https://api.ssllabs.com/api/v3/'
local ERRORS = {
['400'] = 'Invocation error (invalid Parameters)',
['429'] = 'Request rate to high',
['500'] = 'Internal Error',
['503'] = 'Service not availabke',
['529'] = 'Service is overloaded'
}
local DEFAULTS = {
publish = false,
startNew = false,
fromCache = false,
maxAge = nil,
all = nil,
ignoreMismatch = false
}
-- Private functions
-- Private functions --
-- check the given options
local function check_options(pl)
if not pl.host or pl.host == '' then
error('host required.')
return nil, 'host required.'
elseif pl.startNew and pl.fromCache then
error('fromCache cannot be used at the same time as startNew.')
return nil, 'fromCache cannot be used at the same time as startNew.'
elseif pl.maxAge and not pl.fromCache then
error('maxAge expects fromCache parameter to be true.')
end
return nil, 'maxAge expects fromCache parameter to be true.'
end
return pl
end
-- since you can give the option values as string
-- OR boolean, we have to check and change them
local function bool_to_parameter(pl)
if not pl then return end
local converted = {}
for k, v in pairs(pl) do
if type(v) == 'boolean' then
if tostring(v) == 'true' then
converted[k] = 'on'
elseif tostring(v) == 'false' then
converted[k] = 'off'
end
converted[k] = v and 'on' or 'off'
else
converted[k] = v
end
@ -70,24 +63,39 @@ local function bool_to_parameter(pl)
return converted
end
-- the function, which make the request
local function api_request(path, payload)
local payload = bool_to_parameter(payload)
payload = payload and bool_to_parameter(payload)
local resp
resp = requests.get({ url = API .. path, params = payload })
if path == 'getRootCertsRaw' then
resp = requests.get({ url = API .. path, params = payload })
else
resp = requests.get({ url = API .. path, params = payload }).json()
if resp.status_code ~= 200 then
return nil, resp.status_code, ERRORS[tostring(resp.status_code)]
end
return resp
if resp.headers['content-type']:find('application/json', nil, true) then
local jresp = resp.json()
if jresp.errors then
return nil, 400, string.format('Invocation Error - API returned: %s', jresp.errors.message)
end
return jresp
else
return resp.text
end
end
-- Public function
-- Public functions --
--- Check availability of the SSL Labs servers
-- and some other data like software version. Implements the [info API call](https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#check-ssl-labs-availability)
-- @treturn table [Info table](https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#info)
-- @treturn ?table|nil [Info table](https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#info) / In case of error nil
-- @treturn number error status code
-- @treturn string error status message
-- @usage local info = ssllabs.info()
function ssllabs.info()
return api_request('info')
@ -97,29 +105,22 @@ end
-- This call is used to initiate an assessment, or to retrieve the status of an assessment in progress or in the cache. Implements the [analyze API call](https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#invoke-assessment-and-check-progress)
-- @tab opts options table with arguments
-- @string opts.host hostname
-- @bool[opt=false] opts.publish if set to `'on'` or `true` the result will be published ont he public result boards.
-- @bool[opt=false] opts.publish if set to `'on'` or `true` the result will be published on the public result boards.
-- @bool[opt=false] opts.startNew if set to `'on'` or `true` a new assessment is started. However, if there's already an assessment in progress, its status is delivered instead.
-- @bool[opt=true] opts.fromCache if set to `'on'` or `true` cached assessment reports will be returned.
-- @number[opt=10] opts.maxAge maximum report age, in hours, if retrieving from cache (`fromCache` parameter set).
-- @string[opt='done'] opts.all by default this call results only summaries of individual endpoints. If this parameter is set to `on`, full information will be returned. If set to `done`, full information will be returned only if the assessment is complete (status is `READY` or `ERROR`).
-- @bool[opt='off'] opts.ignoreMismatch set to `on` to proceed with assessments even when the server certificate doesn't match the assessment hostname. Please note that this parameter is ignored if a cached report is returned.
-- @treturn table [Host table](https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#host)
-- @bool[opt=false] opts.ignoreMismatch set to `on` to proceed with assessments even when the server certificate doesn't match the assessment hostname. Please note that this parameter is ignored if a cached report is returned.
-- @treturn ?table|nil [Host table](https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#host)
-- @treturn ?nil|number error status code
-- @treturn ?nil|string error status message
-- @usage local result = ssllabs.analyze({
-- host = 'example.com',
-- fromCache = true,
-- maxAge = 36
-- })
function ssllabs.analyze(opts)
local defaults = {
publish = false,
startNew = false,
fromCache = true,
maxAge = 10,
all = 'done',
ignoreMismatch = false
}
setmetatable(opts, { __index = defaults })
setmetatable(opts, { __index = DEFAULTS })
local payload = {
host = opts.host,
@ -133,7 +134,46 @@ function ssllabs.analyze(opts)
check_options(payload)
return api_request('analyze', payload)
return api_request('analyze', assert(check_options(payload)))
end
--- Retrieve cached assessment report.
-- Short for `ssllabs.analyze({host = host, fromCache = true})`.
-- @string host hostname
-- @number[opt] maxAge maximum report age, in hours, if retrieving from cache (`fromCache` parameter set).
-- @treturn ?table|nil [Host table](https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#host)
-- @treturn ?nil|number error status code
-- @treturn ?nil|string error status message
-- @usage local result = ssllabs.from_cache('example.com', 36)
function ssllabs.from_cache(host, maxAge)
return ssllabs.analyze({
host = host,
maxAge = maxAge,
fromCache = 'on'
})
end
--- Start new assessment.
-- Short for `ssllabs.analyze({host = host, startNew = true})`.
-- @tab opts options table with arguments
-- @string opts.host hostname
-- @bool[opt=false] opts.publish if set to `'on'` or `true` the result will be published on the public result boards.
-- @bool[opt=false] opts.ignoreMismatch set to `on` to proceed with assessments even when the server certificate doesn't match the assessment hostname. Please note that this parameter is ignored if a cached report is returned.
-- @treturn ?table|nil [Host table](https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#host)
-- @treturn ?nil|number error status code
-- @treturn ?nil|string error status message
-- @usage local result = ssllabs.new_assessment({
-- host = 'example.com',
-- publish = true,
-- ignoreMismatch = false
-- })
function ssllabs.new_assessment(opts)
return ssllabs.analyze({
host = opts.host,
startNew = 'on',
publish = opts.publish,
ignoreMismatch = opts.ignoreMismatch
})
end
--- Retrieve detailed endpoint information.
@ -142,18 +182,14 @@ end
-- @string opts.host hostname
-- @string opts.s endpoint IP address
-- @bool[opt=true] opts.fromCache
-- @treturn table [Endpoint table](https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#endpoint)
-- @treturn ?table|nil [Endpoint table](https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#endpoint)
-- @treturn ?nil|number error status code
-- @treturn ?nil|string error status message
-- @usage local ep_data = ssllabs.get_endpoint_data()
function ssllabs.get_endpoint_data(opts)
if not opts.host or not opts.s then
error('host and endpoint IP address required.')
end
local defaults = {
fromCache = true
}
assert(opts.host and opts.s, 'host and endpoint IP address required.')
setmetatable(opts, { __index = defaults })
setmetatable(opts, { __index = DEFAULTS })
local payload = {
host = opts.host,
@ -165,7 +201,9 @@ function ssllabs.get_endpoint_data(opts)
end
--- Retrieve known status codes.
-- @treturn table [StatusCode table](https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#statuscodes)
-- @treturn ?table|nil [StatusCode table](https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#statuscodes)
-- @treturn ?nil|number error status code
-- @treturn ?nil|string error status message
-- @usage local code = ssllabs.get_status_codes()
function ssllabs.get_status_codes()
return api_request('getStatusCodes')
@ -175,10 +213,10 @@ end
-- @treturn string This call returns the root certificates used for trust validation.
-- @usage local certs = ssllabs.get_root_certs_raw()
function ssllabs.get_root_certs_raw()
local resp = api_request('getRootCertsRaw')
return resp.text
return api_request('getRootCertsRaw')
end
if _TEST then
ssllabs._bool_to_parameter = bool_to_parameter
end

Loading…
Cancel
Save