Added support for customizing chaos container for nodes

This commit is contained in:
Eugenio Marzo
2021-07-04 17:20:26 +02:00
parent a83193cb84
commit fda9d47b4f
4 changed files with 171 additions and 98 deletions

View File

@@ -17,24 +17,20 @@ ngx.header['Access-Control-Allow-Methods'] = 'GET, POST, OPTIONS'
ngx.header['Access-Control-Allow-Headers'] = 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'
ngx.header['Access-Control-Expose-Headers'] = 'Content-Length,Content-Range'
if ngx.var.request_method == "GET" and action == 'default' then
ngx.say(config['default_chaos_container'])
elseif ngx.var.request_method == "GET" and action == 'chaos_container' then
if ngx.var.request_method == "GET" and action == 'container_definition' then
ngx.log(ngx.ERR, "Received request for getting chaos container definition")
local res, err = red:get("chaos_container")
if res == ngx.null then
ngx.say('A custom chaos container has not yet been configured')
ngx.log(ngx.ERR, "There is no chaos_container key set in Redis. Taking default chaos container definition")
ngx.say(config['default_chaos_container'])
else
ngx.log(ngx.ERR, "There is chaos_container key set in Redis. Taking custom chaos container definition")
ngx.say(res)
end
elseif ngx.var.request_method == "POST" and action == 'set' then
ngx.say('New chaos container has been configured')
if arg['chaos_container'] == nil then
ngx.say("Please set the parameter 'chaos_container'")
else
red:set("chaos_container", arg['chaos_container'])
ngx.say("chaos_container has been configured in Redis")
end
local body_data = ngx.req.get_body_data()
ngx.log(ngx.ERR, "Received new yaml definition for chaos container: " .. body_data)
red:set("chaos_container", body_data)
ngx.say("New chaos container definition has been configured in Redis")
return ngx.exit(ngx.status)
end