Skip to content

Commit

Permalink
lua-resty-auto-ssl-storage-adapter-consul (#25): debug helpers, more …
Browse files Browse the repository at this point in the history
…centralzed this time (not really need in the end product, but I need to inspect lua things without killing openresty
  • Loading branch information
fititnt committed Nov 28, 2019
1 parent 8175bb2 commit 2c78474
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
6 changes: 5 additions & 1 deletion files/resty/auto-ssl/storage_adapters/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
doc
doc

DataDumper.lua
# ansible -m copy -a "src=./DataDumper.lua dest=/usr/local/share/lua/5.1/resty/auto-ssl/storage_adapters/DataDumper.lua" aguia-pescadora-delta.etica.ai,aguia-pescadora-echo.etica.ai,aguia-pescadora-foxtrot.etica.ai
# ansible -m copy -a "src=./debughelpers.lua dest=/usr/local/share/lua/5.1/resty/auto-ssl/storage_adapters/debughelpers.lua" aguia-pescadora-delta.etica.ai,aguia-pescadora-echo.etica.ai,aguia-pescadora-foxtrot.etica.ai
20 changes: 17 additions & 3 deletions files/resty/auto-ssl/storage_adapters/consul.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@
local consul = require('resty.consul')
-- local consul = require('resty.auto-ssl.storage_adapters.consul')

-- @TODO: remove this line after finished debugging the consul.lua
-- http://lua-users.org/wiki/DataDumper
-- local DataDumper = require("DataDumper")
require 'DataDumper'
require 'debughelpers'

local function dump(value, varname)
--- print(DataDumper(...), "\n---")
-- ngx.log(ngx.ERR, DataDumper(value, varname, false, 2))
ngx.log(ngx.ERR, dumpvar(value, varname, false, 2))
end

-- @module storage_adapter_consul
local _M = {}

Expand Down Expand Up @@ -172,9 +184,11 @@ function _M.get(self, key)
local res_read_body, res_err = res:read_body()
-- ngx.log(ngx.ERR, '_M.get ', type(res_read_body), ' ', type(res_err))
-- ngx.log(ngx.ERR, '_M.get ', res_read_body, ' ', res_err)
ngx.log(ngx.ERR, '_M.get ', type(res), ' ', type(res_read_body), ' ', res.body)
local plpretty = require "pl.pretty"
plpretty.dump(res)
-- dump('oioioi', res)
dump(res)
-- dump(res, '_M.get res')
-- ngx.log(ngx.ERR, '_M.get: [type(res): ', type(res), '] ', type(res_read_body), ' ', res.body)
--- local plpretty = require "pl.pretty"
-- ngx.log(ngx.ERR, '_M.get', cjson.encode(res_err), cjson.encode(res_err))
-- ngx.log(ngx.ERR, cjson.encode(res))

Expand Down
33 changes: 33 additions & 0 deletions files/resty/auto-ssl/storage_adapters/debughelpers.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
-- https://pastebin.com/A7JScXWk
function dumpvar(data)
-- cache of tables already printed, to avoid infinite recursive loops
local tablecache = {}
local buffer = ""
local padder = " "

local function _dumpvar(d, depth)
local t = type(d)
local str = tostring(d)
if (t == "table") then
if (tablecache[str]) then
-- table already dumped before, so we dont
-- dump it again, just mention it
buffer = buffer.."<"..str..">\n"
else
tablecache[str] = (tablecache[str] or 0) + 1
buffer = buffer.."("..str..") {\n"
for k, v in pairs(d) do
buffer = buffer..string.rep(padder, depth+1).."["..k.."] => "
_dumpvar(v, depth+1)
end
buffer = buffer..string.rep(padder, depth).."}\n"
end
elseif (t == "number") then
buffer = buffer.."("..t..") "..str.."\n"
else
buffer = buffer.."("..t..") \""..str.."\"\n"
end
end
_dumpvar(data, 0)
return buffer
end
2 changes: 1 addition & 1 deletion templates/openresty/nginx/conf/nginx.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ http {
-- so this must be configured.
auto_ssl:set("allow_domain", function(domain)

ngx.log(ngx.WARN, "allow_domain will try domain:", domain)
ngx.log(ngx.WARN, "allow_domain started. Will evaluate if should or not obtain certificates to ", domain)

-- Fail first if domain seems to be an IP.
-- @see https://github.com/GUI/lua-resty-auto-ssl/issues/26#issuecomment-366919522
Expand Down

0 comments on commit 2c78474

Please sign in to comment.