Add some docstrings and logging
This commit is contained in:
parent
fffc555faf
commit
d6a88f666f
@ -58,6 +58,7 @@ module Vagrant
|
||||
# @param [Pathname] directory The directory where this box exists on
|
||||
# disk.
|
||||
# @param [String] metadata_url Metadata URL for box
|
||||
# @param [Hook] hook A hook to apply to the box downloader, for example, for authentication
|
||||
def initialize(name, provider, version, directory, metadata_url: nil, hook: nil)
|
||||
@name = name
|
||||
@version = version
|
||||
|
||||
@ -59,7 +59,7 @@ module Vagrant
|
||||
@ca_cert = options[:ca_cert]
|
||||
@ca_path = options[:ca_path]
|
||||
@continue = options[:continue]
|
||||
@headers = options[:headers]
|
||||
@headers = Array(options[:headers])
|
||||
@insecure = options[:insecure]
|
||||
@ui = options[:ui]
|
||||
@client_cert = options[:client_cert]
|
||||
|
||||
@ -13,6 +13,8 @@ module VagrantPlugins
|
||||
module CloudCommand
|
||||
class AddDownloaderAuthentication < AddAuthentication
|
||||
|
||||
@@logger = Log4r::Logger.new("vagrant::clout::add_download_authentication")
|
||||
|
||||
def call(env)
|
||||
client = Client.new(env[:env])
|
||||
token = client.token
|
||||
@ -38,8 +40,9 @@ module VagrantPlugins
|
||||
self.class.custom_host_notified!
|
||||
end
|
||||
|
||||
if !Array(env[:downloader].headers).any? { |h| h.include?("Authorization") }
|
||||
env[:downloader].headers ||= []
|
||||
if Array(env[:downloader].headers).any? { |h| h.include?("Authorization") }
|
||||
@@logger.info("Not adding an authentication header, one already found")
|
||||
else
|
||||
env[:downloader].headers << "Authorization: Bearer #{token}"
|
||||
end
|
||||
end
|
||||
|
||||
@ -36,13 +36,13 @@ describe VagrantPlugins::CloudCommand::AddDownloaderAuthentication do
|
||||
|
||||
env[:downloader] = dwnloader
|
||||
subject.call(env)
|
||||
expect(env[:downloader].headers.nil?).to eq(true)
|
||||
expect(env[:downloader].headers.empty?).to eq(true)
|
||||
end
|
||||
|
||||
it "does nothing if we aren't logged in" do
|
||||
env[:downloader] = dwnloader
|
||||
subject.call(env)
|
||||
expect(env[:downloader].headers.nil?).to eq(true)
|
||||
expect(env[:downloader].headers.empty?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
@ -117,7 +117,7 @@ describe VagrantPlugins::CloudCommand::AddDownloaderAuthentication do
|
||||
subject.call(env)
|
||||
|
||||
expect(env[:downloader].source).to eq(file_path)
|
||||
expect(env[:downloader].headers).to eq(nil)
|
||||
expect(env[:downloader].headers.empty?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
@ -149,7 +149,7 @@ describe VagrantPlugins::CloudCommand::AddDownloaderAuthentication do
|
||||
VagrantPlugins::CloudCommand::Client.new(iso_env).store_token(token)
|
||||
env[:downloader] = dwnloader
|
||||
subject.call(env)
|
||||
expect(env[:downloader].headers).to eq(nil)
|
||||
expect(env[:downloader].headers.empty?).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user