Validate conversion of map to cmd options
This commit is contained in:
parent
7e125969dd
commit
646de433a9
@ -433,7 +433,7 @@ module Vagrant
|
||||
downloader_options[:headers] = ["Accept: application/json"] if opts[:json]
|
||||
downloader_options[:ui] = env[:ui] if opts[:ui]
|
||||
downloader_options[:location_trusted] = env[:box_download_location_trusted]
|
||||
downloader_options[:box_download_options] = env[:box_download_options]
|
||||
downloader_options[:box_extra_download_options] = env[:box_extra_download_options]
|
||||
|
||||
Util::Downloader.new(url, temp_path, downloader_options)
|
||||
end
|
||||
|
||||
@ -67,7 +67,7 @@ module Vagrant
|
||||
box_download_checksum_type = machine.config.vm.box_download_checksum_type
|
||||
box_download_checksum = machine.config.vm.box_download_checksum
|
||||
box_download_location_trusted = machine.config.vm.box_download_location_trusted
|
||||
box_download_options = machine.config.vm.box_download_options
|
||||
box_extra_download_options = machine.config.vm.box_extra_download_options
|
||||
box_formats = machine.provider_options[:box_format] ||
|
||||
machine.provider_name
|
||||
|
||||
@ -93,7 +93,7 @@ module Vagrant
|
||||
box_checksum_type: box_download_checksum_type,
|
||||
box_checksum: box_download_checksum,
|
||||
box_download_location_trusted: box_download_location_trusted,
|
||||
box_download_options: box_download_options,
|
||||
box_extra_download_options: box_extra_download_options,
|
||||
}))
|
||||
rescue Errors::BoxAlreadyExists
|
||||
# Just ignore this, since it means the next part will succeed!
|
||||
|
||||
@ -70,7 +70,7 @@ module Vagrant
|
||||
:sha384 => options[:sha384],
|
||||
:sha512 => options[:sha512]
|
||||
}.compact
|
||||
@extra_download_options = options[:box_download_options]
|
||||
@extra_download_options = options[:box_extra_download_options] || []
|
||||
end
|
||||
|
||||
# This executes the actual download, downloading the source file
|
||||
@ -247,8 +247,7 @@ module Vagrant
|
||||
options << "-u" << @auth if @auth
|
||||
options << "--location-trusted" if @location_trusted
|
||||
|
||||
options.concat(
|
||||
Vagrant::Util::MapCommandOptions.map_to_command_options(@extra_download_options))
|
||||
options.concat(@extra_download_options)
|
||||
|
||||
if @headers
|
||||
Array(@headers).each do |header|
|
||||
|
||||
@ -46,6 +46,7 @@ module VagrantPlugins
|
||||
attr_accessor :usable_port_range
|
||||
attr_reader :provisioners
|
||||
attr_reader :disks
|
||||
attr_reader :box_extra_download_options
|
||||
|
||||
# This is an experimental feature that isn't public yet.
|
||||
attr_accessor :clone
|
||||
@ -68,6 +69,7 @@ module VagrantPlugins
|
||||
@box_download_insecure = UNSET_VALUE
|
||||
@box_download_location_trusted = UNSET_VALUE
|
||||
@box_download_options = UNSET_VALUE
|
||||
@box_extra_download_options = UNSET_VALUE
|
||||
@box_url = UNSET_VALUE
|
||||
@box_version = UNSET_VALUE
|
||||
@clone = UNSET_VALUE
|
||||
@ -470,6 +472,7 @@ module VagrantPlugins
|
||||
@box_url = nil if @box_url == UNSET_VALUE
|
||||
@box_version = nil if @box_version == UNSET_VALUE
|
||||
@box_download_options = {} if @box_download_options == UNSET_VALUE
|
||||
@box_extra_download_options = Vagrant::Util::MapCommandOptions.map_to_command_options(@box_download_options)
|
||||
@clone = nil if @clone == UNSET_VALUE
|
||||
@communicator = nil if @communicator == UNSET_VALUE
|
||||
@graceful_halt_timeout = 60 if @graceful_halt_timeout == UNSET_VALUE
|
||||
@ -721,6 +724,15 @@ module VagrantPlugins
|
||||
errors << I18n.t("vagrant.config.vm.box_download_options_type", type: box_download_options.class.to_s)
|
||||
end
|
||||
|
||||
box_download_options.each do |k, v|
|
||||
# If the value is truthy and
|
||||
# if `box_extra_download_options` does not include the key
|
||||
# then the conversion to extra download options produced an error
|
||||
if v && !box_extra_download_options.include?("--#{k}")
|
||||
errors << I18n.t("vagrant.config.vm.box_download_options_not_converted", missing_key: k)
|
||||
end
|
||||
end
|
||||
|
||||
used_guest_paths = Set.new
|
||||
@__synced_folders.each do |id, options|
|
||||
# If the shared folder is disabled then don't worry about validating it
|
||||
|
||||
@ -1940,6 +1940,8 @@ en:
|
||||
box_missing: "A box must be specified."
|
||||
box_download_options_type: |-
|
||||
Found "box_download_options" specified as type '%{type}', should be a Hash
|
||||
box_download_options_not_converted: |-
|
||||
Something went wrong converting VM config `box_download_options`. Value for provided key '%{missing_key}' is invalid type. Should be String or Bool
|
||||
clone_and_box: "Only one of clone or box can be specified."
|
||||
hostname_invalid_characters: |-
|
||||
The hostname set for the VM '%{name}' should only contain letters, numbers,
|
||||
|
||||
@ -259,7 +259,7 @@ describe Vagrant::Util::Downloader do
|
||||
end
|
||||
|
||||
context "when extra download options specified" do
|
||||
let(:options) { {:box_download_options => {test: "arbitrary"}} }
|
||||
let(:options) { {:box_extra_download_options => ["--test", "arbitrary"]} }
|
||||
subject { described_class.new(source, destination, options) }
|
||||
|
||||
it "inserts the extra download options" do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user