Class: VMC::Start::Login

Inherits:
Base
  • Object
show all
Defined in:
lib/vmc/cli/start/login.rb

Instance Method Summary collapse

Methods inherited from Base

#displayed_target?, #precondition

Methods inherited from CLI

#check_logged_in, #check_target, #client, client, client=, #client_target, #color_enabled?, #default_action, #ensure_config_dir, #err, #execute, #fail, #force?, #invalidate_client, #log_error, #name_list, #no_v2, #one_of, #precondition, #quiet?, #remove_target_info, #sane_target_url, #save_target_info, #save_targets, #set_target, #table, #target_file, #target_info, #targets_info, #tokens_file, #user_colors, #v2?, #verbose?

Methods included from VMC::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

#loginObject



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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/vmc/cli/start/login.rb', line 45

def 
  show_context

  credentials =
      { :username => input[:username],
        :password => input[:password]
      }

  prompts = client.

  # ask username first
  if prompts.key? :username
    type, label = prompts.delete :username
    credentials[:username] ||= ask_prompt(type, label)
  end

  info = target_info

  authenticated = false
  failed = false
  remaining_attempts = 3
  until authenticated || remaining_attempts <= 0
    remaining_attempts -= 1
    unless force?
      ask_prompts(credentials, prompts)
    end

    with_progress("Authenticating") do |s|
      begin
        info[:token] = client.(credentials)
        authenticated = true
      rescue CFoundry::Denied
        return if force?

        s.fail do
          failed = true
          credentials.delete(:password)
        end
      end
    end
  end

  save_target_info(info)
  invalidate_client

  if v2?
    line if input.interactive?(:organization) || input.interactive?(:space)
    select_org_and_space(input, info)
    save_target_info(info)
  end
ensure
  exit_status 1 if not authenticated
end