Skip to content

Commit 39ed34b

Browse files
committed
Merge pull request #8 from jonsyu1/feature/recursive-lookup
Handle recursive lookups on etcd directories
2 parents 9b56b6d + 40a297b commit 39ed34b

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lib/hiera/backend/etcd_backend.rb

+18-2
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,34 @@ def lookup(key, scope, order_override, resolution_type)
2525
next
2626
end
2727
begin
28-
result = @client.get("#{path}/#{key}")
28+
result = @client.get("#{path}/#{key}").node
2929
rescue
3030
Hiera.debug("[hiera-etcd]: bad request key")
3131
next
3232
end
33-
answer = self.parse_result(result.value, resolution_type, scope)
33+
answer = self.traverse_node(result, resolution_type, scope)
3434
next unless answer
3535
break
3636
end
3737
answer
3838
end
3939

40+
def traverse_node(node, type, scope)
41+
if (node.dir == nil)
42+
then
43+
return parse_result(node.value, type, scope)
44+
else
45+
answer ||= {}
46+
47+
node.children.each do|n|
48+
key = n.key
49+
# Normalize the key
50+
relative_key = key[key.rindex('/')+1..-1]
51+
answer[relative_key] = traverse_node(@client.get(key).node, type, scope)
52+
end
53+
return answer
54+
end
55+
end
4056

4157
def parse_result(res, type, scope)
4258
answer = nil

0 commit comments

Comments
 (0)