Sha256: ee050972f4dbcf3c9b575e5ea5eb1c5a63731d22001ec3877f2b410746e58b20
Contents?: true
Size: 1.56 KB
Versions: 2
Compression:
Stored size: 1.56 KB
Contents
require 'httparty' require 'httmultiparty' require 'mixlib/authentication/signedheaderauth' require 'openssl' module Stove class Uploader include HTTMultiParty # The cookbook associated with this uploader # # @return [Stove::Cookbook] attr_reader :cookbook # Create a new uploader instance for the given cookbook. # # @param [Stove::Cookbook] cookbook # the cookbook for this uploader def initialize(cookbook) @cookbook = cookbook end def upload! response = self.class.post(upload_url, { :headers => headers, :query => { :tarball => File.new(cookbook.tarball), :cookbook => { category: cookbook.category }.to_json, }, }) if response.success? Stove.formatter.upload(cookbook) else raise Stove::UploadError.new(response) end end private def headers { 'Accept' => 'application/json', }.merge(Mixlib::Authentication::SignedHeaderAuth.signing_object({ :http_method => 'post', :timestamp => Time.now.utc.iso8601, :user_id => username, :path => URI.parse(upload_url).path, :file => File.new(cookbook.tarball), }).sign(pem_file)) end def pem_file OpenSSL::PKey::RSA.new(File.read(File.expand_path(Stove::Config['opscode_pem_file']))) end def username Stove::Config['opscode_username'] end def upload_url "#{Stove::CommunitySite.base_uri}/cookbooks" end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
stove-1.1.2 | lib/stove/uploader.rb |
stove-1.1.0 | lib/stove/uploader.rb |