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 2021/02/20 09:21:53 UTC

[GitHub] [apisix] membphis commented on a change in pull request #3567: feat: add plugin config

membphis commented on a change in pull request #3567:
URL: https://github.com/apache/apisix/pull/3567#discussion_r579627401



##########
File path: apisix/cli/etcd.lua
##########
@@ -251,7 +251,7 @@ function _M.init(env, args)
         for _, dir_name in ipairs({"/routes", "/upstreams", "/services",
                                    "/plugins", "/consumers", "/node_status",
                                    "/ssl", "/global_rules", "/stream_routes",
-                                   "/proto", "/plugin_metadata"}) do
+                                   "/proto", "/plugin_metadata", "/plugin_configs"}) do

Review comment:
       Is it possible to move this logic to the `init_by_lua phase` in the future? 

##########
File path: apisix/plugin_config.lua
##########
@@ -0,0 +1,69 @@
+--
+-- 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 plugin_checker = require("apisix.plugin").plugin_checker
+local pairs = pairs
+local error = error
+
+
+local plugin_configs
+
+
+local _M = {
+}
+
+
+function _M.init_worker()
+    local err
+    plugin_configs, err = core.config.new("/plugin_configs", {
+        automatic = true,
+        checker = plugin_checker,
+    })
+    if not plugin_configs then
+        error("failed to sync /plugin_configs: " .. err)
+    end
+end
+
+
+function _M.get(id)
+    return plugin_configs:get(id)
+end
+
+
+function _M.merge(route_conf, plugin_config)
+    if route_conf.prev_plugin_config_ver ~= plugin_config.modifiedIndex then

Review comment:
       another code style:
   
   ```lua
   if route_conf.prev_plugin_config_ver == plugin_config.modifiedIndex then
       return route_conf
   end
   
   ...
   ```

##########
File path: apisix/init.lua
##########
@@ -381,6 +383,18 @@ function _M.http_access_phase()
                   core.json.delay_encode(api_ctx.matched_route, true))
 
     local enable_websocket = route.value.enable_websocket
+
+    if route.value.plugin_config_id then
+        local pc = plugin_config.get(route.value.plugin_config_id)

Review comment:
       `pc` is not a good name

##########
File path: apisix/schema_def.lua
##########
@@ -746,6 +749,20 @@ _M.plugins = {
 }
 
 
+_M.plugin_config = {
+    type = "object",
+    properties = {
+        id = id_schema,
+        desc = {type = "string", maxLength = 256},

Review comment:
       all of the `desc` should be the same, declare it as a variable and just quote it




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

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