Dog-Lee commented on a change in pull request #6512:
URL: https://github.com/apache/apisix/pull/6512#discussion_r822261123
##########
File path: apisix/plugins/recaptcha.lua
##########
@@ -0,0 +1,122 @@
+local radix = require("resty.radixtree")
+local core = require("apisix.core")
+local http = require("resty.http")
+
+local schema = {
+ type = "object",
+ properties = {
+ recaptcha_secret_key = { type = "string" },
+ apis = {
+ type = "array",
+ items = {
+ type = "object",
+ properties = {
+ path = { type = "string" },
+ methods = { type = "array", items = { type = "string" },
minItems = 1 },
+ param_from = { type = "string", default = "header", enum =
{ "header", "query" } },
+ param_name = { type = "string", default = "captcha" },
+ }
+ },
+ minItems = 1
+ },
+ response = {
+ type = "object",
+ properties = {
+ content_type = { type = "string", default = "application/json;
charset=utf-8" },
+ status_code = { type = "number", default = 400 },
+ body = { type = "string", default = '{"message": "invalid
captcha"}' }
+ }
+ },
+
+ },
+ additionalProperties = false,
+ required = { "recaptcha_secret_key" },
+}
+
+local recaptcha_url = "https://www.recaptcha.net"
+
+local _M = {
+ version = 0.1,
+ priority = 700,
+ name = "recaptcha",
+ schema = schema,
+}
+
+function _M.check_schema(conf, schema_type)
+ return core.schema.check(schema, conf)
+end
+
+local function build_radixtree(apis)
+ local items = {}
+ for _, api in ipairs(apis) do
+ local item = {
+ paths = { api.path },
+ methods = api.methods,
+ metadata = api,
+ }
+ table.insert(items, item)
+ end
+ return radix.new(items)
+end
+
+local function find_api(request, apis)
+ local rx = build_radixtree(apis)
+ return rx:match(request.path, { method = request.method })
+end
Review comment:
@spacewander I just dig into lua-resty-expr document, and found that it
seems only support arg_xxx now(please correct me if I'm wrong). Usually, the
recaptcha API depends on the path rather than arg.
And yes, this is an anti-pattern. I have discussed this with @shuaijinchao
before. To match APISIX pattern, I can add a match_all(boolean, default true)
property to verify every request once the plugin is executed. Just like the
other plugins.
What do you think?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]