demo_co.lua
package.path = './src/?.lua;./src/?/init.lua;' .. package.path
local ssll = require('ssllabs')
local hosts = {
'edolas.world',
'blog.kokolor.es'
}
local checks = {}
local finished = {}
local function sleep(n)
os.execute('sleep ' .. tonumber(n))
end
local function check(opts)
table.insert(checks, coroutine.create(function()
local resp, err, msg = ssll.analyze(opts)
opts.startNew = nil
while true do
if err then return err, msg end
coroutine.yield(resp)
resp, err, msg = ssll.analyze(opts)
end
end))
end
local function run()
while true do
local noc = #checks
if noc == 0 then break end
for i = 1, noc do
local _, resp = coroutine.resume(checks[i])
if resp.status == 'READY' or resp.status == 'ERROR' then
finished[resp.host] = resp
table.remove(checks, i)
print(resp.host .. ' assessment finished!')
break
end
print(resp.host .. ' in progress...')
end
sleep(10)
end
end
for _, h in ipairs(hosts) do
check ({ host = h, publish = true, startNew = true })
end
run()
for k, v in pairs(finished) do
for _, e in ipairs(v.endpoints) do
print(k, e.ipAddress, e.grade)
end
end