diff --git a/plugins/commands/cloud/client/client.rb b/plugins/commands/cloud/client/client.rb index 0e9452e1d..365973706 100644 --- a/plugins/commands/cloud/client/client.rb +++ b/plugins/commands/cloud/client/client.rb @@ -18,6 +18,7 @@ module VagrantPlugins ###################################################################### APP = "app".freeze + include Util include Vagrant::Util::Presence attr_accessor :client @@ -32,7 +33,10 @@ module VagrantPlugins def initialize(env) @logger = Log4r::Logger.new("vagrant::cloud::client") @env = env - @client = VagrantCloud::Client.new(access_token: token) + @client = VagrantCloud::Client.new( + access_token: token, + url_base: api_server_url + ) end # Removes the token, effectively logging the user out. @@ -72,7 +76,10 @@ module VagrantPlugins password: password, description: description, code: code) Vagrant::Util::CredentialScrubber.sensitive(r[:token]) - @client = VagrantCloud::Client.new(access_token: r[:token]) + @client = VagrantCloud::Client.new( + access_token: r[:token], + url_base: api_server_url + ) r[:token] end end @@ -106,7 +113,7 @@ module VagrantPlugins end # Reset after we store the token since this is now _our_ token - @client = VagrantCloud::Client.new(access_token: token) + @client = VagrantCloud::Client.new(access_token: token, url_base: api_server_url) nil end diff --git a/plugins/commands/cloud/locales/en.yml b/plugins/commands/cloud/locales/en.yml index 451bd8dbe..713282261 100644 --- a/plugins/commands/cloud/locales/en.yml +++ b/plugins/commands/cloud/locales/en.yml @@ -112,7 +112,7 @@ en: Failed to update box %{org}/%{box_name} whoami: read_error: |- - Failed to read organization %{org} + Failed to locate account information provider: create_fail: |- Failed to create provider %{provider} on box %{org}/%{box_name} for version %{version} diff --git a/plugins/commands/cloud/util.rb b/plugins/commands/cloud/util.rb index 355af731d..36856c5ba 100644 --- a/plugins/commands/cloud/util.rb +++ b/plugins/commands/cloud/util.rb @@ -5,8 +5,16 @@ module VagrantPlugins def api_server_url if Vagrant.server_url == Vagrant::DEFAULT_SERVER_URL return "#{Vagrant.server_url}/api/v1" - else - return Vagrant.server_url + end + begin + addr = URI.parse(Vagrant.server_url.to_s) + if addr.path.empty? || addr.path.to_s == "/" + addr.path = "/api/v1" + end + + addr.to_s + rescue URI::Error + Vagrant.server_url end end diff --git a/test/unit/plugins/commands/cloud/client_test.rb b/test/unit/plugins/commands/cloud/client_test.rb index 843d4e93b..c6be8d842 100644 --- a/test/unit/plugins/commands/cloud/client_test.rb +++ b/test/unit/plugins/commands/cloud/client_test.rb @@ -101,7 +101,7 @@ describe VagrantPlugins::CloudCommand::Client do end it "should create a new internal client" do - expect(VagrantCloud::Client).to receive(:new).with(access_token: new_token) + expect(VagrantCloud::Client).to receive(:new).with(access_token: new_token, url_base: anything) subject.login end @@ -174,7 +174,7 @@ describe VagrantPlugins::CloudCommand::Client do end it "should create a new internal client with token" do - expect(VagrantCloud::Client).to receive(:new).with(access_token: new_token) + expect(VagrantCloud::Client).to receive(:new).with(access_token: new_token, url_base: anything) subject.store_token(new_token) end