Class: Chef::Knife::SupermarketShare

Inherits:
Knife::CookbookSiteShare
  • Object
show all
Defined in:
lib/chef/knife/supermarket_share.rb

Instance Method Summary collapse

Instance Method Details

#do_upload(cookbook_filename, cookbook_category, user_id, user_secret_filename) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/chef/knife/supermarket_share.rb', line 59

def do_upload(cookbook_filename, cookbook_category, user_id, user_secret_filename)
   uri = "#{config[:supermarket_site]}/api/v1/cookbooks"

   # Categories are optional both in knife cookbook site
   # (which this plugin seeks to replace) and on the
   # Supermarket community site.  Best practice now
   # seems to be to just omit the category entirely.
   #
   # see:
   # https://github.com/chef/supermarket/pull/915
   # https://github.com/chef/chef/pull/2198

   category_string = { 'category'=>'' }.to_json

   http_resp = Chef::CookbookSiteStreamingUploader.post(uri, user_id, user_secret_filename, {
     :tarball => File.open(cookbook_filename),
     :cookbook => category_string
   })

   res = Chef::JSONCompat.from_json(http_resp.body)
   if http_resp.code.to_i != 201
     if res['error_messages']
       if res['error_messages'][0] =~ /Version already exists/
         ui.error "The same version of this cookbook already exists on the Opscode Cookbook Site."
         exit(1)
       else
         ui.error "#{res['error_messages'][0]}"
         exit(1)
       end
     else
       ui.error "Unknown error while sharing cookbook"
       ui.error "Server response: #{http_resp.body}"
       exit(1)
     end
   end
   res
end

#runObject

since we subclass cookbook_site and it expects a category, pass a phantom empty category parameter before invoking Chef::Knife::CookbookSiteShare#run … Tested on 11.16.4 and 12.0.3.



52
53
54
55
56
57
58
# File 'lib/chef/knife/supermarket_share.rb', line 52

def run
  Chef::Log.deprecation <<EOF
The `knife-supermarket` gem has been deprecated and the `knife supermarket` subcommands have been moved in to core Chef. Please ensure you have Chef 12.12 or newer, and then uninstall this gem.
EOF
  @name_args << "" if @name_args.length == 1
  super
end