Class: CF::Start::Login
- Defined in:
- lib/cf/cli/start/login.rb
Instance Method Summary collapse
Methods inherited from Base
Methods inherited from CLI
#add_exception_name_to_msg, #build_client, #check_logged_in, #check_target, client, #client, client=, #client_target, #color_enabled?, #debug?, #default_action, #ensure_config_dir, #err, #execute, #fail, #fail_unknown, #force?, #formatted_exception_output, #help, #help_header, #invalidate_client, #log_error, #log_error_and_dump_crashlog, #name_list, #normalize_targets_info, #one_of, #quiet?, #remove_target_info, #sane_target_url, #save_target_info, #save_targets, #save_token_if_it_changes, #set_target, #table, #target_info, #targets_info, #user_colors, #verbose?, #wrap_errors
Methods included from CF::Spacing
#indented, #justify, #line, #lines, #quiet?, #spaced, #start_line, #tabular, #text_width, #trim_escapes
Methods included from Interactive
#ask, #handler, #input_state, #list_choices, #prompt, #show_default
Instance Method Details
#login ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# 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 ⇒ Object
6 7 8 |
# File 'lib/cf/cli/start/login.rb', line 6 def precondition check_target end |