class CF::Start::Login
Public Instance Methods
login()
click to toggle source
# File lib/cf/cli/start/login.rb, line 21 def login show_context expected_prompts = if input[:sso] [:username, :passcode] else [:username, :password] end credentials = { :username => input[:username], :password => input[:password] } prompts = client.login_prompts # ask username first if prompts.key?(:username) type, label = prompts.delete(:username) credentials[:username] ||= ask_prompt(type, label) end info = target_info auth_token = nil authenticated = false failed = false remaining_attempts = 3 until authenticated || remaining_attempts <= 0 remaining_attempts -= 1 failed = false unless force? ask_prompts(credentials, prompts.slice(*expected_prompts)) end with_progress("Authenticating") do |s| begin auth_token = client.login(credentials.slice(*expected_prompts)) authenticated = true rescue CFoundry::Denied return if force? s.fail do failed = true credentials = credentials.slice(:username) end end end end return if failed info.merge!(auth_token.to_hash) save_target_info(info) invalidate_client line if input.interactive?(:organization) || input.interactive?(:space) CF::Populators::Target.new(input).populate_and_save! ensure exit_status 1 if not authenticated end
precondition()
click to toggle source
# File lib/cf/cli/start/login.rb, line 6 def precondition check_target end
Private Instance Methods
ask_prompt(type, label)
click to toggle source
# File lib/cf/cli/start/login.rb, line 94 def ask_prompt(type, label) if type == "password" options = { :echo => "*", :forget => true } else options = {} end ask(label, options) end
ask_prompts(credentials, prompts)
click to toggle source
# File lib/cf/cli/start/login.rb, line 87 def ask_prompts(credentials, prompts) prompts.each do |name, meta| type, label = meta credentials[name] ||= ask_prompt(type, label) end end