Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(conf) overcome penlight's 'list_delim' setting #1569

Merged
merged 1 commit into from
Aug 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions kong/conf_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ local function check_and_infer(conf)
local v_schema = CONF_INFERENCES[k] or {}
local typ = v_schema.typ

if type(value) == "string" then
value = string.gsub(value, "#.-$", "") -- remove trailing comment if any
value = pl_stringx.strip(value)
end

-- transform {boolean} values ("on"/"off" aliasing to true/false)
-- transform {ngx_boolean} values ("on"/"off" aliasing to on/off)
-- transform {explicit string} values (number values converted to strings)
Expand All @@ -135,13 +140,9 @@ local function check_and_infer(conf)
value = setmetatable(pl_stringx.split(value, ","), nil) -- remove List mt
end

if type(value) == "string" then
-- default type is string, and an empty if unset
value = value ~= "" and tostring(value) or nil
if value then
value = string.gsub(value, "#.-$", "")
value = pl_stringx.strip(value)
end
if value == "" then
-- unset values are removed
value = nil
end

typ = typ or "string"
Expand Down Expand Up @@ -279,7 +280,10 @@ local function load(path, custom_conf)

log.verbose("reading config file at %s", path)
local s = pl_stringio.open(f)
from_file_conf, err = pl_config.read(s)
from_file_conf, err = pl_config.read(s, {
smart = false,
list_delim = "_blank_" -- mandatory but we want to ignore it
})
s:close()
if not from_file_conf then return nil, err end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/01-unit/02-conf_loader_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ describe("Configuration loader", function()
assert.equal("cassandra", conf.database)
assert.equal("debug", conf.log_level)
end)
it("overcomes penlight's list_delim option", function()
local conf = assert(conf_loader("spec/fixtures/to-strip.conf"))
assert.False(conf.dnsmasq)
assert.True(conf.plugins.foobar)
assert.True(conf.plugins["hello-world"])
end)

describe("inferences", function()
it("infer booleans (on/off/true/false strings)", function()
Expand Down
14 changes: 14 additions & 0 deletions spec/fixtures/to-strip.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
database = cassandra # strip me
log_level = debug # strip this
# comment too
dnsmasq = off # Toggles if Kong should start/stop dnsmasq,
# which can be used as the Nginx DNS resolver.
# Using dnsmasq allows Nginx to resolve
# domains defined in /etc/hosts.
# dnsmasq must be installed and available in
# your $PATH.
dns_resolver = 8.8.8.8

custom_plugins = foobar,hello-world # Comma-separated list of additional plugins
# this node should load.
# Use this property to load custom plugins
# that are not bundled with Kong.
# Plugins will be loaded from the
# `kong.plugins.{name}.*` namespace.