Skip to content

Commit

Permalink
Merge pull request #508 from 3scale/nginx-resolver
Browse files Browse the repository at this point in the history
[nginx] define resolver directive in the config
  • Loading branch information
mikz authored Nov 28, 2017
2 parents 17522a5 + d83daa9 commit 0613e63
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- New policy chains system. This allows users to write custom policies to configure what Apicast can do on each of the Nginx phases [PR #450](https://github.com/3scale/apicast/pull/450)
- Resolver can resolve nginx upstreams [PR #478](https://github.com/3scale/apicast/pull/478)
- Add `resolver` directive in the nginx configuration [PR #508](https://github.com/3scale/apicast/pull/508)
- Calls 3scale backend with the 'no_body' option enabled. This reduces network traffic in cases where APIcast does not need to parse the response body [PR #483](https://github.com/3scale/apicast/pull/483)
- Methods to modify policy chains [PR #505](https://github.com/3scale/apicast/pull/505)
- Ability to load several environment configurations [PR #504](https://github.com/3scale/apicast/pull/504)
Expand Down
5 changes: 5 additions & 0 deletions gateway/conf/nginx.conf.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ http {

lua_package_path ";;{{prefix}}/?.lua;{{prefix}}/src/?.lua";

{% if nameservers %}
resolver {{ nameservers | join: " " }};
{% endif %}


{% for file in "http.d/*.conf" | filesystem %}
{% include file %}
{% endfor %}
Expand Down
24 changes: 24 additions & 0 deletions gateway/src/apicast/cli/environment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,32 @@ local assert = assert
local error = error
local print = print
local pairs = pairs
local ipairs = ipairs
local tostring = tostring
local insert = table.insert
local concat = table.concat
local re = require('ngx.re')

local function parse_nameservers()
local resolver = require('resty.resolver')
local nameservers = {}

for _,nameserver in ipairs(resolver.init_nameservers()) do
-- resty.resolver returns nameservers as tables with __tostring metamethod
-- unfortunately those objects can't be joined with table.concat
-- and have to be converted to strings first
insert(nameservers, tostring(nameserver))
end

-- return the table only if there are some nameservers
-- because it is way easier to check in liquid and `resolver` directive
-- has to contain at least one server, so we can skip it when there are none
if #nameservers > 0 then
return nameservers
end
end


local _M = {}
---
-- @field default_environment Default environment name.
Expand All @@ -26,9 +48,11 @@ _M.default_environment = 'production'

--- Default configuration.
-- @tfield ?string ca_bundle path to CA store file
-- @tfield ?{string,...} nameservers list of nameservers
-- @table environment.default_config default configuration
_M.default_config = {
ca_bundle = resty_env.value('SSL_CERT_FILE'),
nameservers = parse_nameservers(),
}

local mt = { __index = _M }
Expand Down
2 changes: 2 additions & 0 deletions gateway/src/resty/resolver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ function _M.init_nameservers(path)
ngx.log(ngx.INFO, 'adding ', search[i], ' as search domain')
insert(_M.search, search[i])
end

return nameservers
end

function _M.nameservers()
Expand Down

0 comments on commit 0613e63

Please sign in to comment.