Skip to content

Commit

Permalink
break resolv.conf in lines
Browse files Browse the repository at this point in the history
  • Loading branch information
maneta committed Feb 27, 2018
1 parent 985a24a commit 999317e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
24 changes: 15 additions & 9 deletions gateway/src/resty/resolver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,6 @@ function _M.parse_nameservers(path)

local search = { }
local nameservers = { search = search }
local domains = match(resolv_conf, 'search%s+([^\n]+)')

ngx.log(ngx.DEBUG, 'search ', domains)
for domain in gmatch(domains or '', '([^%s]+)') do
ngx.log(ngx.DEBUG, 'search domain: ', domain)
insert(search, domain)
end

local resolver
resolver, err = _M.parse_resolver(resty_env.value('RESOLVER'))
Expand All @@ -131,10 +124,23 @@ function _M.parse_nameservers(path)
-- see https://github.com/3scale/apicast/issues/321 for more details
insert(nameservers, resolver)
end

for _,line in ipairs(re.split(resolv_conf, "\n+")) do

local domains = match(line, '^search%s+([^\n]+)')

if domains then
ngx.log(ngx.DEBUG, 'search ', domains)

for domain in gmatch(domains or '', '([^%s]+)') do
ngx.log(ngx.DEBUG, 'search domain: ', domain)
insert(search, domain)
end
end

for server in gmatch(resolv_conf, 'nameserver%s+([^%s]+)') do
local server = match(line, '^nameserver%s+([^%s]+)')
-- TODO: implement port matching based on https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=549190
if server ~= resolver then
if server and server ~= resolver then
insert(nameservers, nameserver.new(server))
end
end
Expand Down
8 changes: 8 additions & 0 deletions spec/resty/resolver_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ describe('resty.resolver', function()
before_each(function()
tmpname = io.tmpfile()

tmpname:write('# nameserver updated in comentary\n')
tmpname:write('#nameserver updated in comentary\n')
tmpname:write('#comentary nameserver 1.2.3.4\n')
tmpname:write('#comentary nameserver\n')
tmpname:write('# search updated.example.com in comentary\n')
tmpname:write('#search updated in comentary\n')
tmpname:write('#search nameserver 1.2.3.4\n')
tmpname:write('#search nameserver\n')
tmpname:write('search localdomain.example.com local\n')
tmpname:write('nameserver 127.0.0.2\n')
tmpname:write('nameserver 127.0.0.1\n')
Expand Down

0 comments on commit 999317e

Please sign in to comment.