Merge pull request #4282 from Mayflower/feature/config-box_server_url
core: add config.vm.box_server_url setting
This commit is contained in:
commit
98667f06c8
|
@ -53,7 +53,7 @@ module Vagrant
|
|||
next if url[i] !~ /^[^\/]+\/[^\/]+$/
|
||||
|
||||
if !File.file?(url[i])
|
||||
server = Vagrant.server_url
|
||||
server = Vagrant.server_url env[:box_server_url]
|
||||
raise Errors::BoxServerNotSet if !server
|
||||
|
||||
expanded = true
|
||||
|
|
|
@ -60,9 +60,9 @@ module Vagrant
|
|||
# Returns the URL prefix to the server.
|
||||
#
|
||||
# @return [String]
|
||||
def self.server_url
|
||||
def self.server_url(config_server_url=nil)
|
||||
result = ENV["VAGRANT_SERVER_URL"]
|
||||
result = nil if result == ""
|
||||
result = config_server_url if result == "" or result == nil
|
||||
result || DEFAULT_SERVER_URL
|
||||
end
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ module VagrantPlugins
|
|||
attr_accessor :box
|
||||
attr_accessor :box_check_update
|
||||
attr_accessor :box_url
|
||||
attr_accessor :box_server_url
|
||||
attr_accessor :box_version
|
||||
attr_accessor :box_download_ca_cert
|
||||
attr_accessor :box_download_ca_path
|
||||
|
|
|
@ -306,6 +306,53 @@ describe Vagrant::Action::Builtin::BoxAdd do
|
|||
end
|
||||
end
|
||||
|
||||
it "add from shorthand path with configured server url" do
|
||||
box_path = iso_env.box2_file(:virtualbox)
|
||||
td = Pathname.new(Dir.mktmpdir)
|
||||
tf = td.join("mitchellh", "precise64.json")
|
||||
tf.dirname.mkpath
|
||||
tf.open("w") do |f|
|
||||
f.write(<<-RAW)
|
||||
{
|
||||
"name": "mitchellh/precise64",
|
||||
"versions": [
|
||||
{
|
||||
"version": "0.5"
|
||||
},
|
||||
{
|
||||
"version": "0.7",
|
||||
"providers": [
|
||||
{
|
||||
"name": "virtualbox",
|
||||
"url": "#{box_path}"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
RAW
|
||||
end
|
||||
|
||||
with_web_server(tf.dirname) do |port|
|
||||
url = "http://127.0.0.1:#{port}"
|
||||
env[:box_url] = "mitchellh/precise64.json"
|
||||
env[:box_server_url] = url
|
||||
|
||||
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
|
||||
expect(name).to eq("mitchellh/precise64")
|
||||
expect(version).to eq("0.7")
|
||||
expect(checksum(path)).to eq(checksum(box_path))
|
||||
expect(opts[:metadata_url]).to eq(
|
||||
"#{url}/#{env[:box_url]}")
|
||||
true
|
||||
}.and_return(box)
|
||||
|
||||
expect(app).to receive(:call).with(env)
|
||||
|
||||
subject.call(env)
|
||||
end
|
||||
end
|
||||
|
||||
it "authenticates HTTP URLs and adds them" do
|
||||
box_path = iso_env.box2_file(:virtualbox)
|
||||
tf = Tempfile.new(["vagrant", ".json"]).tap do |f|
|
||||
|
|
|
@ -71,6 +71,18 @@ describe Vagrant do
|
|||
expect(subject.server_url).to eq("foo")
|
||||
end
|
||||
end
|
||||
|
||||
it "is the VAGRANT_SERVER_URL value if the server url is configured" do
|
||||
with_temp_env("VAGRANT_SERVER_URL" => "foo") do
|
||||
expect(subject.server_url('bar')).to eq("foo")
|
||||
end
|
||||
end
|
||||
|
||||
it "is the configured server url if VAGRANT_SERVER_URL is not set" do
|
||||
with_temp_env("VAGRANT_SERVER_URL" => nil) do
|
||||
expect(subject.server_url("bar")).to eq("bar")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#user_data_path" do
|
||||
|
|
Loading…
Reference in New Issue