Skip to content

Commit

Permalink
Fix CHEF-2225: handle deprecated cookbooks in knife cookbook site dow…
Browse files Browse the repository at this point in the history
…nload
  • Loading branch information
Nuo Yan committed Apr 14, 2011
1 parent a4b0523 commit b5324dd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
5 changes: 3 additions & 2 deletions chef/distro/common/html/knife-cookbook-site.1.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions chef/distro/common/man/man1/knife-cookbook-site.1
Expand Up @@ -52,6 +52,10 @@ If \fI\-d\fR is specified, the process is applied recursively to all the cookboo
\fB\-f\fR, \fB\-\-file FILE\fR
The filename to write to
.
.TP
\fB\-\-force\fR
Force download deprecated cookbook
.
.P
Downloads a specific cookbook from the Community site, optionally specifying a certain version\.
.
Expand Down
2 changes: 2 additions & 0 deletions chef/distro/common/markdown/man1/knife-cookbook-site.mkd
Expand Up @@ -39,6 +39,8 @@ __knife cookbook site download COOKBOOK [VERSION]__ _(options)_

* `-f`, `--file FILE`:
The filename to write to
* `--force`:
Force download deprecated cookbook

Downloads a specific cookbook from the Community site, optionally
specifying a certain version.
Expand Down
40 changes: 26 additions & 14 deletions chef/lib/chef/knife/cookbook_site_download.rb
Expand Up @@ -5,9 +5,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -27,26 +27,38 @@ class CookbookSiteDownload < Knife
category "cookbook site"

option :file,
:short => "-f FILE",
:long => "--file FILE",
:description => "The filename to write to"
:short => "-f FILE",
:long => "--file FILE",
:description => "The filename to write to"

option :force,
:long => "--force",
:description => "Force download deprecated version"

def run
if @name_args.length == 1
current = noauth_rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{name_args[0]}")
cookbook_data = noauth_rest.get_rest(current["latest_version"])
else
cookbook_data = noauth_rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{name_args[0]}/versions/#{name_args[1].gsub('.', '_')}")
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']

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)
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
Expand Down

0 comments on commit b5324dd

Please sign in to comment.