Remove downloaders, no longer needed
This commit is contained in:
parent
6c1eb2b007
commit
25f66cee51
|
@ -69,7 +69,6 @@ module Vagrant
|
|||
autoload :CLI, 'vagrant/cli'
|
||||
autoload :Command, 'vagrant/command'
|
||||
autoload :Config, 'vagrant/config'
|
||||
autoload :Downloaders, 'vagrant/downloaders'
|
||||
autoload :Driver, 'vagrant/driver'
|
||||
autoload :Environment, 'vagrant/environment'
|
||||
autoload :Errors, 'vagrant/errors'
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
module Vagrant
|
||||
module Downloaders
|
||||
# Represents a base class for a downloader. A downloader handles
|
||||
# downloading a box file to a temporary file.
|
||||
class Base
|
||||
include Vagrant::Util
|
||||
|
||||
def initialize(ui)
|
||||
@ui = ui
|
||||
end
|
||||
|
||||
# Tests whether a URL matches this download. Subclasses must
|
||||
# override this and return `true` for any URLs they wish to
|
||||
# handle.
|
||||
def self.match?(url); false; end
|
||||
|
||||
# Downloads the source file to the destination file. It is up to
|
||||
# implementors of this class to handle the logic.
|
||||
def download!(source_url, destination_file); end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,28 +0,0 @@
|
|||
require 'fileutils'
|
||||
require 'uri'
|
||||
|
||||
module Vagrant
|
||||
module Downloaders
|
||||
# "Downloads" a file to a temporary file. Basically, this downloader
|
||||
# simply does a file copy.
|
||||
class File < Base
|
||||
def self.match?(uri)
|
||||
extracted = URI.extract(uri, "file")
|
||||
|
||||
# We match if we got a file URI. It doesn't matter here if the file
|
||||
# doesn't exist because we check again later as well.
|
||||
return true if extracted && extracted.include?(uri)
|
||||
|
||||
# Otherwise we match if the file exists
|
||||
return ::File.file?(::File.expand_path(uri))
|
||||
end
|
||||
|
||||
def download!(source_url, destination_file)
|
||||
raise Errors::DownloaderFileDoesntExist if !::File.file?(::File.expand_path(source_url))
|
||||
|
||||
@ui.info I18n.t("vagrant.downloaders.file.download")
|
||||
FileUtils.cp(::File.expand_path(source_url), destination_file.path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,116 +0,0 @@
|
|||
require 'net/http'
|
||||
require 'net/https'
|
||||
require 'uri'
|
||||
require 'base64'
|
||||
|
||||
module Vagrant
|
||||
module Downloaders
|
||||
# Downloads a file from an HTTP URL to a temporary file. This
|
||||
# downloader reports its progress to stdout while downloading.
|
||||
class HTTP < Base
|
||||
def self.match?(uri)
|
||||
# URI.parse barfs on '<drive letter>:\\files \on\ windows'
|
||||
extracted = URI.extract(uri, ['http', 'https']).first
|
||||
extracted && extracted.include?(uri)
|
||||
end
|
||||
|
||||
def download!(source_url, destination_file)
|
||||
uri = URI.parse(source_url)
|
||||
proxy_uri = resolve_proxy(uri)
|
||||
|
||||
http = Net::HTTP.new(uri.host, uri.port, proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
|
||||
http.read_timeout = nil # Disable the read timeout, just let it try to download
|
||||
|
||||
if uri.scheme == "https"
|
||||
http.use_ssl = true
|
||||
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||
end
|
||||
|
||||
http.start do |h|
|
||||
@ui.info I18n.t("vagrant.downloaders.http.download", :url => source_url)
|
||||
|
||||
headers = nil
|
||||
if uri.user && uri.password
|
||||
headers = {'Authorization' => 'Basic ' + Base64.encode64(uri.user + ':' + uri.password)}
|
||||
end
|
||||
|
||||
h.request_get(uri.request_uri, headers) do |response|
|
||||
if response.is_a?(Net::HTTPRedirection)
|
||||
# Follow the HTTP redirect.
|
||||
# TODO: Error on some redirect limit
|
||||
download!(response["Location"], destination_file)
|
||||
return
|
||||
elsif !response.is_a?(Net::HTTPOK)
|
||||
raise Errors::DownloaderHTTPStatusError, :status => response.code
|
||||
end
|
||||
|
||||
total = response.content_length
|
||||
progress = 0
|
||||
segment_count = 0
|
||||
|
||||
response.read_body do |segment|
|
||||
# Report the progress out
|
||||
progress += segment.length
|
||||
segment_count += 1
|
||||
|
||||
# Progress reporting is limited to every 25 segments just so
|
||||
# we're not constantly updating
|
||||
if segment_count % 25 == 0
|
||||
@ui.clear_line
|
||||
@ui.report_progress(progress, total)
|
||||
segment_count = 0
|
||||
end
|
||||
|
||||
# Store the segment
|
||||
destination_file.write(segment)
|
||||
end
|
||||
|
||||
# Clear the line one last time so that the progress meter disappears
|
||||
@ui.clear_line
|
||||
end
|
||||
end
|
||||
rescue Errno::ECONNRESET
|
||||
raise Errors::DownloaderHTTPConnectReset
|
||||
rescue Errno::ETIMEDOUT
|
||||
raise Errors::DownloaderHTTPConnectTimeout
|
||||
rescue SocketError
|
||||
raise Errors::DownloaderHTTPSocketError
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# This method respects the "http_proxy" and "no_proxy" environmental
|
||||
# variables so that HTTP proxies can properly be used with Vagrant.
|
||||
def resolve_proxy(source_uri)
|
||||
# Get the proper proxy key depending on the scheme of the box URL
|
||||
proxy_key = "#{source_uri.scheme}_proxy".downcase
|
||||
proxy_string = ENV[proxy_key] || ENV[proxy_key.upcase] || ""
|
||||
|
||||
if !proxy_string.empty?
|
||||
# Make sure the proxy string starts with a protocol so that
|
||||
# URI.parse works properly below.
|
||||
proxy_string = "http://#{proxy_string}" if !proxy_string.include?("://")
|
||||
|
||||
if ENV.has_key?("no_proxy")
|
||||
# Respect the "no_proxy" environmental variable which contains a list
|
||||
# of hosts that a proxy should not be used for.
|
||||
ENV["no_proxy"].split(",").each do |host|
|
||||
if source_uri.host =~ /#{Regexp.quote(host.strip)}$/
|
||||
proxy_string = ""
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
begin
|
||||
URI.parse(proxy_string)
|
||||
rescue URI::InvalidURIError
|
||||
# If we have an invalid URI, we assume the proxy is invalid,
|
||||
# so we don't use a proxy.
|
||||
URI.parse("")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,14 +0,0 @@
|
|||
require File.expand_path("../../../base", __FILE__)
|
||||
|
||||
describe Vagrant::Downloaders::Base do
|
||||
let(:ui) { double("ui") }
|
||||
let(:instance) { described_class.new(ui) }
|
||||
|
||||
it "should not match anything by default" do
|
||||
described_class.match?("foo").should_not be
|
||||
end
|
||||
|
||||
it "should implement `download!`" do
|
||||
instance.download!("foo", "bar").should be_nil
|
||||
end
|
||||
end
|
|
@ -1,87 +0,0 @@
|
|||
require File.expand_path("../../../base", __FILE__)
|
||||
|
||||
require "tempfile"
|
||||
|
||||
describe Vagrant::Downloaders::File do
|
||||
include_context "unit"
|
||||
|
||||
let(:ui) { double("ui") }
|
||||
let(:instance) { described_class.new(ui) }
|
||||
|
||||
before(:each) do
|
||||
ui.stub(:info)
|
||||
end
|
||||
|
||||
describe "matching" do
|
||||
it "should match an existing file" do
|
||||
described_class.match?(__FILE__).should be
|
||||
end
|
||||
|
||||
it "should not match non-existent files" do
|
||||
described_class.match?(File.join(__FILE__, "nowaywaywaywayayway")).should_not be
|
||||
end
|
||||
|
||||
it "should match files where the path needs to be expanded" do
|
||||
old_home = ENV["HOME"]
|
||||
begin
|
||||
# Create a temporary file
|
||||
temp = temporary_file
|
||||
|
||||
# Set our home directory to be this directory so we can use
|
||||
# "~" paths
|
||||
ENV["HOME"] = File.dirname(temp.to_s)
|
||||
|
||||
# Test that we can find the temp file
|
||||
described_class.match?("~/#{File.basename(temp.to_s)}").should be
|
||||
ensure
|
||||
ENV["HOME"] = old_home
|
||||
end
|
||||
end
|
||||
|
||||
it "should match file:// URIs" do
|
||||
described_class.match?("file://#{__FILE__}").should be
|
||||
end
|
||||
end
|
||||
|
||||
describe "downloading" do
|
||||
let(:destination_file) { temporary_file.open("w") }
|
||||
|
||||
it "should raise an exception if the file does not exist" do
|
||||
path = File.join(__FILE__, "nopenopenope")
|
||||
File.exist?(path).should_not be
|
||||
|
||||
expect { instance.download!(path, destination_file) }.
|
||||
to raise_error(Vagrant::Errors::DownloaderFileDoesntExist)
|
||||
end
|
||||
|
||||
it "should raise an exception if the file is a directory" do
|
||||
path = File.dirname(__FILE__)
|
||||
File.should be_directory(path)
|
||||
|
||||
expect { instance.download!(path, destination_file) }.
|
||||
to raise_error(Vagrant::Errors::DownloaderFileDoesntExist)
|
||||
end
|
||||
|
||||
it "should find files that use shell expansions" do
|
||||
old_home = ENV["HOME"]
|
||||
begin
|
||||
# Create a temporary file
|
||||
temp = Tempfile.new("vagrant")
|
||||
|
||||
# Set our home directory to be this directory so we can use
|
||||
# "~" paths
|
||||
ENV["HOME"] = File.dirname(temp.path)
|
||||
|
||||
# Test that we can find the temp file
|
||||
expect { instance.download!("~/#{File.basename(temp.path)}", destination_file) }.
|
||||
to_not raise_error
|
||||
ensure
|
||||
ENV["HOME"] = old_home
|
||||
end
|
||||
end
|
||||
|
||||
it "should copy the source to the destination" do
|
||||
pending "setup paths"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,23 +0,0 @@
|
|||
require File.expand_path("../../../base", __FILE__)
|
||||
|
||||
describe Vagrant::Downloaders::HTTP do
|
||||
let(:ui) { double("ui") }
|
||||
let(:instance) { described_class.new(ui) }
|
||||
|
||||
describe "matching" do
|
||||
it "should match URLs" do
|
||||
described_class.match?("http://google.com/foo.box").should be
|
||||
described_class.match?("https://google.com/foo.box").should be
|
||||
described_class.match?("http://foo:bar@google.com/foo.box").should be
|
||||
described_class.match?("http://google.com:8500/foo.box").should be
|
||||
end
|
||||
|
||||
it "should not match file:// URIs" do
|
||||
described_class.match?("file://#{__FILE__}").should_not be
|
||||
end
|
||||
end
|
||||
|
||||
describe "downloading" do
|
||||
# Integration tests only.
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue