class Dpl::Providers::ChefSupermarket
Constants
- URL
Public Instance Methods
Source
# File lib/dpl/providers/chef_supermarket.rb, line 57 def deploy info :upload upload end
Source
# File lib/dpl/providers/chef_supermarket.rb, line 46 def setup Chef::Config[:client_key] = client_key chdir dir end
Source
# File lib/dpl/providers/chef_supermarket.rb, line 51 def validate info :validate validate_file client_key uploader.validate_cookbooks end
Private Instance Methods
Source
# File lib/dpl/providers/chef_supermarket.rb, line 103 def build_dir @build_dir ||= Chef::Knife::Core::CookbookSiteStreamingUploader.create_build_dir(cookbook) end
Source
# File lib/dpl/providers/chef_supermarket.rb, line 91 def cookbook @cookbook ||= loader.cookbook_version end
Source
# File lib/dpl/providers/chef_supermarket.rb, line 115 def handle_error(res) res = JSON.parse(res) unknown_error(res) unless res['error_messages'] version_exists if res['error_messages'][0].include?('Version already exists') error (res['error_messages'][0]).to_s end
Source
# File lib/dpl/providers/chef_supermarket.rb, line 130 def json(obj) JSON.dump(obj) end
Source
# File lib/dpl/providers/chef_supermarket.rb, line 95 def loader Chef::Cookbook::CookbookVersionLoader.new('.').tap(&:load!) end
Source
# File lib/dpl/providers/chef_supermarket.rb, line 79 def name @name ||= name_from_json || name_from_rb || error(:missing_file, 'metadata.json or metadata.rb') end
Source
# File lib/dpl/providers/chef_supermarket.rb, line 83 def name_from_json JSON.parse(read('metadata.json'))['name'] if file?('metadata.json') end
Source
# File lib/dpl/providers/chef_supermarket.rb, line 87 def name_from_rb Chef::Cookbook::Metadata.new.from_file('metadata.rb') if file?('metadata.rb') end
Source
# File lib/dpl/providers/chef_supermarket.rb, line 69 def params { cookbook: json(category:), tarball: } end
Source
# File lib/dpl/providers/chef_supermarket.rb, line 73 def tarball shell "tar -czf /tmp/#{name}.tgz -C #{build_dir} ." shell "tar -tvf /tmp/#{name}.tgz" open "/tmp/#{name}.tgz" end
Source
# File lib/dpl/providers/chef_supermarket.rb, line 122 def unknown_error(msg) error :unknown_error, msg end
Source
# File lib/dpl/providers/chef_supermarket.rb, line 64 def upload res = Chef::Knife::Core::CookbookSiteStreamingUploader.post(URL, user_id, client_key, params) handle_error(res.body) if res.code.to_i != 201 end
Source
# File lib/dpl/providers/chef_supermarket.rb, line 99 def uploader Chef::CookbookUploader.new(cookbook) end
Source
# File lib/dpl/providers/chef_supermarket.rb, line 107 def validate_file(path) error :missing_file, path unless file?(path) end
Source
# File lib/dpl/providers/chef_supermarket.rb, line 126 def version_exists error :version_exists end