Class: Chef::Knife::CookbookSiteDownload

Inherits:
Chef::Knife show all
Defined in:
lib/chef/knife/cookbook_site_download.rb

Instance Attribute Summary collapse

Attributes inherited from Chef::Knife

#name_args, #ui

Instance Method Summary collapse

Methods inherited from Chef::Knife

#api_key, category, common_name, #configure_chef, #create_object, #delete_object, deps, #format_rest_error, guess_category, #highlight_config_error, #humanize_exception, #humanize_http_exception, inherited, #initialize, list_commands, load_commands, load_deps, msg, #noauth_rest, #parse_options, #read_config_file, reset_subcommands!, #rest, run, #run_with_pretty_exceptions, #server_url, #show_usage, snake_case_name, subcommand_category, subcommand_class_from, subcommand_loader, subcommands, subcommands_by_category, ui, unnamed?, #username

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename

Constructor Details

This class inherits a constructor from Chef::Knife

Instance Attribute Details

#versionObject (readonly)

Returns the value of attribute version.



24
25
26
# File 'lib/chef/knife/cookbook_site_download.rb', line 24

def version
  @version
end

Instance Method Details

#runObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/chef/knife/cookbook_site_download.rb', line 38

def run
  current = noauth_rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{name_args[0]}")
  if current["deprecated"] == true
    replacement = File.basename(current["replacement"])
    ui.warn("DEPRECATION: This cookbook has been deprecated. It has been replaced by #{replacement}.")
    unless config[:force]
      ui.warn("Use --force to force download deprecated cookbook.")
      return
    end
  end
  cookbook_data = if @name_args.length == 1
                    noauth_rest.get_rest(current["latest_version"])
                  else
                    noauth_rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{name_args[0]}/versions/#{name_args[1].gsub('.', '_')}")
                  end

  @version = cookbook_data['version']
  unless config[:file]
    config[:file] = File.join(Dir.pwd, "#{@name_args[0]}-#{cookbook_data['version']}.tar.gz")
  end
  ui.info("Downloading #{@name_args[0]} from the cookbooks site at version #{cookbook_data['version']} to #{config[:file]}")
  noauth_rest.sign_on_redirect = false
  tf = noauth_rest.get_rest(cookbook_data["file"], true)

  FileUtils.cp(tf.path, config[:file])
  ui.info("Cookbook saved: #{config[:file]}")
end