Merge pull request #12235 from chrisroberts/api-notify-ups
Prevent notification on default store, fix client end point
This commit is contained in:
commit
60323fdd6c
@ -4,6 +4,7 @@ module Vagrant
|
||||
|
||||
# Hosts that do not require notification on redirect
|
||||
SILENCED_HOSTS = [
|
||||
"vagrantcloud-files-production.s3-accelerate.amazonaws.com".freeze,
|
||||
"vagrantcloud.com".freeze,
|
||||
"vagrantup.com".freeze
|
||||
].freeze
|
||||
@ -21,6 +22,7 @@ module Vagrant
|
||||
# Accumulate progress_data
|
||||
progress_data << data
|
||||
|
||||
redirect_notify = false
|
||||
while true
|
||||
# If the download has been redirected and we are no longer downloading
|
||||
# from the original host, notify the user that the target host has
|
||||
@ -30,16 +32,15 @@ module Vagrant
|
||||
if !location.empty?
|
||||
location_uri = URI.parse(location)
|
||||
|
||||
unless location_uri.host.nil?
|
||||
redirect_notify = false
|
||||
if !location_uri.host.nil? && !redirect_notify
|
||||
logger.info("download redirected to #{location}")
|
||||
source_uri = URI.parse(source)
|
||||
source_host = source_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)
|
||||
ui.rewriting do |ui|
|
||||
ui.clear_line
|
||||
ui.detail "Download redirected to host: #{location_uri.host}"
|
||||
if location_host != source_host && !SILENCED_HOSTS.include?(location_host) && !SILENCED_HOSTS.include?(location_uri.host.to_s)
|
||||
ui.rewriting do |_ui|
|
||||
_ui.clear_line
|
||||
_ui.detail "Download redirected to host: #{location_uri.host}"
|
||||
end
|
||||
end
|
||||
redirect_notify = true
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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}
|
||||
|
||||
@ -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)
|
||||
if addr.path.empty? || addr.path.to_s == "/"
|
||||
addr.path = "/api/v1"
|
||||
end
|
||||
|
||||
addr.to_s
|
||||
rescue URI::Error
|
||||
Vagrant.server_url
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -53,16 +53,16 @@ describe VagrantPlugins::CloudCommand::AddDownloaderAuthentication do
|
||||
it "warns when adding token to custom server" do
|
||||
server_url = "https://surprise.com"
|
||||
allow(Vagrant).to receive(:server_url).and_return(server_url)
|
||||
|
||||
|
||||
token = "foobarbaz"
|
||||
VagrantPlugins::CloudCommand::Client.new(iso_env).store_token(token)
|
||||
|
||||
|
||||
expect(subject).to receive(:sleep).once
|
||||
expect(ui).to receive(:warn).once
|
||||
|
||||
|
||||
env[:downloader] = dwnloader
|
||||
subject.call(env)
|
||||
|
||||
|
||||
expect(env[:downloader].headers).to eq(["Authorization: Bearer #{token}"])
|
||||
end
|
||||
end
|
||||
@ -97,11 +97,11 @@ describe VagrantPlugins::CloudCommand::AddDownloaderAuthentication do
|
||||
let(:auth_header) { "Authorization Bearer: token" }
|
||||
let(:other_header) {"some: thing"}
|
||||
let(:dwnloader) { Vagrant::Util::Downloader.new(server_url, "/some/path", {headers: [other_header]}) }
|
||||
|
||||
|
||||
it "appends the auth header" do
|
||||
token = "foobarbaz"
|
||||
VagrantPlugins::CloudCommand::Client.new(iso_env).store_token(token)
|
||||
|
||||
|
||||
env[:downloader] = dwnloader
|
||||
subject.call(env)
|
||||
|
||||
@ -115,7 +115,7 @@ describe VagrantPlugins::CloudCommand::AddDownloaderAuthentication do
|
||||
it "returns original urls when not modified" do
|
||||
env[:downloader] = dwnloader
|
||||
subject.call(env)
|
||||
|
||||
|
||||
expect(env[:downloader].source).to eq(file_path)
|
||||
expect(env[:downloader].headers.empty?).to eq(true)
|
||||
end
|
||||
@ -125,7 +125,7 @@ describe VagrantPlugins::CloudCommand::AddDownloaderAuthentication do
|
||||
dwnloader.headers << auth_header
|
||||
token = "foobarbaz"
|
||||
VagrantPlugins::CloudCommand::Client.new(iso_env).store_token(token)
|
||||
|
||||
|
||||
env[:downloader] = dwnloader
|
||||
subject.call(env)
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user