Class: Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-packer-plugin/utils/downloader.rb

Class Method Summary collapse

Class Method Details

.get(file, destination, params = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/vagrant-packer-plugin/utils/downloader.rb', line 5

def self.get(file, destination, params=nil)
	if params.nil? or params.databags_username.nil?
		file = file.gsub("file://", "")
		file_path = file.gsub("$PWD", "#{Dir.pwd}")
		puts "[packer-build] #{file_path} to #{destination}"
		open(file_path) {|f|
		   File.open(destination,"wb") do |file|
		     file.puts f.read
		   end
		}
	else
		self.get_with_auth(file, destination, params.databags_username, params.databags_password)
	end
end

.get_with_auth(file, destination, user, password) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/vagrant-packer-plugin/utils/downloader.rb', line 20

def self.get_with_auth(file, destination,user, password)
	puts "[packer-build] retrieving with authentication"
	file = file.gsub("file://", "")
	file_path = file.gsub("$PWD", "#{Dir.pwd}")
	puts "[packer-build] #{file_path} to #{destination}"
	open(file_path, :http_basic_authentication => [user, password], :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE) {|f|
		File.open(destination,"wb") do |file|
			file.puts f.read
		end
	}
end