diff options
author | Serdar Sutay <serdar@opscode.com> | 2014-10-10 15:50:51 -0700 |
---|---|---|
committer | Serdar Sutay <serdar@opscode.com> | 2014-10-10 15:50:51 -0700 |
commit | b44a86aab6a4c7e4f8474cebbc0457b673529e67 (patch) | |
tree | 80b80510f8528820228ee4dd4f511adb2fbe621a /lib/chef/knife/cookbook_site_share.rb | |
parent | dcd979cd994d7d9fa630343ed86d7bd9b02bbda2 (diff) | |
parent | bb278f43e68c5b71fc0ad6009d14a1a10cd9b776 (diff) | |
download | chef-b44a86aab6a4c7e4f8474cebbc0457b673529e67.tar.gz |
Merge pull request #2203 from martinb3/master
Allow `knife cookbook site share` to omit category
Diffstat (limited to 'lib/chef/knife/cookbook_site_share.rb')
-rw-r--r-- | lib/chef/knife/cookbook_site_share.rb | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/lib/chef/knife/cookbook_site_share.rb b/lib/chef/knife/cookbook_site_share.rb index d6cd570067..b4a7873c71 100644 --- a/lib/chef/knife/cookbook_site_share.rb +++ b/lib/chef/knife/cookbook_site_share.rb @@ -31,7 +31,7 @@ class Chef require 'chef/cookbook_site_streaming_uploader' end - banner "knife cookbook site share COOKBOOK CATEGORY (options)" + banner "knife cookbook site share COOKBOOK [CATEGORY] (options)" category "cookbook site" option :cookbook_path, @@ -48,16 +48,20 @@ class Chef :description => "Don't take action, only print what files will be upload to SuperMarket." def run - if @name_args.length < 2 + config[:cookbook_path] ||= Chef::Config[:cookbook_path] + + if @name_args.length < 1 show_usage - ui.fatal("You must specify the cookbook name and the category you want to share this cookbook to.") - exit 1 + ui.fatal("You must specify the cookbook name.") + exit(1) + elsif @name_args.length < 2 + cookbook_name = @name_args[0] + category = get_category(cookbook_name) + else + cookbook_name = @name_args[0] + category = @name_args[1] end - config[:cookbook_path] ||= Chef::Config[:cookbook_path] - - cookbook_name = @name_args[0] - category = @name_args[1] cl = Chef::CookbookLoader.new(config[:cookbook_path]) if cl.cookbook_exists?(cookbook_name) cookbook = cl[cookbook_name] @@ -99,6 +103,22 @@ class Chef end + def get_category(cookbook_name) + begin + data = noauth_rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{@name_args[0]}") + if !data["category"] && data["error_code"] + ui.fatal("Received an error from the Opscode Cookbook site: #{data["error_code"]}. On the first time you upload it, you are required to specify the category you want to share this cookbook to.") + exit(1) + else + data['category'] + end + rescue => e + ui.fatal("Unable to reach Opscode Cookbook Site: #{e.message}. Increase log verbosity (-VV) for more information.") + Chef::Log.debug("\n#{e.backtrace.join("\n")}") + exit(1) + end + end + def do_upload(cookbook_filename, cookbook_category, user_id, user_secret_filename) uri = "https://supermarket.getchef.com/api/v1/cookbooks" |