Vagrant::Box.load_metadata did not provide a way to specify the HTTPS download options that could be specified when downloading boxes (ca cert, ca path, client cert, insecure). As a result, while it was possible to add a box whose metadata file needed to be downloaded with one of those options specified, it was impossible to check for updates. The following changes have been made to address the situation: 1. Create a DownloadMixins module to provide the --insecure, --cacert, --capth, and --cert command line options to all of `vagrant box add`, `vagrant box update`, and `vagrant box outdated`. 2. Extend `Vagrant::Box.has_update?` and `Vagrant::Box.load_metadata` to accept said download options. 3. Extend `box outdated` and `box update` commands to pass download options down. 4. Extend `Vagrant::Builtin::Action::BoxCheckOutdated` to honour download options. 5. Options specified on the command line take precedence over options specified in the machine configuration, if any. 6. Fix bug in `vagrant box add` where client cert was being passed down using the wrong environment key. 7. Unit test coverage in update_test and box_check_outdated_test. Resolves #4420
97 lines
3.0 KiB
Ruby
97 lines
3.0 KiB
Ruby
require 'optparse'
|
|
|
|
require_relative 'download_mixins'
|
|
|
|
module VagrantPlugins
|
|
module CommandBox
|
|
module Command
|
|
class Add < Vagrant.plugin("2", :command)
|
|
include DownloadMixins
|
|
|
|
def execute
|
|
options = {}
|
|
|
|
opts = OptionParser.new do |o|
|
|
o.banner = "Usage: vagrant box add [options] <name, url, or path>"
|
|
o.separator ""
|
|
o.separator "Options:"
|
|
o.separator ""
|
|
|
|
o.on("-c", "--clean", "Clean any temporary download files") do |c|
|
|
options[:clean] = c
|
|
end
|
|
|
|
o.on("-f", "--force", "Overwrite an existing box if it exists") do |f|
|
|
options[:force] = f
|
|
end
|
|
|
|
build_download_options(o, options)
|
|
|
|
o.on("--provider PROVIDER", String, "Provider the box should satisfy") do |p|
|
|
options[:provider] = p
|
|
end
|
|
|
|
o.on("--box-version VERSION", String, "Constrain version of the added box") do |v|
|
|
options[:version] = v
|
|
end
|
|
|
|
o.separator ""
|
|
o.separator "The box descriptor can be the name of a box on Vagrant Cloud,"
|
|
o.separator "or a URL, or a local .box file, or a local .json file containing"
|
|
o.separator "the catalog metadata."
|
|
o.separator ""
|
|
o.separator "The options below only apply if you're adding a box file directly,"
|
|
o.separator "and not using a Vagrant server or a box structured like 'user/box':"
|
|
o.separator ""
|
|
|
|
o.on("--checksum CHECKSUM", String, "Checksum for the box") do |c|
|
|
options[:checksum] = c
|
|
end
|
|
|
|
o.on("--checksum-type TYPE", String, "Checksum type (md5, sha1, sha256)") do |c|
|
|
options[:checksum_type] = c.to_sym
|
|
end
|
|
|
|
o.on("--name BOX", String, "Name of the box") do |n|
|
|
options[:name] = n
|
|
end
|
|
end
|
|
|
|
# Parse the options
|
|
argv = parse_options(opts)
|
|
return if !argv
|
|
if argv.empty? || argv.length > 2
|
|
raise Vagrant::Errors::CLIInvalidUsage,
|
|
help: opts.help.chomp
|
|
end
|
|
|
|
url = argv[0]
|
|
if argv.length == 2
|
|
options[:name] = argv[0]
|
|
url = argv[1]
|
|
end
|
|
|
|
@env.action_runner.run(Vagrant::Action.action_box_add, {
|
|
box_url: url,
|
|
box_name: options[:name],
|
|
box_provider: options[:provider],
|
|
box_version: options[:version],
|
|
box_checksum_type: options[:checksum_type],
|
|
box_checksum: options[:checksum],
|
|
box_clean: options[:clean],
|
|
box_force: options[:force],
|
|
box_download_ca_cert: options[:ca_cert],
|
|
box_download_ca_path: options[:ca_path],
|
|
box_client_cert: options[:client_cert],
|
|
box_download_insecure: options[:insecure],
|
|
ui: Vagrant::UI::Prefixed.new(@env.ui, "box"),
|
|
})
|
|
|
|
# Success, exit status 0
|
|
0
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|