summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-05-18 11:40:29 -0700
committerTim Smith <tsmith84@gmail.com>2020-05-18 11:40:29 -0700
commit9601876d934b37f6948e2a26f4ad59dc1a9d09db (patch)
tree57b2d1cfcc323632bb23ca75df59237f991ed2dc
parentff02c248813616f322879eb437f2c398017c0201 (diff)
downloadchef-9601876d934b37f6948e2a26f4ad59dc1a9d09db.tar.gz
Fix failures inspecting a single cookbook
The chef-resource-inspector with zero args inspects chef, but you can also pass it an argument to inspect cookbooks or files. The current logic for inspecting a cookbook is broken. It incorrectly tries to load cookbooks and it results in failures after several minutes of spinning. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource_inspector.rb7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/chef/resource_inspector.rb b/lib/chef/resource_inspector.rb
index bc96ffd4a3..a12b06fcb2 100644
--- a/lib/chef/resource_inspector.rb
+++ b/lib/chef/resource_inspector.rb
@@ -69,8 +69,8 @@ module ResourceInspector
dir, name = File.split(path)
Chef::Cookbook::FileVendor.fetch_from_disk(path)
loader = Chef::CookbookLoader.new(dir)
- cookbooks = loader.load_cookbooks
- resources = cookbooks[name].files_for(:resources)
+ cookbook = loader.load_cookbook(name)
+ resources = cookbook.files_for(:resources)
resources.each_with_object({}) do |r, res|
pth = r["full_path"]
@@ -83,13 +83,14 @@ module ResourceInspector
# otherwise, if we have a path then extract all the resources from the cookbook
# or else do a list of built in resources
#
+ # @param arguments [Array, String] One of more paths to a cookbook or a resource file to inspect
# @param complete [TrueClass, FalseClass] Whether to show properties defined in the base Resource class
# @return [String] JSON formatting of all resources
def self.inspect(arguments = [], complete: false)
output = if arguments.empty?
ObjectSpace.each_object(Class).select { |k| k < Chef::Resource }.each_with_object({}) { |klass, acc| acc[klass.resource_name] = extract_resource(klass) }
else
- arguments.each_with_object({}) do |arg, acc|
+ Array(arguments).each_with_object({}) do |arg, acc|
if File.directory?(arg)
extract_cookbook(arg, complete).each { |k, v| acc[k] = v }
else