Skip to content

Commit 16302e9

Browse files
Thom MaySeth Falcon
authored andcommitted
Convert index_recipes to return *all* recipes
This changes the API somewhat; rather than just an array of recipes (which is bust because recipes may only exist in certain versions of cookbooks) you get a hash back: cookbook -> version -> recipes. Change the only two places that use _recipes to DTRT
1 parent f77f78a commit 16302e9

3 files changed

Lines changed: 8 additions & 12 deletions

File tree

chef-server-api/app/controllers/cookbooks.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,11 @@ def index_latest
5858
end
5959

6060
def index_recipes
61-
all_cookbooks = Array(Chef::CookbookVersion.cdb_list_latest(true))
62-
all_cookbooks.map! do |cookbook|
63-
cookbook.manifest["recipes"].map { |r| "#{cookbook.name}::#{File.basename(r['name'], ".rb")}" }
61+
display Chef::CookbookVersion.cdb_list(true).inject({}) do |memo, f|
62+
memo[f.name] ||= {}
63+
memo[f.name][f.version] = f.recipe_filenames_by_name.keys
64+
memo
6465
end
65-
all_cookbooks.flatten!
66-
all_cookbooks.sort!
67-
display all_cookbooks
6866
end
6967

7068
def show_versions

chef-server-webui/app/controllers/application.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,9 @@ def determine_name(type, object)
256256
def get_available_recipes
257257
r = Chef::REST.new(Chef::Config[:chef_server_url])
258258
all_recipes = Array.new
259-
r.get_rest('cookbooks').keys.each do |cb|
260-
all_recipes << r.get_rest("cookbooks/#{cb}")[cb].sort!{|x,y| y <=> x }.map do |ver|
261-
r.get_rest("cookbooks/#{cb}/#{ver}").recipe_filenames.map do |rec|
262-
rn = File.basename(rec, ".rb")
263-
rn == "default" ? "#{cb} #{ver}" : "#{cb}::#{rn} #{ver}"
264-
end
259+
r.get_rest('cookbooks/_recipes').keys.each do |cb|
260+
all_recipes << all[cb].sort{|x,y| y <=> x }.map do |ver, recipes|
261+
recipes.map{ |rn| rn == "default" ? "#{cb} #{ver}" : "#{cb}::#{rn} #{ver}" }
265262
end
266263
end
267264
all_recipes.flatten.uniq

chef/lib/chef/knife/recipe_list.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Chef::Knife::RecipeList < Chef::Knife
2323

2424
def run
2525
recipes = rest.get_rest('cookbooks/_recipes')
26+
recipes = recipes.keys.map { |cb| recipes[cb].map {|ver, rec| rec.map{ |rn| "#{cb}::#{rn} (#{ver})" }}}.flatten.uniq
2627
if pattern = @name_args.first
2728
recipes = recipes.grep(Regexp.new(pattern))
2829
end

0 commit comments

Comments
 (0)