16
17
18
19
20
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
|
# File 'lib/appfog-vmc-plugin/vmc/start/login.rb', line 16
def login
show_context
credentials =
{ :username => input[:username],
:password => input[:password]
}
prompts = client.login_prompts
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.login(credentials[:username], credentials[:password])
authenticated = true
rescue CFoundry::Denied, CFoundry::Forbidden
return if force?
s.fail do
failed = true
credentials.delete(:password)
end
end
end
end
if authenticated
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)
end
ensure
exit_status 1 if not authenticated
end
|