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
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

View File

@ -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}

View File

@ -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

View File

@ -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