Respect proxy envvars for login command

This commit is contained in:
Seth Vargo 2015-11-23 20:19:45 -05:00
parent 1fd3c955b7
commit bd48d24825
2 changed files with 22 additions and 3 deletions

View File

@ -1,4 +1,5 @@
require "rest_client"
require "vagrant/util/downloader"
module VagrantPlugins
module LoginCommand
@ -45,8 +46,23 @@ module VagrantPlugins
with_error_handling do
url = "#{Vagrant.server_url}/api/v1/authenticate"
request = { "user" => { "login" => user, "password" => pass } }
response = RestClient.post(
url, JSON.dump(request), content_type: :json)
proxy = nil
proxy ||= ENV["HTTPS_PROXY"] || ENV["https_proxy"]
proxy ||= ENV["HTTP_PROXY"] || ENV["http_proxy"]
response = RestClient::Request.execute(
method: :post,
url: url,
payload: JSON.dump(request),
proxy: proxy,
headers: {
accept: :json,
content_type: :json,
user_agent: Vagrant::Util::Downloader::USER_AGENT,
},
)
data = JSON.load(response.to_s)
data["token"]
end

View File

@ -67,7 +67,10 @@ describe VagrantPlugins::LoginCommand::Client do
"token" => "baz",
}
headers = { "Content-Type" => "application/json" }
headers = {
"Accept" => "application/json",
"Content-Type" => "application/json",
}
stub_request(:post, "#{Vagrant.server_url}/api/v1/authenticate").
with(body: JSON.dump(request), headers: headers).