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-22 08:58:59 -0700
commit2b015db32d56ab5a383f2a182860f8c884a2c287 (patch)
tree87827c9c1ab6176dae6497b7b6b50ab1a4dbb76c
parentf9483a91ea24f8a3385a180ae5f4cdf063d91eb8 (diff)
downloadchef-2b015db32d56ab5a383f2a182860f8c884a2c287.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 7006bb5bd6..edc6c66510 100644
--- a/lib/chef/resource_inspector.rb
+++ b/lib/chef/resource_inspector.rb
@@ -68,8 +68,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"]
@@ -82,13 +82,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