From 5e2549fe8b72ab261580808d908c6b5ae479a0b1 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 3 Apr 2013 11:57:40 -0700 Subject: [PATCH] Add "--insecure" flag for downloader --- config/default.rb | 3 ++- lib/vagrant/action/builtin/box_add.rb | 6 +++++- lib/vagrant/util/downloader.rb | 7 +++++-- plugins/commands/box/command/add.rb | 7 ++++++- plugins/kernel_v2/config/downloader.rb | 17 +++++++++++++++++ plugins/kernel_v2/plugin.rb | 5 +++++ 6 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 plugins/kernel_v2/config/downloader.rb diff --git a/config/default.rb b/config/default.rb index 135fc48db..b86db2b6c 100644 --- a/config/default.rb +++ b/config/default.rb @@ -1,5 +1,6 @@ Vagrant.configure("2") do |config| - # default config goes here + config.downloader.insecure = false + config.vagrant.host = :detect config.ssh.username = "vagrant" diff --git a/lib/vagrant/action/builtin/box_add.rb b/lib/vagrant/action/builtin/box_add.rb index 4576b9731..23ff4b83b 100644 --- a/lib/vagrant/action/builtin/box_add.rb +++ b/lib/vagrant/action/builtin/box_add.rb @@ -24,12 +24,16 @@ module Vagrant url = "file:#{url}" end + downloader_options = {} + downloader_options[:insecure] = env[:box_download_insecure] + downloader_options[:ui] = env[:ui] + # Download the box to a temporary path. We store the temporary # path as an instance variable so that the `#recover` method can # access it. env[:ui].info(I18n.t("vagrant.actions.box.download.downloading")) begin - downloader = Util::Downloader.new(url, @temp_path, :ui => env[:ui]) + downloader = Util::Downloader.new(url, @temp_path, downloader_options) downloader.download! rescue Errors::DownloaderInterrupted # The downloader was interrupted, so just return, because that diff --git a/lib/vagrant/util/downloader.rb b/lib/vagrant/util/downloader.rb index 3cfbf5656..d815b692a 100644 --- a/lib/vagrant/util/downloader.rb +++ b/lib/vagrant/util/downloader.rb @@ -16,6 +16,7 @@ module Vagrant # Get the various optional values options ||= {} + @insecure = options[:insecure] @ui = options[:ui] end @@ -29,10 +30,12 @@ module Vagrant # Build the list of parameters to execute with cURL options = [ "--fail", - "--output", @destination, - @source + "--output", @destination ] + options << "--insecure" if @insecure + options << @source + # This variable can contain the proc that'll be sent to # the subprocess execute. data_proc = nil diff --git a/plugins/commands/box/command/add.rb b/plugins/commands/box/command/add.rb index 42ab6e583..7f6829c7d 100644 --- a/plugins/commands/box/command/add.rb +++ b/plugins/commands/box/command/add.rb @@ -15,6 +15,10 @@ module VagrantPlugins options[:force] = f end + o.on("--insecure", "If set, SSL certs will not be validated.") do |i| + options[:insecure] = i + end + o.on("--provider provider", String, "The provider that backs the box.") do |p| options[:provider] = p @@ -34,7 +38,8 @@ module VagrantPlugins :box_name => argv[0], :box_provider => provider, :box_url => argv[1], - :box_force => options[:force] + :box_force => options[:force], + :box_download_insecure => options[:insecure], }) # Success, exit status 0 diff --git a/plugins/kernel_v2/config/downloader.rb b/plugins/kernel_v2/config/downloader.rb new file mode 100644 index 000000000..ddf60032c --- /dev/null +++ b/plugins/kernel_v2/config/downloader.rb @@ -0,0 +1,17 @@ +module VagrantPlugins + module Kernel_V2 + class DownloaderConfig < Vagrant.plugin("2", :config) + attr_accessor :insecure + + def initialize + super + + @insecure = UNSET_VALUE + end + + def finalize! + @insecure = false if @insecure == UNSET_VALUE + end + end + end +end diff --git a/plugins/kernel_v2/plugin.rb b/plugins/kernel_v2/plugin.rb index 55cfcc0dc..5e010cfa9 100644 --- a/plugins/kernel_v2/plugin.rb +++ b/plugins/kernel_v2/plugin.rb @@ -15,6 +15,11 @@ module VagrantPlugins # "kernel_v1", none of these configuration classes are upgradable. # This is by design, since we can't be sure if they're upgradable # until another version is available. + config("downloader") do + require File.expand_path("../config/downloader", __FILE__) + DownloaderConfig + end + config("ssh") do require File.expand_path("../config/ssh", __FILE__) SSHConfig