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 2020/11/17 05:12:52 UTC

[GitHub] [apisix] spacewander opened a new pull request #2772: fix(etcd): avoid getting with prefix

spacewander opened a new pull request #2772:
URL: https://github.com/apache/apisix/pull/2772


   Fix #2771.
   
   ### What this PR does / why we need it:
   <!--- Why is this change required? What problem does it solve? -->
   <!--- If it fixes an open issue, please link to the issue here. -->
   
   ### Pre-submission checklist:
   
   * [ ] Did you explain what problem does this PR solve? Or what new features have been added?
   * [x] Have you added corresponding test cases?
   * [ ] Have you modified the corresponding document?
   * [x] Is this PR backward compatible?
   


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



[GitHub] [apisix] spacewander commented on a change in pull request #2772: fix(etcd): avoid getting with prefix

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #2772:
URL: https://github.com/apache/apisix/pull/2772#discussion_r525030453



##########
File path: apisix/core/etcd.lua
##########
@@ -92,17 +94,28 @@ function _M.get_format(res, realkey)
     if not res.body.kvs then
         return not_found(res)
     end
+
     res.body.action = "get"
 
-    -- In etcd v2, the direct key asked for is `node`, others which under this dir are `nodes`
-    -- While in v3, this structure is flatten and all keys related the key asked for are `kvs`
-    res.body.node = kvs_to_node(res.body.kvs[1])
-    if not res.body.kvs[1].value then
-        -- remove last "/" when necesary
-        if string.sub(res.body.node.key, -1, -1) == "/" then
-            res.body.node.key = string.sub(res.body.node.key, 1, #res.body.node.key-1)
+    if not is_dir then
+        local key = res.body.kvs[1].key
+        if key ~= real_key then
+            return not_found(res)
+        end
+
+        res.body.node = kvs_to_node(res.body.kvs[1])
+
+    else
+        -- In etcd v2, the direct key asked for is `node`, others which under this dir are `nodes`
+        -- While in v3, this structure is flatten and all keys related the key asked for are `kvs`
+        res.body.node = kvs_to_node(res.body.kvs[1])
+        if not res.body.kvs[1].value then
+            -- remove last "/" when necesary
+            if string.sub(res.body.node.key, -1, -1) == "/" then

Review comment:
       @tokers Updated




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



[GitHub] [apisix] tokers commented on a change in pull request #2772: fix(etcd): avoid getting with prefix

Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #2772:
URL: https://github.com/apache/apisix/pull/2772#discussion_r525005827



##########
File path: apisix/core/etcd.lua
##########
@@ -92,17 +94,28 @@ function _M.get_format(res, realkey)
     if not res.body.kvs then
         return not_found(res)
     end
+
     res.body.action = "get"
 
-    -- In etcd v2, the direct key asked for is `node`, others which under this dir are `nodes`
-    -- While in v3, this structure is flatten and all keys related the key asked for are `kvs`
-    res.body.node = kvs_to_node(res.body.kvs[1])
-    if not res.body.kvs[1].value then
-        -- remove last "/" when necesary
-        if string.sub(res.body.node.key, -1, -1) == "/" then
-            res.body.node.key = string.sub(res.body.node.key, 1, #res.body.node.key-1)
+    if not is_dir then
+        local key = res.body.kvs[1].key
+        if key ~= real_key then
+            return not_found(res)
+        end
+
+        res.body.node = kvs_to_node(res.body.kvs[1])
+
+    else
+        -- In etcd v2, the direct key asked for is `node`, others which under this dir are `nodes`
+        -- While in v3, this structure is flatten and all keys related the key asked for are `kvs`
+        res.body.node = kvs_to_node(res.body.kvs[1])
+        if not res.body.kvs[1].value then
+            -- remove last "/" when necesary
+            if string.sub(res.body.node.key, -1, -1) == "/" then

Review comment:
       What about using `string.byte` 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.

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



[GitHub] [apisix] membphis merged pull request #2772: fix(etcd): avoid getting with prefix

Posted by GitBox <gi...@apache.org>.
membphis merged pull request #2772:
URL: https://github.com/apache/apisix/pull/2772


   


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