leslie-tsang commented on a change in pull request #6512: URL: https://github.com/apache/apisix/pull/6512#discussion_r830708007
########## File path: apisix/plugins/recaptcha.lua ########## @@ -0,0 +1,101 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one or more +-- contributor license agreements. See the NOTICE file distributed with +-- this work for additional information regarding copyright ownership. +-- The ASF licenses this file to You under the Apache License, Version 2.0 +-- (the "License"); you may not use this file except in compliance with +-- the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +local core = require("apisix.core") +local http = require("resty.http") +local ngx = ngx + +local schema = { + type = "object", + properties = { + secret_key = { type = "string" }, + parameter_source = { type = "string", default = "header", enum = { "header", "query" } }, + parameter_name = { type = "string", default = "captcha" }, + ssl_verify = { type = "boolean", default = true }, + 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"}' } + } + }, + }, + required = { "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) + return core.schema.check(schema, conf) +end + +local function retrieve_captcha(ctx, conf) Review comment: ```suggestion local function retrieve_captcha(ctx, conf) ``` Please follow the [CODE_STYLE.md](https://github.com/apache/apisix/blob/master/CODE_STYLE.md#blank-line). > The functions needs to be separated by two blank lines: ########## File path: apisix/plugins/recaptcha.lua ########## @@ -0,0 +1,101 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one or more +-- contributor license agreements. See the NOTICE file distributed with +-- this work for additional information regarding copyright ownership. +-- The ASF licenses this file to You under the Apache License, Version 2.0 +-- (the "License"); you may not use this file except in compliance with +-- the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +local core = require("apisix.core") +local http = require("resty.http") +local ngx = ngx + +local schema = { + type = "object", + properties = { + secret_key = { type = "string" }, + parameter_source = { type = "string", default = "header", enum = { "header", "query" } }, + parameter_name = { type = "string", default = "captcha" }, + ssl_verify = { type = "boolean", default = true }, + 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"}' } + } + }, + }, + required = { "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) + return core.schema.check(schema, conf) +end + +local function retrieve_captcha(ctx, conf) + if conf.parameter_source == "header" then + return core.request.header(ctx, conf.parameter_name) + end + + if conf.parameter_source == "query" then + local uri_args = core.request.get_uri_args(ctx) or {} + return uri_args[conf.parameter_name] + end +end + +function _M.access(conf, ctx) Review comment: ```suggestion function _M.access(conf, ctx) ``` Please follow the [CODE_STYLE.md](https://github.com/apache/apisix/blob/master/CODE_STYLE.md#blank-line). > The functions needs to be separated by two blank lines: ########## File path: docs/zh/latest/plugins/recaptcha.md ########## @@ -0,0 +1,112 @@ +--- +title: recaptcha +--- + +<!-- +# + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +--> + +## 描述 + +通过向 Google reCAPTCHA 服务校验客户端传递的验证码来限制对上游服务的访问。插件支持自定义无效校验码的响应体。 + +> 注意,此插件只支持 Google reCAPTCHA v2 版本。 + +## 属性 + +| Name | Type | Requirement | Default | Valid | Description | +| --------- | ------------- | ----------- | ---------- | ------------------------------------------------------------------------ |-------------------------------------| +| secret_key | string | 必须 | | | Google reCAPTCHA v2 的 secret key | +| parameter_source | string | 可选 | header | | 验证码参数的来源枚举值。当前仅支持 `header`, `query` | +| parameter_name | string | 可选 | captcha | | 验证码参数的名称 | +| response | object | 可选 | content_type = `application/json; charset=utf-8`<br />status_code = `400`<br />body = `{"message":"invalid captcha"}` | | 无效验证码的 HTTP 响应体 | Review comment: Why `<br>` here ? -- 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]
