Skip to content

Commit

Permalink
Add API endpoint for Coraza connectivity check
Browse files Browse the repository at this point in the history
  • Loading branch information
TheophileDiot committed Feb 6, 2024
1 parent b5d54d5 commit 3e48e99
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions coraza/coraza.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ local coraza = class("coraza", plugin)
local ngx = ngx
local ngx_req = ngx.req
local ERR = ngx.ERR
local HTTP_INTERNAL_SERVER_ERROR = ngx.HTTP_INTERNAL_SERVER_ERROR
local HTTP_OK = ngx.HTTP_OK
local http_new = http.new
local has_variable = utils.has_variable
local get_deny_status = utils.get_deny_status
Expand Down Expand Up @@ -199,4 +201,29 @@ function coraza:is_needed()
return is_needed
end

function coraza:api()
if self.ctx.bw.uri == "/coraza/ping" and self.ctx.bw.request_method == "POST" then
-- Check coraza connection
local check, err = has_variable("USE_CORAZA", "yes")
if check == nil then
return self:ret(true, "error while checking variable USE_CORAZA (" .. err .. ")")
end
if not check then
return self:ret(true, "Coraza plugin not enabled")
end

-- Send ping request
local ok, data = self:ping()
if not ok then
return self:ret(
true,
"error while sending ping request to " .. self.variables["CORAZA_API"] .. " : " .. data,
HTTP_INTERNAL_SERVER_ERROR
)
end
return self:ret(true, "ping request is successful", HTTP_OK)
end
return self:ret(false, "success")
end

return coraza

0 comments on commit 3e48e99

Please sign in to comment.