Continue if entity already exists with publish command
This commit is contained in:
parent
83bd592e30
commit
3c45acc35f
|
@ -34,6 +34,7 @@ module Vagrant
|
||||||
redirect_notify = false
|
redirect_notify = false
|
||||||
logger.info("download redirected to #{location}")
|
logger.info("download redirected to #{location}")
|
||||||
source_uri = URI.parse(source)
|
source_uri = URI.parse(source)
|
||||||
|
# TODO: shouldn't this be....`.first`?
|
||||||
source_host = source_uri.host.to_s.split(".", 2).last
|
source_host = source_uri.host.to_s.split(".", 2).last
|
||||||
location_host = location_uri.host.to_s.split(".", 2).last
|
location_host = location_uri.host.to_s.split(".", 2).last
|
||||||
if !redirect_notify && location_host != source_host && !SILENCED_HOSTS.include?(location_host)
|
if !redirect_notify && location_host != source_host && !SILENCED_HOSTS.include?(location_host)
|
||||||
|
|
|
@ -67,7 +67,7 @@ module VagrantPlugins
|
||||||
def publish_box(org, box_name, version, provider_name, box_file, options, access_token)
|
def publish_box(org, box_name, version, provider_name, box_file, options, access_token)
|
||||||
server_url = VagrantPlugins::CloudCommand::Util.api_server_url
|
server_url = VagrantPlugins::CloudCommand::Util.api_server_url
|
||||||
|
|
||||||
@env.ui.warn("You are about to create a box on Vagrant Cloud with the following options:\n")
|
@env.ui.warn("You are about to publish a box on Vagrant Cloud with the following options:\n")
|
||||||
box_opts = " #{org}/#{box_name}: (v#{version}) for provider '#{provider_name}'\n"
|
box_opts = " #{org}/#{box_name}: (v#{version}) for provider '#{provider_name}'\n"
|
||||||
box_opts << " Private: true\n" if options[:private]
|
box_opts << " Private: true\n" if options[:private]
|
||||||
box_opts << " Automatic Release: true\n" if options[:release]
|
box_opts << " Automatic Release: true\n" if options[:release]
|
||||||
|
@ -89,13 +89,50 @@ module VagrantPlugins
|
||||||
provider = VagrantCloud::Provider.new(cloud_version, provider_name, nil, options[:url], org, box_name, access_token)
|
provider = VagrantCloud::Provider.new(cloud_version, provider_name, nil, options[:url], org, box_name, access_token)
|
||||||
|
|
||||||
ui = Vagrant::UI::Prefixed.new(@env.ui, "cloud")
|
ui = Vagrant::UI::Prefixed.new(@env.ui, "cloud")
|
||||||
|
|
||||||
begin
|
begin
|
||||||
ui.info(I18n.t("cloud_command.publish.box_create"))
|
ui.info(I18n.t("cloud_command.publish.box_create"))
|
||||||
box.create
|
box.create
|
||||||
|
rescue VagrantCloud::ClientError => e
|
||||||
|
if e.error_code == 422
|
||||||
|
ui.warn("Box already exists, updating instead...")
|
||||||
|
box.update(options)
|
||||||
|
else
|
||||||
|
@env.ui.error(I18n.t("cloud_command.errors.publish.fail", org: org, box_name: box_name))
|
||||||
|
@env.ui.error(e)
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
ui.info(I18n.t("cloud_command.publish.version_create"))
|
ui.info(I18n.t("cloud_command.publish.version_create"))
|
||||||
cloud_version.create_version
|
cloud_version.create_version
|
||||||
|
rescue VagrantCloud::ClientError => e
|
||||||
|
if e.error_code == 422
|
||||||
|
ui.warn("Version already exists, updating instead...")
|
||||||
|
cloud_version.update
|
||||||
|
else
|
||||||
|
@env.ui.error(I18n.t("cloud_command.errors.publish.fail", org: org, box_name: box_name))
|
||||||
|
@env.ui.error(e)
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
ui.info(I18n.t("cloud_command.publish.provider_create"))
|
ui.info(I18n.t("cloud_command.publish.provider_create"))
|
||||||
provider.create_provider
|
provider.create_provider
|
||||||
|
rescue VagrantCloud::ClientError => e
|
||||||
|
if e.error_code == 422
|
||||||
|
ui.warn("Provider already exists, updating instead...")
|
||||||
|
provider.update
|
||||||
|
else
|
||||||
|
@env.ui.error(I18n.t("cloud_command.errors.publish.fail", org: org, box_name: box_name))
|
||||||
|
@env.ui.error(e)
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
if !options[:url]
|
if !options[:url]
|
||||||
box_file = File.absolute_path(box_file)
|
box_file = File.absolute_path(box_file)
|
||||||
ui.info(I18n.t("cloud_command.publish.upload_provider", file: box_file))
|
ui.info(I18n.t("cloud_command.publish.upload_provider", file: box_file))
|
||||||
|
|
|
@ -47,7 +47,7 @@ describe VagrantPlugins::CloudCommand::AuthCommand::Command::Whoami do
|
||||||
|
|
||||||
it "returns 1 if encountering an error making request" do
|
it "returns 1 if encountering an error making request" do
|
||||||
allow(account).to receive(:validate_token).
|
allow(account).to receive(:validate_token).
|
||||||
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message"))
|
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message", 404))
|
||||||
expect(subject.execute).to eq(1)
|
expect(subject.execute).to eq(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -54,7 +54,7 @@ describe VagrantPlugins::CloudCommand::BoxCommand::Command::Create do
|
||||||
.and_return(box)
|
.and_return(box)
|
||||||
|
|
||||||
allow(box).to receive(:create).
|
allow(box).to receive(:create).
|
||||||
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message"))
|
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message", 422))
|
||||||
expect(subject.execute).to eq(1)
|
expect(subject.execute).to eq(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -55,7 +55,7 @@ describe VagrantPlugins::CloudCommand::BoxCommand::Command::Delete do
|
||||||
.and_return(box)
|
.and_return(box)
|
||||||
|
|
||||||
allow(box).to receive(:delete).
|
allow(box).to receive(:delete).
|
||||||
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message"))
|
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message", 404))
|
||||||
expect(subject.execute).to eq(1)
|
expect(subject.execute).to eq(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -56,7 +56,7 @@ describe VagrantPlugins::CloudCommand::BoxCommand::Command::Show do
|
||||||
.and_return(box)
|
.and_return(box)
|
||||||
|
|
||||||
allow(box).to receive(:read).
|
allow(box).to receive(:read).
|
||||||
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message"))
|
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message", 404))
|
||||||
expect(subject.execute).to eq(1)
|
expect(subject.execute).to eq(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -57,7 +57,7 @@ describe VagrantPlugins::CloudCommand::BoxCommand::Command::Update do
|
||||||
|
|
||||||
allow(box).to receive(:update).
|
allow(box).to receive(:update).
|
||||||
with(organization: "vagrant", name: "box-name", description: "update", short_description: "short").
|
with(organization: "vagrant", name: "box-name", description: "update", short_description: "short").
|
||||||
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message"))
|
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message", 404))
|
||||||
expect(subject.execute).to eq(1)
|
expect(subject.execute).to eq(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -63,7 +63,7 @@ describe VagrantPlugins::CloudCommand::ProviderCommand::Command::Create do
|
||||||
and_return(provider)
|
and_return(provider)
|
||||||
|
|
||||||
allow(provider).to receive(:create_provider).
|
allow(provider).to receive(:create_provider).
|
||||||
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message"))
|
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message", 422))
|
||||||
expect(subject.execute).to eq(1)
|
expect(subject.execute).to eq(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -63,7 +63,7 @@ describe VagrantPlugins::CloudCommand::ProviderCommand::Command::Delete do
|
||||||
and_return(provider)
|
and_return(provider)
|
||||||
|
|
||||||
allow(provider).to receive(:delete).
|
allow(provider).to receive(:delete).
|
||||||
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message"))
|
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message", 404))
|
||||||
expect(subject.execute).to eq(1)
|
expect(subject.execute).to eq(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -63,7 +63,7 @@ describe VagrantPlugins::CloudCommand::ProviderCommand::Command::Update do
|
||||||
and_return(provider)
|
and_return(provider)
|
||||||
|
|
||||||
allow(provider).to receive(:update).
|
allow(provider).to receive(:update).
|
||||||
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message"))
|
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message", 404))
|
||||||
expect(subject.execute).to eq(1)
|
expect(subject.execute).to eq(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -67,9 +67,21 @@ describe VagrantPlugins::CloudCommand::Command::Publish do
|
||||||
and_return(uploader)
|
and_return(uploader)
|
||||||
allow(uploader).to receive(:upload!)
|
allow(uploader).to receive(:upload!)
|
||||||
allow(box).to receive(:create).
|
allow(box).to receive(:create).
|
||||||
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message"))
|
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message", 404))
|
||||||
expect(subject.execute).to eq(1)
|
expect(subject.execute).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "calls update if entity already exists" do
|
||||||
|
allow(provider).to receive(:upload_url).and_return("http://upload.here/there")
|
||||||
|
allow(Vagrant::Util::Uploader).to receive(:new).
|
||||||
|
with("http://upload.here/there", "/full/path/to/the/virtualbox.box", {ui: anything}).
|
||||||
|
and_return(uploader)
|
||||||
|
allow(uploader).to receive(:upload!)
|
||||||
|
allow(box).to receive(:create).
|
||||||
|
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message", 422))
|
||||||
|
expect(box).to receive(:update)
|
||||||
|
expect(subject.execute).to eq(0)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with arguments and releasing a box" do
|
context "with arguments and releasing a box" do
|
||||||
|
|
|
@ -45,7 +45,7 @@ describe VagrantPlugins::CloudCommand::Command::Search do
|
||||||
allow(VagrantCloud::Search).to receive(:new).
|
allow(VagrantCloud::Search).to receive(:new).
|
||||||
and_return(search)
|
and_return(search)
|
||||||
allow(search).to receive(:search).
|
allow(search).to receive(:search).
|
||||||
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message"))
|
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message", 404))
|
||||||
|
|
||||||
expect(subject.execute).to eq(1)
|
expect(subject.execute).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
|
@ -58,7 +58,7 @@ describe VagrantPlugins::CloudCommand::VersionCommand::Command::Create do
|
||||||
and_return(version)
|
and_return(version)
|
||||||
|
|
||||||
allow(version).to receive(:create_version).
|
allow(version).to receive(:create_version).
|
||||||
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message"))
|
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message", 422))
|
||||||
expect(subject.execute).to eq(1)
|
expect(subject.execute).to eq(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,7 +59,7 @@ describe VagrantPlugins::CloudCommand::VersionCommand::Command::Delete do
|
||||||
and_return(version)
|
and_return(version)
|
||||||
|
|
||||||
allow(version).to receive(:delete).
|
allow(version).to receive(:delete).
|
||||||
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message"))
|
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message", 404))
|
||||||
expect(subject.execute).to eq(1)
|
expect(subject.execute).to eq(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,7 +59,7 @@ describe VagrantPlugins::CloudCommand::VersionCommand::Command::Release do
|
||||||
and_return(version)
|
and_return(version)
|
||||||
|
|
||||||
allow(version).to receive(:release).
|
allow(version).to receive(:release).
|
||||||
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message"))
|
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message", 404))
|
||||||
expect(subject.execute).to eq(1)
|
expect(subject.execute).to eq(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,7 +59,7 @@ describe VagrantPlugins::CloudCommand::VersionCommand::Command::Revoke do
|
||||||
and_return(version)
|
and_return(version)
|
||||||
|
|
||||||
expect(version).to receive(:revoke).
|
expect(version).to receive(:revoke).
|
||||||
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message"))
|
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message", 404))
|
||||||
expect(subject.execute).to eq(1)
|
expect(subject.execute).to eq(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -58,7 +58,7 @@ describe VagrantPlugins::CloudCommand::VersionCommand::Command::Update do
|
||||||
and_return(version)
|
and_return(version)
|
||||||
|
|
||||||
allow(version).to receive(:update).
|
allow(version).to receive(:update).
|
||||||
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message"))
|
and_raise(VagrantCloud::ClientError.new("Fail Message", "Message", 404))
|
||||||
expect(subject.execute).to eq(1)
|
expect(subject.execute).to eq(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue