Class: DPL::Provider::ChefSupermarket
- Inherits:
-
DPL::Provider
- Object
- DPL::Provider
- DPL::Provider::ChefSupermarket
- Defined in:
- lib/dpl/provider/chef_supermarket.rb
Instance Attribute Summary collapse
-
#cookbook ⇒ Object
readonly
Returns the value of attribute cookbook.
-
#cookbook_category ⇒ Object
readonly
Returns the value of attribute cookbook_category.
-
#cookbook_name ⇒ Object
readonly
Returns the value of attribute cookbook_name.
Attributes inherited from DPL::Provider
Instance Method Summary collapse
Methods inherited from DPL::Provider
apt_get, #cleanup, #commit_msg, context, #create_key, #default_text_charset, #default_text_charset?, #deploy, #detect_encoding?, #encoding_for, #error, experimental, #initialize, #log, new, npm_g, #option, pip, requires, #run, #setup_git_credentials, #setup_git_ssh, #sha, shell, #uncleanup, #user_agent, #warn
Constructor Details
This class inherits a constructor from DPL::Provider
Instance Attribute Details
#cookbook ⇒ Object (readonly)
Returns the value of attribute cookbook.
16 17 18 |
# File 'lib/dpl/provider/chef_supermarket.rb', line 16 def cookbook @cookbook end |
#cookbook_category ⇒ Object (readonly)
Returns the value of attribute cookbook_category.
15 16 17 |
# File 'lib/dpl/provider/chef_supermarket.rb', line 15 def cookbook_category @cookbook_category end |
#cookbook_name ⇒ Object (readonly)
Returns the value of attribute cookbook_name.
15 16 17 |
# File 'lib/dpl/provider/chef_supermarket.rb', line 15 def cookbook_name @cookbook_name end |
Instance Method Details
#check_app ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dpl/provider/chef_supermarket.rb', line 29 def check_app @cookbook_name = [:cookbook_name] || [:app] @cookbook_category = [:cookbook_category] unless cookbook_category error "Missing cookbook_category option\n" + "see https://docs.getchef.com/knife_cookbook_site.html#id12" end log "Validating cookbook #{cookbook_name}" # Check that cookbook exist and is valid # So we assume cookbook path is '..' cl = ::Chef::CookbookLoader.new '..' @cookbook = cl[cookbook_name] ::Chef::CookbookUploader.new(cookbook, '..').validate_cookbooks end |
#check_auth ⇒ Object
22 23 24 25 26 27 |
# File 'lib/dpl/provider/chef_supermarket.rb', line 22 def check_auth error "Missing user_id option" unless [:user_id] error "Missing client_key option" unless [:client_key] ::Chef::Config[:client_key] = [:client_key] error "#{[:client_key]} does not exist" unless ::File.exist?([:client_key]) end |
#needs_key? ⇒ Boolean
18 19 20 |
# File 'lib/dpl/provider/chef_supermarket.rb', line 18 def needs_key? false end |
#push_app ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/dpl/provider/chef_supermarket.rb', line 45 def push_app log "Creating cookbook build directory" tmp_cookbook_dir = Chef::CookbookSiteStreamingUploader.create_build_dir(cookbook) log "Making tarball in #{tmp_cookbook_dir}" system("tar -czf #{cookbook_name}.tgz #{cookbook_name}", :chdir => tmp_cookbook_dir) uri = "https://supermarket.chef.io/api/v1/cookbooks" log "Uploading to #{uri}" category_string = { 'category'=>cookbook_category }.to_json http_resp = ::Chef::CookbookSiteStreamingUploader.post( uri, [:user_id], [:client_key], { :tarball => File.open("#{tmp_cookbook_dir}/#{cookbook_name}.tgz"), :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/ error "The same version of this cookbook already exists on the Opscode Cookbook Site." else error "#{res['error_messages'][0]}" end else error "Unknown error while sharing cookbook\n" + "Server response: #{http_resp.body}" end end log "Upload complete." ::FileUtils.rm_rf tmp_cookbook_dir end |