swarm/k8s - less storage, more API

This commit is contained in:
florian
2021-09-05 00:36:15 +02:00
parent 062fa3e78a
commit ca81535bb3
18 changed files with 133 additions and 47 deletions

View File

@@ -2,6 +2,7 @@ local M = {}
local api_list = {}
local iputils = require "resty.iputils"
local upload = require "resty.upload"
local logger = require "logger"
api_list["^/ping$"] = function ()
return true
@@ -27,6 +28,10 @@ api_list["^/stop$"] = function ()
return os.execute("/usr/sbin/nginx -s quit") == 0
end
api_list["^/stop%-temp$"] = function ()
return os.execute("/usr/sbin/nginx -c /tmp/nginx-temp.conf -s stop") == 0
end
api_list["^/conf$"] = function ()
if not M.save_file("/tmp/conf.tar.gz") then
return false
@@ -69,7 +74,7 @@ api_list["^/modsec$"] = function ()
return M.extract_file("/tmp/modsec.tar.gz", "/modsec-confs/")
end
api_list["^/modsec-crs$"] = function ()
api_list["^/modsec%-crs$"] = function ()
if not M.save_file("/tmp/modsec-crs.tar.gz") then
return false
end
@@ -79,6 +84,7 @@ end
function M.save_file (name)
local form, err = upload:new(4096)
if not form then
logger.log(ngx.ERR, "API", err)
return false
end
form:set_timeout(1000)
@@ -87,6 +93,7 @@ function M.save_file (name)
local typ, res, err = form:read()
if not typ then
file:close()
logger.log(ngx.ERR, "API", "not typ")
return false
end
if typ == "eof" then
@@ -102,7 +109,7 @@ function M.save_file (name)
end
function M.extract_file(archive, destination)
return os.execute("tar xzf " .. archive .. " -C " .. destination)
return os.execute("tar xzf " .. archive .. " -C " .. destination) == 0
end
function M.is_api_call (api_uri, api_whitelist_ip)