
Actually read from the file Logs probably shouldn't assume knowledge of implementation detail Typos Added integration test, and dynamic update config refactor Don't force the 8k default Minimal test case to make the configuration/backends request body write to temp file Leverage new safe config updating methods, and use 2 replicas instead of 4 Small refactor Better integration test, addresses other feedback Update bindata
66 lines
1.6 KiB
Lua
66 lines
1.6 KiB
Lua
-- this is the Lua representation of Configuration struct in internal/ingress/types.go
|
|
local configuration_data = ngx.shared.configuration_data
|
|
|
|
local _M = {}
|
|
|
|
function _M.get_backends_data()
|
|
return configuration_data:get("backends")
|
|
end
|
|
|
|
local function fetch_request_body()
|
|
ngx.req.read_body()
|
|
local body = ngx.req.get_body_data()
|
|
|
|
if not body then
|
|
-- request body might've been written to tmp file if body > client_body_buffer_size
|
|
local file_name = ngx.req.get_body_file()
|
|
local file = io.open(file_name, "rb")
|
|
|
|
if not file then
|
|
return nil
|
|
end
|
|
|
|
body = file:read("*all")
|
|
file:close()
|
|
end
|
|
|
|
return body
|
|
end
|
|
|
|
function _M.call()
|
|
if ngx.var.request_method ~= "POST" and ngx.var.request_method ~= "GET" then
|
|
ngx.status = ngx.HTTP_BAD_REQUEST
|
|
ngx.print("Only POST and GET requests are allowed!")
|
|
return
|
|
end
|
|
|
|
if ngx.var.request_uri ~= "/configuration/backends" then
|
|
ngx.status = ngx.HTTP_NOT_FOUND
|
|
ngx.print("Not found!")
|
|
return
|
|
end
|
|
|
|
if ngx.var.request_method == "GET" then
|
|
ngx.status = ngx.HTTP_OK
|
|
ngx.print(_M.get_backends_data())
|
|
return
|
|
end
|
|
|
|
local backends = fetch_request_body()
|
|
if not backends then
|
|
ngx.log(ngx.ERR, "dynamic-configuration: unable to read valid request body")
|
|
ngx.status = ngx.HTTP_BAD_REQUEST
|
|
return
|
|
end
|
|
|
|
local success, err = configuration_data:set("backends", backends)
|
|
if not success then
|
|
ngx.log(ngx.ERR, "dynamic-configuration: error updating configuration: " .. tostring(err))
|
|
ngx.status = ngx.HTTP_BAD_REQUEST
|
|
return
|
|
end
|
|
|
|
ngx.status = ngx.HTTP_CREATED
|
|
end
|
|
|
|
return _M
|