started work on moving variables from .lua to nginx
This commit is contained in:
19
lua/api.lua
19
lua/api.lua
@@ -1,20 +1,19 @@
|
||||
local M = {}
|
||||
local api_list = {}
|
||||
local api_whitelist_ip = {%API_WHITELIST_IP%}
|
||||
local iputils = require "resty.iputils"
|
||||
local whitelist = iputils.parse_cidrs(api_whitelist_ip)
|
||||
local M = {}
|
||||
M.api_list = {}
|
||||
local iputils = require "resty.iputils"
|
||||
|
||||
api_list["^/ping$"] = function ()
|
||||
M.api_list["^/ping$"] = function ()
|
||||
return true
|
||||
end
|
||||
|
||||
api_list["^/reload$"] = function ()
|
||||
M.api_list["^/reload$"] = function ()
|
||||
return os.execute("/usr/sbin/nginx -s reload") == 0
|
||||
end
|
||||
|
||||
function M.is_api_call (api_uri)
|
||||
function M.is_api_call (api_uri, api_whitelist_ip)
|
||||
local whitelist = iputils.parse_cidrs(api_whitelist_ip)
|
||||
if iputils.ip_in_cidrs(ngx.var.remote_addr, whitelist) and ngx.var.request_uri:sub(1, #api_uri) .. "/" == api_uri .. "/" then
|
||||
for uri, code in pairs(api_list) do
|
||||
for uri, code in pairs(M.api_list) do
|
||||
if string.match(ngx.var.request_uri:sub(#api_uri + 1), uri) then
|
||||
return true
|
||||
end
|
||||
@@ -24,7 +23,7 @@ function M.is_api_call (api_uri)
|
||||
end
|
||||
|
||||
function M.do_api_call (api_uri)
|
||||
for uri, code in pairs(api_list) do
|
||||
for uri, code in pairs(M.api_list) do
|
||||
if string.match(ngx.var.request_uri:sub(#api_uri + 1), uri) then
|
||||
return code()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user