diff --git a/CHANGELOG.md b/CHANGELOG.md index 53935a792..6228e10db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/gateway/conf/nginx.conf.liquid b/gateway/conf/nginx.conf.liquid index c684367ac..6666cfa2b 100644 --- a/gateway/conf/nginx.conf.liquid +++ b/gateway/conf/nginx.conf.liquid @@ -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 %} diff --git a/gateway/src/apicast/cli/environment.lua b/gateway/src/apicast/cli/environment.lua index 5626fb53f..136ff673b 100644 --- a/gateway/src/apicast/cli/environment.lua +++ b/gateway/src/apicast/cli/environment.lua @@ -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. @@ -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 } diff --git a/gateway/src/resty/resolver.lua b/gateway/src/resty/resolver.lua index 9da607d09..4ff225a49 100644 --- a/gateway/src/resty/resolver.lua +++ b/gateway/src/resty/resolver.lua @@ -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()