-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
feat(conf) add support to configure nginx directives via kong.conf #3530
Changes from all commits
4a42c8f
392e203
659bbb6
2317d42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
local pl_utils = require "pl.utils" | ||
local log = require "kong.cmd.utils.log" | ||
local fmt = string.format | ||
|
||
|
||
local cmd = [[ printenv ]] | ||
|
||
|
||
-- returns table and err | ||
local function read_all() | ||
log.debug("reading environment variables: %s", cmd) | ||
local vars = {} | ||
local success, ret_code, stdout, stderr = pl_utils.executeex(cmd) | ||
if not success or ret_code ~= 0 then | ||
return nil, fmt("could not read environment variables (exit code: %d): %s", | ||
ret_code, stderr) | ||
end | ||
|
||
for line in stdout:gmatch("[^\r\n]+") do | ||
local i = string.find(line, "=") -- match first = | ||
if i then | ||
local k = string.sub(line, 1, i - 1) | ||
local v = string.sub(line, i + 1) | ||
if k and v then | ||
vars[k] = v | ||
end | ||
end | ||
end | ||
return vars | ||
end | ||
|
||
|
||
return { | ||
read_all = read_all, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
local helpers = require "spec.helpers" | ||
|
||
|
||
describe("Custom NGINX directives", function() | ||
local proxy_client | ||
local bp | ||
|
||
local function start(config) | ||
return function() | ||
bp.routes:insert { | ||
hosts = { "headers-inspect.com" }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, a super minor thing but which I think we should start paying attention in our tests (perhaps worth an addition to the style guide even?) — I suggest we stop using "valid-looking" URLs in tests, even if we're not hitting them (we've had in the past tests that used an innocent-looking URL which ended up pointing to a porn site!) — we can use instead There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for sharing pointing this out! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1
I've also seen cases of test/example code in public documentation using "domain.com", which at one point hosted malware; customers who blindly copy-pasted were in for a nasty surprise :p IANA has reserved Just my $0.02. |
||
} | ||
|
||
config = config or {} | ||
config.nginx_conf = "spec/fixtures/custom_nginx.template" | ||
|
||
assert(helpers.start_kong(config)) | ||
end | ||
end | ||
|
||
setup(function() | ||
bp = helpers.get_db_utils() | ||
end) | ||
|
||
before_each(function() | ||
proxy_client = helpers.proxy_client() | ||
end) | ||
|
||
after_each(function() | ||
if proxy_client then | ||
proxy_client:close() | ||
end | ||
end) | ||
|
||
describe("with config value 'nginx_proxy_add_header=foo-header bar-value'", function() | ||
|
||
setup(start{ | ||
["nginx_proxy_add_header"] = "foo-header bar-value" | ||
}) | ||
|
||
teardown(helpers.stop_kong) | ||
|
||
it("header 'foo-header' should be inserted", function() | ||
local res = assert(proxy_client:send { | ||
method = "GET", | ||
path = "/get", | ||
headers = { | ||
host = "headers-inspect.com", | ||
} | ||
}) | ||
|
||
assert.res_status(200, res) | ||
assert.equal("bar-value", res.headers["foo-header"]) | ||
end) | ||
|
||
end) | ||
end) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe there is no need for this extra variable anymore, it is used only once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is used for the debug log as well.