Skip to content

Commit 0b11b96

Browse files
dafyddcrosbyfacebook-github-bot
authored andcommitted
backport include_recipes key for JSON recipes
Summary: See chef/chef#15299 Differential Revision: D83189633 fbshipit-source-id: 384d1e2a722a56c0ea3abfec40b11053a5c5ddb8
1 parent e84b1c9 commit 0b11b96

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

cookbooks/fb_helpers/libraries/json_recipes_monkeypatch.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,28 @@ def from_json_file(filename)
7878

7979
def from_json(string)
8080
res = JSONCompat.from_json(string)
81-
unless res.is_a?(Hash) && res.key?("resources")
82-
raise ArgumentError, "JSON recipe '#{source_file}' must contain a top-level 'resources' hash"
81+
unless res.is_a?(Hash) && (res.key?("resources") || res.key?("include_recipes"))
82+
raise ArgumentError, "JSON recipe '#{source_file}' must contain a top-level 'resources' or 'include_recipes' hash key"
8383
end
8484

8585
from_hash(res)
8686
end
87+
88+
89+
def from_hash(hash)
90+
hash["resources"]&.each do |rhash|
91+
type = rhash.delete("type").to_sym
92+
name = rhash.delete("name")
93+
res = declare_resource(type, name)
94+
rhash.each do |key, value|
95+
# FIXME?: we probably need a way to instance_exec a string that contains block code against the property?
96+
res.send(key, value)
97+
end
98+
end
99+
hash["include_recipes"]&.each do |recipe|
100+
run_context.include_recipe recipe
101+
end
102+
end
87103
end
88104
end
89105

0 commit comments

Comments
 (0)