tzssangglass commented on code in PR #7771:
URL: https://github.com/apache/apisix/pull/7771#discussion_r956840736


##########
apisix/plugins/limit-count/init.lua:
##########
@@ -0,0 +1,310 @@
+--
+-- 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 limit_local_new = require("resty.limit.count").new
+local core = require("apisix.core")
+local apisix_plugin = require("apisix.plugin")
+local tab_insert = table.insert
+local ipairs = ipairs
+local pairs = pairs
+
+
+local plugin_name = "limit-count"
+local limit_redis_cluster_new
+local limit_redis_new
+do
+    local redis_src = "apisix.plugins.limit-count.limit-count-redis"
+    limit_redis_new = require(redis_src).new
+
+    local cluster_src = "apisix.plugins.limit-count.limit-count-redis-cluster"
+    limit_redis_cluster_new = require(cluster_src).new
+end
+local lrucache = core.lrucache.new({
+    type = 'plugin', serial_creating = true,
+})
+local group_conf_lru = core.lrucache.new({
+    type = 'plugin',
+})
+
+
+local policy_to_additional_properties = {
+    redis = {
+        properties = {
+            redis_host = {
+                type = "string", minLength = 2
+            },
+            redis_port = {
+                type = "integer", minimum = 1, default = 6379,
+            },
+            redis_password = {
+                type = "string", minLength = 0,
+            },
+            redis_database = {
+                type = "integer", minimum = 0, default = 0,
+            },
+            redis_timeout = {
+                type = "integer", minimum = 1, default = 1000,
+            },
+        },
+        required = {"redis_host"},
+    },
+    ["redis-cluster"] = {
+        properties = {
+            redis_cluster_nodes = {
+                type = "array",
+                minItems = 2,
+                items = {
+                    type = "string", minLength = 2, maxLength = 100
+                },
+            },
+            redis_password = {
+                type = "string", minLength = 0,
+            },
+            redis_timeout = {
+                type = "integer", minimum = 1, default = 1000,
+            },
+            redis_cluster_name = {
+                type = "string",
+            },
+        },
+        required = {"redis_cluster_nodes", "redis_cluster_name"},
+    },
+}
+local schema = {
+    type = "object",
+    properties = {
+        count = {type = "integer", exclusiveMinimum = 0},
+        time_window = {type = "integer",  exclusiveMinimum = 0},
+        group = {type = "string"},
+        key = {type = "string", default = "remote_addr"},
+        key_type = {type = "string",
+            enum = {"var", "var_combination", "constant"},
+            default = "var",
+        },
+        rejected_code = {
+            type = "integer", minimum = 200, maximum = 599, default = 503
+        },
+        rejected_msg = {
+            type = "string", minLength = 1
+        },
+        policy = {
+            type = "string",
+            enum = {"local", "redis", "redis-cluster"},
+            default = "local",
+        },
+        allow_degradation = {type = "boolean", default = false},
+        show_limit_quota_header = {type = "boolean", default = true}
+    },
+    required = {"count", "time_window"},
+    ["if"] = {
+        properties = {
+            policy = {
+                enum = {"redis"},
+            },
+        },
+    },
+    ["then"] = policy_to_additional_properties.redis,
+    ["else"] = {
+        ["if"] = {
+            properties = {
+                policy = {
+                    enum = {"redis-cluster"},
+                },
+            },
+        },
+        ["then"] = policy_to_additional_properties["redis-cluster"],
+    }
+}
+
+local schema_copy = core.table.deepcopy(schema)
+
+local _M = {
+    schema = schema
+}
+
+
+local function group_conf(conf)
+    return conf
+end
+
+
+function _M.check_schema(conf)
+    local ok, err = core.schema.check(schema, conf)
+    if not ok then
+        return false, err
+    end
+
+    if conf.group then
+        -- means that call by some plugin not support
+        if conf._vid then

Review Comment:
   ref: https://github.com/apache/apisix/pull/7771#discussion_r955692338



-- 
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]

Reply via email to