Merge pull request #8876 from mitchellh/vagrantcloud-login-description
command/login: Add description to created token
This commit is contained in:
commit
715b447892
|
@ -40,15 +40,24 @@ module VagrantPlugins
|
|||
# Login logs a user in and returns the token for that user. The token
|
||||
# is _not_ stored unless {#store_token} is called.
|
||||
#
|
||||
# @param [String] user
|
||||
# @param [String] pass
|
||||
# @param [String] username_or_email
|
||||
# @param [String] password
|
||||
# @param [String] description
|
||||
# @return [String] token The access token, or nil if auth failed.
|
||||
def login(user, pass)
|
||||
@logger.info("Logging in '#{user}'")
|
||||
def login(username_or_email, password, description: nil)
|
||||
@logger.info("Logging in '#{username_or_email}'")
|
||||
|
||||
with_error_handling do
|
||||
url = "#{Vagrant.server_url}/api/v1/authenticate"
|
||||
request = { "user" => { "login" => user, "password" => pass } }
|
||||
url = "#{Vagrant.server_url}/api/v1/authenticate"
|
||||
request = {
|
||||
user: {
|
||||
login: username_or_email,
|
||||
password: password
|
||||
},
|
||||
token: {
|
||||
description: description
|
||||
}
|
||||
}
|
||||
|
||||
proxy = nil
|
||||
proxy ||= ENV["HTTPS_PROXY"] || ENV["https_proxy"]
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require 'socket'
|
||||
|
||||
module VagrantPlugins
|
||||
module LoginCommand
|
||||
class Command < Vagrant.plugin("2", "command")
|
||||
|
@ -48,8 +50,9 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
# Ask for the username
|
||||
login = nil
|
||||
password = nil
|
||||
login = nil
|
||||
password = nil
|
||||
description = nil
|
||||
while !login
|
||||
login = @env.ui.ask("Vagrant Cloud Username: ")
|
||||
end
|
||||
|
@ -58,7 +61,14 @@ module VagrantPlugins
|
|||
password = @env.ui.ask("Password (will be hidden): ", echo: false)
|
||||
end
|
||||
|
||||
token = @client.login(login, password)
|
||||
description_default = "Vagrant login from #{Socket.gethostname}"
|
||||
while !description
|
||||
description =
|
||||
@env.ui.ask("Token description (Defaults to #{description_default.inspect}): ")
|
||||
end
|
||||
description = description_default if description.empty?
|
||||
|
||||
token = @client.login(login, password, description: description)
|
||||
if !token
|
||||
@env.ui.error(I18n.t("login_command.invalid_login"))
|
||||
return 1
|
||||
|
|
|
@ -61,6 +61,9 @@ describe VagrantPlugins::LoginCommand::Client do
|
|||
"login" => "foo",
|
||||
"password" => "bar",
|
||||
},
|
||||
"token" => {
|
||||
"description" => "Token description"
|
||||
}
|
||||
}
|
||||
|
||||
response = {
|
||||
|
@ -76,7 +79,8 @@ describe VagrantPlugins::LoginCommand::Client do
|
|||
with(body: JSON.dump(request), headers: headers).
|
||||
to_return(status: 200, body: JSON.dump(response))
|
||||
|
||||
expect(subject.login("foo", "bar")).to eq("baz")
|
||||
expect(subject.login("foo", "bar", description: "Token description"))
|
||||
.to eq("baz")
|
||||
end
|
||||
|
||||
it "returns nil on bad login" do
|
||||
|
|
Loading…
Reference in New Issue