Skip to content

Commit

Permalink
Merge pull request voxpupuli#57 from jairojunior/master
Browse files Browse the repository at this point in the history
Fix issue voxpupuli#56
  • Loading branch information
nanliu committed May 21, 2015
2 parents 4f266b1 + 4ac6589 commit 4713d1d
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions lib/puppet_x/bodeco/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ module Util
def self.download(url, filepath, options = {})
uri = URI(url)
@connection = PuppetX::Bodeco.const_get(uri.scheme.upcase).new("#{uri.scheme}://#{uri.host}:#{uri.port}", options)
@connection.download("#{uri.path}?#{uri.query}", filepath)
@connection.download(uri, filepath)
end

def self.content(url, filepath, options = {})
def self.content(url, options = {})
uri = URI(url)
@connection = PuppetX::Bodeco.const_get(uri.scheme.upcase).new("#{uri.scheme}://#{uri.host}:#{uri.port}", options)
@connection.content("#{uri.path}?#{uri.query}")
@connection.content(uri)
end
end

Expand All @@ -27,8 +27,8 @@ def initialize(url, options)
require 'faraday_middleware'
end

if Facter.value(:osfamily) == 'windows' and !ENV.has_key?("SSL_CERT_FILE")
ENV["SSL_CERT_FILE"] = File.expand_path(File.join(__FILE__, '..', '..', '..', '..', 'files', 'cacert.pem'))
if Facter.value(:osfamily) == 'windows' and !ENV.key?('SSL_CERT_FILE')
ENV['SSL_CERT_FILE'] = File.expand_path(File.join(__FILE__, '..', '..', '..', '..', 'files', 'cacert.pem'))
end

@connection = ::Faraday.new(url) do |conn|
Expand All @@ -41,20 +41,20 @@ def initialize(url, options)
end
end

def download(url_path, file_path)
def download(uri, file_path)
f = File.open(file_path, 'wb')
f.write(@connection.get(url_path).body)
f.write(@connection.get(uri.request_uri).body)
f.close
rescue Faraday::Error::ClientError
f.close
File.unlink(file_path)
raise $!, "Unable to download file #{url_path} from #{@connection.url_prefix}. #{$!}", $!.backtrace
raise $ERROR_INFO, "Unable to download file #{uri.request_uri} from #{@connection.url_prefix}. #{$ERROR_INFO}", $ERROR_INFO.backtrace
end

def content(url_path)
@connection.get(url_path).body
def content(uri)
@connection.get(uri.request_uri).body
rescue Faraday::Error::ClientError
raise $!, "Unable to retrieve content #{url_path} from #{@connection.url_prefix}. #{$!}", $!.backtrace
raise $ERROR_INFO, "Unable to retrieve content #{uri.request_uri} from #{@connection.url_prefix}. #{$ERROR_INFO}", $ERROR_INFO.backtrace
end
end

Expand All @@ -77,17 +77,17 @@ def initialize(url, options)
end
end

def download(url, file_path)
@ftp.getbinaryfile(url, file_path)
def download(uri, file_path)
@ftp.getbinaryfile(uri.path, file_path)
end
end

class FILE
def initialize(url, options)
def initialize(_url, _options)
end

def download(url_path, file_path)
FileUtils.copy(url_path, file_path)
def download(uri, file_path)
FileUtils.copy(uri.path, file_path)
end
end
end
Expand Down

0 comments on commit 4713d1d

Please sign in to comment.