AlinsRan commented on code in PR #13347:
URL: https://github.com/apache/apisix/pull/13347#discussion_r3230863408


##########
apisix/plugins/data-mask.lua:
##########
@@ -0,0 +1,265 @@
+--
+-- 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 ngx       = ngx
+local ipairs    = ipairs
+local next      = next
+local type      = type
+local re_sub    = ngx.re.sub
+local core      = require("apisix.core")
+local jp        = require("jsonpath")
+
+local plugin_name = "data-mask"
+
+local schema = {
+    type = "object",
+    properties = {
+        request = {
+            type = "array",
+            items = {
+                type = "object",
+                properties = {
+                    type = {type = "string", enum = {"query", "header", 
"body"}},
+                    body_format = {type = "string", enum = {"json", 
"urlencoded"}},
+                    name = {type = "string"},
+                    action = {type = "string", enum = {"regex", "replace", 
"remove"}},
+                    regex = {type = "string"},
+                    value = {type = "string"},
+                },
+                required = {"type", "name", "action"},
+                allOf = {
+                    {
+                        ["if"] = {
+                            properties = {type = {const = "body"}},
+                        },
+                        ["then"] = {
+                            required = {"body_format"},
+                        },
+                    },
+                    {
+                        ["if"] = {
+                            properties = {action = {const = "regex"}},
+                        },
+                        ["then"] = {
+                            required = {"regex", "value"},
+                        },
+                    },
+                    {
+                        ["if"] = {
+                            properties = {action = {const = "replace"}},
+                        },
+                        ["then"] = {
+                            required = {"value"},
+                        },
+                    },
+                },
+            },
+        },
+        max_body_size = {
+            type = "integer",
+            exclusiveMinimum = 0,
+            default = 1024 * 1024,
+        },
+        max_req_post_args = {
+            type = "integer",
+            default = 100,
+            minimum = 0,
+        }
+    },
+}
+
+
+local _M = {
+    version = 0.1,
+    priority = 1500,
+    name = plugin_name,
+    schema = schema,
+}
+
+
+function _M.check_schema(conf)
+    local ok, err = core.schema.check(schema, conf)
+    if not ok then
+         return false, err
+    end
+    return true
+end
+
+
+local function regex_replace(origin, regex, new)
+    local res, _, err = re_sub(origin, regex, new, "jo")
+    if not res then
+        core.log.error("failed to replace (" .. origin .. ") by regex (".. 
regex ..
+                            ") with new value (" .. new .. "): ", err)
+    end
+    return res

Review Comment:
   Fixed in 66e2cab8: `regex_replace()` now only logs the regex error message 
without including the original value or replacement string.



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