From 3b3e144c9f1c88e1c6cc825257fdc56824cd3216 Mon Sep 17 00:00:00 2001 From: eyalzek Date: Tue, 20 Jun 2017 14:43:49 +0200 Subject: [PATCH] Append `/` character when fetching the kv otherwise the operation fetches keys which do not EXACTLY match the request key. For example, having the following keys: `foo/bar` & `foo-test/bar` and fetching them with: `consul.kv.get({'key': 'foo', recurse:true}, function(err,kvs,res) {console.log(kvs);});` will return: ``` [ { LockIndex: 0, Key: 'foo/bar', Flags: 0, Value: 'test1', CreateIndex: 171, ModifyIndex: 171 }, { LockIndex: 0, Key: 'foo-test/bar', Flags: 0, Value: 'test2', CreateIndex: 10, ModifyIndex: 10 } ] ``` this change will avoid that problem. --- lib/consul/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/consul/index.js b/lib/consul/index.js index b1fbdad..5985a84 100644 --- a/lib/consul/index.js +++ b/lib/consul/index.js @@ -308,7 +308,7 @@ var get_kvs = function(branch, file, cb) { logger.trace('Getting tree for key %s', key_name); // Load all sub-keys as a flattened tree of KV pairs - consul.kv.get({'key': key_name, token: token, recurse: true}, function(err, kvs, res) { + consul.kv.get({'key': key_name + '/', token: token, recurse: true}, function(err, kvs, res) { if (err) return cb('Failed to get tree for key ' + key_name + ' due to ' + err, undefined); var tree = []