Class: ChefServerSlice::CookbookTemplates

Inherits:
Application
  • Object
show all
Includes:
Chef::Mixin::Checksum, Chef::Mixin::FindPreferredFile
Defined in:
app/controllers/cookbook_templates.rb

Instance Method Summary collapse

Methods inherited from Application

#absolute_slice_url, #access_denied, #authorized_node, #escape_node_id, #expand_cookbook_deps, #fix_up_node_id, #get_available_recipes, #load_all_files, #load_cookbook_segment, #login_required, #redirect_back_or_default, #segment_files, #specific_cookbooks, #store_location

Instance Method Details

#indexObject

def load_cookbook_templates()

@cl = Chef::CookbookLoader.new
@cookbook = @cl[params[:cookbook_id]]
raise NotFound unless @cookbook

@templates = Hash.new
@cookbook.template_files.each do |tf|
  full = File.expand_path(tf)
  name = File.basename(full)
  tf =~ /^.+#{params[:cookbook_id]}[\\|\/]templates[\\|\/](.+?)[\\|\/]#{name}/
  singlecopy = $1
  @templates[full] = {
    :name => name,
    :singlecopy => singlecopy,
    :file => full,
  }
end
@templates

end



52
53
54
55
56
57
58
59
# File 'app/controllers/cookbook_templates.rb', line 52

def index
  if params[:id]
    show
  else
    @templates = load_cookbook_files(params[:cookbook_id], :template)
    display @templates
  end
end

#showObject

Raises:

  • (NotFound)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/cookbook_templates.rb', line 61

def show
  to_send = find_preferred_file(
    params[:cookbook_id], 
    :template, 
    params[:id], 
    params[:fqdn], 
    params[:platform], 
    params[:version]
  )
  raise NotFound, "Cannot find a suitable template!" unless to_send
  current_checksum = checksum(to_send)
  Chef::Log.debug("old sum: #{params[:checksum]}, new sum: #{current_checksum}") 
  if current_checksum == params[:checksum]
    render "Template #{to_send} has not changed", :status => 304
  else
    send_file(to_send)
  end
end