2012-04-19 20:59:48 +00:00
|
|
|
require 'optparse'
|
|
|
|
|
Add HTTPS download options to `box update` and `box outdated`
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
2014-09-08 03:45:32 +00:00
|
|
|
require_relative 'download_mixins'
|
|
|
|
|
2012-04-19 20:59:48 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module CommandBox
|
|
|
|
module Command
|
2012-11-07 05:05:14 +00:00
|
|
|
class Add < Vagrant.plugin("2", :command)
|
Add HTTPS download options to `box update` and `box outdated`
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
2014-09-08 03:45:32 +00:00
|
|
|
include DownloadMixins
|
|
|
|
|
2012-04-19 20:59:48 +00:00
|
|
|
def execute
|
|
|
|
options = {}
|
|
|
|
|
2012-08-18 23:13:14 +00:00
|
|
|
opts = OptionParser.new do |o|
|
2014-05-25 19:54:48 +00:00
|
|
|
o.banner = "Usage: vagrant box add [options] <name, url, or path>"
|
2014-02-08 08:20:50 +00:00
|
|
|
o.separator ""
|
|
|
|
o.separator "Options:"
|
2012-08-18 23:13:14 +00:00
|
|
|
o.separator ""
|
2012-04-19 20:59:48 +00:00
|
|
|
|
2014-01-23 18:45:39 +00:00
|
|
|
o.on("-c", "--clean", "Clean any temporary download files") do |c|
|
2013-11-23 23:55:52 +00:00
|
|
|
options[:clean] = c
|
|
|
|
end
|
|
|
|
|
2014-02-08 08:20:50 +00:00
|
|
|
o.on("-f", "--force", "Overwrite an existing box if it exists") do |f|
|
2012-04-19 20:59:48 +00:00
|
|
|
options[:force] = f
|
|
|
|
end
|
2013-01-12 05:24:57 +00:00
|
|
|
|
Add HTTPS download options to `box update` and `box outdated`
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
2014-09-08 03:45:32 +00:00
|
|
|
build_download_options(o, options)
|
2013-05-21 10:41:15 +00:00
|
|
|
|
2014-09-01 09:23:37 +00:00
|
|
|
o.on("--location-trusted", "Trust 'Location' header from HTTP redirects and use the same credentials for subsequent urls as for the initial one") do |l|
|
|
|
|
options[:location_trusted] = l
|
|
|
|
end
|
|
|
|
|
2014-02-08 08:20:50 +00:00
|
|
|
o.on("--provider PROVIDER", String, "Provider the box should satisfy") do |p|
|
2013-01-12 05:24:57 +00:00
|
|
|
options[:provider] = p
|
|
|
|
end
|
2014-01-23 18:45:39 +00:00
|
|
|
|
2014-02-08 08:20:50 +00:00
|
|
|
o.on("--box-version VERSION", String, "Constrain version of the added box") do |v|
|
2014-01-23 21:27:50 +00:00
|
|
|
options[:version] = v
|
|
|
|
end
|
|
|
|
|
2014-05-24 19:37:47 +00:00
|
|
|
o.separator ""
|
2017-05-22 16:42:31 +00:00
|
|
|
o.separator "The box descriptor can be the name of a box on HashiCorp's Vagrant Cloud,"
|
2014-05-24 19:37:47 +00:00
|
|
|
o.separator "or a URL, or a local .box file, or a local .json file containing"
|
|
|
|
o.separator "the catalog metadata."
|
2014-01-23 18:45:39 +00:00
|
|
|
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 ""
|
|
|
|
|
2014-02-08 08:20:50 +00:00
|
|
|
o.on("--checksum CHECKSUM", String, "Checksum for the box") do |c|
|
2014-01-23 18:45:39 +00:00
|
|
|
options[:checksum] = c
|
|
|
|
end
|
|
|
|
|
2014-02-08 08:20:50 +00:00
|
|
|
o.on("--checksum-type TYPE", String, "Checksum type (md5, sha1, sha256)") do |c|
|
2014-01-23 18:45:39 +00:00
|
|
|
options[:checksum_type] = c.to_sym
|
|
|
|
end
|
|
|
|
|
2014-02-08 08:20:50 +00:00
|
|
|
o.on("--name BOX", String, "Name of the box") do |n|
|
2014-01-23 18:45:39 +00:00
|
|
|
options[:name] = n
|
|
|
|
end
|
2012-04-19 20:59:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Parse the options
|
|
|
|
argv = parse_options(opts)
|
|
|
|
return if !argv
|
2014-01-23 18:45:39 +00:00
|
|
|
if argv.empty? || argv.length > 2
|
|
|
|
raise Vagrant::Errors::CLIInvalidUsage,
|
|
|
|
help: opts.help.chomp
|
|
|
|
end
|
2012-04-19 20:59:48 +00:00
|
|
|
|
2014-01-23 18:45:39 +00:00
|
|
|
url = argv[0]
|
|
|
|
if argv.length == 2
|
|
|
|
options[:name] = argv[0]
|
|
|
|
url = argv[1]
|
|
|
|
end
|
2013-01-17 06:52:44 +00:00
|
|
|
|
2012-08-18 23:13:14 +00:00
|
|
|
@env.action_runner.run(Vagrant::Action.action_box_add, {
|
2014-01-23 18:45:39 +00:00
|
|
|
box_url: url,
|
|
|
|
box_name: options[:name],
|
|
|
|
box_provider: options[:provider],
|
2014-01-23 21:27:50 +00:00
|
|
|
box_version: options[:version],
|
2014-01-23 18:45:39 +00:00
|
|
|
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],
|
2014-05-19 15:41:13 +00:00
|
|
|
box_download_ca_path: options[:ca_path],
|
2019-01-28 14:45:24 +00:00
|
|
|
box_download_client_cert: options[:client_cert],
|
2014-01-23 18:45:39 +00:00
|
|
|
box_download_insecure: options[:insecure],
|
2014-09-01 09:23:37 +00:00
|
|
|
box_download_location_trusted: options[:location_trusted],
|
2014-01-24 06:16:20 +00:00
|
|
|
ui: Vagrant::UI::Prefixed.new(@env.ui, "box"),
|
2012-07-10 03:09:54 +00:00
|
|
|
})
|
2012-04-19 20:59:48 +00:00
|
|
|
|
|
|
|
# Success, exit status 0
|
|
|
|
0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|