Skip to content

Commit 9b56b6d

Browse files
committed
Merge pull request #6 from jumanjiman/json
Attempt to parse json hash or array when called with hiera()
2 parents b92c42f + c35e770 commit 9b56b6d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/hiera/backend/etcd_backend.rb

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def parse_result(res, type, scope)
4242
answer = nil
4343
case type
4444
when :array
45+
# Called with hiera_array().
4546
answer ||= []
4647
begin
4748
data = Backend.parse_answer(JSON[res], scope)
@@ -56,6 +57,7 @@ def parse_result(res, type, scope)
5657
Hiera.warn("Data is in json format, but this is not an array")
5758
end
5859
when :hash
60+
# Called with hiera_hash().
5961
answer ||= {}
6062
begin
6163
data = Backend.parse_answer(JSON[res], scope)
@@ -69,6 +71,8 @@ def parse_result(res, type, scope)
6971
Hiera.warn("Data is in json format, but this is not an hash")
7072
end
7173
else
74+
# Called with hiera(), which can return an array, hash, or string.
75+
res = JSON[res] rescue res
7276
answer = Backend.parse_answer(res, scope)
7377
end
7478
answer

0 commit comments

Comments
 (0)