Class: VMC::Start::Login

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

Constant Summary

Constants inherited from Mothership

Mothership::VERSION

Instance Attribute Summary

Attributes inherited from Mothership

#input

Instance Method Summary collapse

Methods inherited from Base

#displayed_target?

Methods inherited from V2CheckCLI

#fail_on_v2

Methods inherited from CLI

#check_logged_in, #check_target, #client, client, client=, #client_target, #color_enabled?, #debug?, #default_action, #ensure_config_dir, #err, #execute, #fail, #fail_unknown, #force?, #invalidate_client, #log_error, #name_list, #no_v2, #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_file, #target_info, #targets_info, #tokens_file, #user_colors, #v2?, #verbose?, #wrap_errors

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

Methods inherited from Mothership

add_input, after, alias_command, around, before, change_argument, commands, #default_action, desc, #execute, #exit_status, #filter, filter, global_option, group, #help, #initialize, input, #interact, interactions, #invoke, method_added, option, #run, start, #unknown_command, #with_filters

Constructor Details

This class inherits a constructor from Mothership

Instance Method Details

#loginObject



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
# File 'lib/vmc/cli/start/login.rb', line 21

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

  auth_token = nil
  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
        auth_token = client.(credentials[:username], credentials[:password])
        authenticated = true
      rescue CFoundry::Denied
        return if force?

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

  info.merge!(auth_token.to_hash)
  save_target_info(info)
  invalidate_client

  if v2?
    line if input.interactive?(:organization) || input.interactive?(:space)
    select_org_and_space(input, info)
  end

  save_target_info(info)
ensure
  exit_status 1 if not authenticated
end

#preconditionObject



6
7
8
9
# File 'lib/vmc/cli/start/login.rb', line 6

def precondition
  check_target
  super
end