diff options
Diffstat (limited to 'lib/chef/knife/supermarket_unshare.rb')
-rw-r--r-- | lib/chef/knife/supermarket_unshare.rb | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/lib/chef/knife/supermarket_unshare.rb b/lib/chef/knife/supermarket_unshare.rb index fd48e172ce..eb17fc6bd4 100644 --- a/lib/chef/knife/supermarket_unshare.rb +++ b/lib/chef/knife/supermarket_unshare.rb @@ -1,6 +1,6 @@ # # Author:: Christopher Webber (<cwebber@chef.io>) -# Copyright:: Copyright (c) 2014 Chef Software, Inc. +# Copyright:: Copyright (c) 2014-2018 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,17 +17,45 @@ # require "chef/knife" -require "chef/knife/cookbook_site_unshare" class Chef class Knife - class SupermarketUnshare < Knife::CookbookSiteUnshare - # Handle the subclassing (knife doesn't do this :() - dependency_loaders.concat(superclass.dependency_loaders) - options.merge!(superclass.options) + class SupermarketUnshare < Knife - banner "knife supermarket unshare COOKBOOK (options)" + deps do + require "chef/json_compat" + end + + banner "knife supermarket unshare COOKBOOK" category "supermarket" + + option :supermarket_site, + short: "-m SUPERMARKET_SITE", + long: "--supermarket-site SUPERMARKET_SITE", + description: "Supermarket Site", + default: "https://supermarket.chef.io", + proc: Proc.new { |supermarket| Chef::Config[:knife][:supermarket_site] = supermarket } + + def run + @cookbook_name = @name_args[0] + if @cookbook_name.nil? + show_usage + ui.fatal "You must provide the name of the cookbook to unshare" + exit 1 + end + + confirm "Do you really want to unshare all versions of the cookbook #{@cookbook_name}" + + begin + rest.delete "#{config[:supermarket_site]}/api/v1/cookbooks/#{@name_args[0]}" + rescue Net::HTTPServerException => e + raise e unless e.message =~ /Forbidden/ + ui.error "Forbidden: You must be the maintainer of #{@cookbook_name} to unshare it." + exit 1 + end + + ui.info "Unshared all versions of the cookbook #{@cookbook_name}" + end end end end |