Use the server url helper method within the client

Some client setup locations where not using the custom helper
    method for the vagrant server URL value so they have been
    updated. The api path is also appended if it is not set for
    custom server URLs
This commit is contained in:
Chris Roberts 2021-03-15 15:23:14 -07:00
parent d3fffd65d2
commit d580fbbee2
4 changed files with 23 additions and 8 deletions

View File

@ -18,6 +18,7 @@ module VagrantPlugins
###################################################################### ######################################################################
APP = "app".freeze APP = "app".freeze
include Util
include Vagrant::Util::Presence include Vagrant::Util::Presence
attr_accessor :client attr_accessor :client
@ -32,7 +33,10 @@ module VagrantPlugins
def initialize(env) def initialize(env)
@logger = Log4r::Logger.new("vagrant::cloud::client") @logger = Log4r::Logger.new("vagrant::cloud::client")
@env = env @env = env
@client = VagrantCloud::Client.new(access_token: token) @client = VagrantCloud::Client.new(
access_token: token,
url_base: api_server_url
)
end end
# Removes the token, effectively logging the user out. # Removes the token, effectively logging the user out.
@ -72,7 +76,10 @@ module VagrantPlugins
password: password, description: description, code: code) password: password, description: description, code: code)
Vagrant::Util::CredentialScrubber.sensitive(r[:token]) 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] r[:token]
end end
end end
@ -106,7 +113,7 @@ module VagrantPlugins
end end
# Reset after we store the token since this is now _our_ token # 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 nil
end end

View File

@ -112,7 +112,7 @@ en:
Failed to update box %{org}/%{box_name} Failed to update box %{org}/%{box_name}
whoami: whoami:
read_error: |- read_error: |-
Failed to read organization %{org} Failed to locate account information
provider: provider:
create_fail: |- create_fail: |-
Failed to create provider %{provider} on box %{org}/%{box_name} for version %{version} Failed to create provider %{provider} on box %{org}/%{box_name} for version %{version}

View File

@ -5,8 +5,16 @@ module VagrantPlugins
def api_server_url def api_server_url
if Vagrant.server_url == Vagrant::DEFAULT_SERVER_URL if Vagrant.server_url == Vagrant::DEFAULT_SERVER_URL
return "#{Vagrant.server_url}/api/v1" return "#{Vagrant.server_url}/api/v1"
else end
return Vagrant.server_url 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
end end

View File

@ -101,7 +101,7 @@ describe VagrantPlugins::CloudCommand::Client do
end end
it "should create a new internal client" do 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 subject.login
end end
@ -174,7 +174,7 @@ describe VagrantPlugins::CloudCommand::Client do
end end
it "should create a new internal client with token" do 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) subject.store_token(new_token)
end end