Add config.vm.box_server_url setting
This commits adds a new config setting `config.vm.box_server_url` to set the URL of a local VagrantCloud instance in the Vagrantfile. If the environment variable `VAGRANT_SERVER_URL` is set, it will still be preferred.
This commit is contained in:
parent
1615325e46
commit
6def193567
|
@ -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