Skip to content

Commit 5e7f24c

Browse files
adamhjkdanielsdeleo
authored andcommitted
Adding a display_manifest function
1 parent b88af12 commit 5e7f24c

4 files changed

Lines changed: 35 additions & 14 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def show
4545
rescue Chef::Exceptions::CouchDBNotFound => e
4646
raise NotFound, "Cannot find a cookbook named #{params[:id]} with version #{params[:version]}"
4747
end
48-
cookbook.generate_manifest { |opts| absolute_slice_url(:cookbook_segment, opts) }
48+
cookbook.display_manifest { |opts| absolute_slice_url(:cookbook_segment, opts) }
4949
display cookbook
5050
end
5151

chef/lib/chef/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def save_node
347347
nil
348348
end
349349
end
350-
350+
351351
# Compiles the full list of recipes for the server, and passes it to an instance of
352352
# Chef::Runner.converge.
353353
#

chef/lib/chef/cookbook.rb

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,35 @@ def self.json_create(o)
313313
cookbook
314314
end
315315

316+
def display_manifest(&url_generation)
317+
self.manifest ? self.manifest : self.generate_manifest
318+
[ 'resources', 'providers', 'recipes', 'definitions', 'libraries', 'attributes', 'files', 'templates' ].each do |segment|
319+
if manifest.has_key?(segment)
320+
manifest[segment].each do |segment_item|
321+
puts segment_item.inspect
322+
url_options = { :cookbook_id => name.to_s, :segment => segment, :id => segment_item["name"] }
323+
set_specificity_arguments(segment_item["specificity"], url_options)
324+
segment_item["uri"] = url_generation.call(url_options)
325+
end
326+
end
327+
end
328+
manifest
329+
end
330+
331+
def set_specificity_arguments(specificity, url_options={})
332+
case specificity
333+
when "default"
334+
when /^host-(.+)$/
335+
url_options[:fqdn] = $1
336+
when /^(.+)-(.+)$/
337+
url_options[:platform] = $1
338+
url_options[:version] = $2
339+
when /^(.+)$/
340+
url_options[:platform] = $1
341+
end
342+
url_options
343+
end
344+
316345
def generate_manifest(&url_generation)
317346
response = {
318347
:recipes => Array.new,
@@ -324,6 +353,7 @@ def generate_manifest(&url_generation)
324353
:resources => Array.new,
325354
:providers => Array.new
326355
}
356+
327357
[ :resources, :providers, :recipes, :definitions, :libraries, :attributes, :files, :templates ].each do |segment|
328358
segment_files(segment).each do |sf|
329359
next if File.directory?(sf)
@@ -342,18 +372,7 @@ def generate_manifest(&url_generation)
342372
specificity = mo[1]
343373
file_name = mo[2]
344374
url_options = { :cookbook_id => name.to_s, :segment => segment, :id => file_name }
345-
346-
case specificity
347-
when "default"
348-
when /^host-(.+)$/
349-
url_options[:fqdn] = $1
350-
when /^(.+)-(.+)$/
351-
url_options[:platform] = $1
352-
url_options[:version] = $2
353-
when /^(.+)$/
354-
url_options[:platform] = $1
355-
end
356-
375+
set_specificity_arguments(specificity, url_options)
357376
file_specificity = specificity
358377
else
359378
mo = sf.match("cookbooks/#{name}/#{segment}/(.+)")
@@ -375,6 +394,7 @@ def generate_manifest(&url_generation)
375394
:checksum => checksum(sf)
376395
}
377396
rs[:specificity] = file_specificity if file_specificity
397+
378398
response[segment] << rs
379399
end
380400
end

chef/lib/chef/knife/cookbook_upload.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def run
5555
else
5656
@name_args.each do |cookbook_name|
5757
cl[cookbook_name].generate_manifest
58+
puts JSON.pretty_generate(cl[cookbook_name])
5859
Chef::Log.info("Saving #{cookbook_name} version #{cl[cookbook_name].version}")
5960
cl[cookbook_name].save
6061
end

0 commit comments

Comments
 (0)