You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/03/04 10:13:49 UTC

[GitHub] [apisix] bzp2010 commented on a change in pull request #6512: feat: support google reCAPTCHA

bzp2010 commented on a change in pull request #6512:
URL: https://github.com/apache/apisix/pull/6512#discussion_r819439267



##########
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:
       Why would you want to manage the api manually through your plugin? With all due respect, this does not match the design of APISIX.
   
   `Route` should be set up and plugins enabled for them first, rather than having your global plugins manage the routes.




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org