Class: PI::Cli::Command::User
Constant Summary
collapse
- YES_SET =
Set.new(["y", "Y", "yes", "YES"])
- NO_SET =
Set.new(["n", "N", "no", "NO"])
PI::Cli::ChooseHelper::DEFAULTS
Instance Method Summary
collapse
#check_envname_valid?, #check_envvalue_valid?, #check_mem_valid?, #check_name_valid?, #check_status, #check_version_name_valid?, #choose_app, #choose_app_help, #choose_app_help_target_not_all, #choose_dnsid, #choose_project, #choose_serviceid, #choose_target, #get_graceful, #select_apps, #total_opts
Methods inherited from Base
#auth_token, #client, #initialize, #target_url
Instance Method Details
#frameworks ⇒ Object
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
# File 'lib/cli/commands/user.rb', line 179
def frameworks
all_opts = total_opts
all_opts.each_value do |value|
err "Invalid options" if value != nil
end
client.check_login_status
runtimes = client.runtimes
java_runtime = runtimes[0].downcase
ruby_runtime = runtimes[1].downcase
python_runtime = runtimes[2].downcase
java_frameworks = client.frameworks(java_runtime)
ruby_frameworks = client.frameworks(ruby_runtime)
python_frameworks = client.frameworks(python_runtime)
frameworks = java_frameworks << ruby_frameworks[0] << ruby_frameworks[1] << python_frameworks[0]
return display JSON.pretty_generate(frameworks) if @options[:json]
return display "No Frameworks" if frameworks.empty?
rtable = table do |t|
t.headings = ['Name']
frameworks.each { |f| t << [f]}
end
display "\n"
display rtable
end
|
#github(name = nil) ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# File 'lib/cli/commands/user.rb', line 140
def github(name=nil)
all_opts = total_opts
all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(email|password)/i}
all_opts_except_valid_opts.each_value do |value|
err "Invalid options" if value != nil
end
client.check_login_status
email = @options[:email]
password = @options[:password]
name = ask "Please input your name" unless name
email = ask "Please input your email" unless email
password = ask "Please input your password", :echo => '*' unless password
manifest = {
:name => "#{name}",
:password => "#{password}",
:email => "#{email}",
:passwordBase64 => "#{password}"
}
github = client.github(manifest)
display "ok".green
end
|
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/cli/commands/user.rb', line 53
def info
all_opts = total_opts
all_opts.each_value do |value|
err "Invalid options" if value != nil
end
info = client.info
return display JSON.pretty_generate(info) if @options[:json]
display "\nName: #{info[:name]}"
display "Description: #{info[:description]}"
display "Build: #{info[:build]}"
display "Version: #{info[:version]}"
end
|
#login(url = nil) ⇒ Object
10
11
12
13
14
15
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
|
# File 'lib/cli/commands/user.rb', line 10
def login(url=nil)
user = @options[:user]
password = @options[:password]
all_opts = total_opts
all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(user|password)/i}
all_opts_except_valid_opts.each_value do |value|
err "Invalid options" if value != nil
end
unless url
env_choices = ["www", "staging", "qa"]
url = ask "Select CloudPi Environment", :choices => env_choices, :indexed => true, :default => "www"
end
url = "#{target_url}" if url.nil? || url.empty?
eval("PI::Cli::Command::Misc").new().send("set_target", url)
unless client.target_valid?
display "Host is not available or is not valid: '#{url}'".red
display "\n<<<\n#{client.raw_info}\n>>>\n"
exit(false)
end
tries ||= 0
user = ask "User" unless user
password = ask "Password", :echo => '*' unless password
login_and_save_token(user, password)
say "Successfully logged into [#{target_url}]".green
rescue PI::Client::TargetError
display "Problem with login, invalid account or password.".red
retry if (tries += 1) < 3 && !@options[:passwd]
exit 1
rescue => e
display "Problem with login, #{e}, try again.".red
exit 1
end
|
44
45
46
47
48
49
50
51
|
# File 'lib/cli/commands/user.rb', line 44
def logout
all_opts = total_opts
all_opts.each_value do |value|
err "Invalid options" if value != nil
end
PI::Cli::Config.remove_token_file
say "Successfully logged out of [#{target_url}]".green
end
|
#password(oldpassword = nil) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/cli/commands/user.rb', line 109
def password(oldpassword=nil)
all_opts = total_opts
all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(password)/i}
all_opts_except_valid_opts.each_value do |value|
err "Invalid options" if value != nil
end
client.check_login_status
newpassword = @options[:password]
oldpassword = ask "Old Password", :echo => '*' unless oldpassword
unless newpassword
loop{
newpassword = ask "New Password", :echo => '*'
newpassword2 = ask "Verify Password", :echo => '*'
if newpassword != newpassword2
display "Passwords did not match, try again"
newpassword =nil
next
else
break
end
}
end
err "New password is same with old one. Don't need to change password." if oldpassword == newpassword
manifest = {
:newPassword => newpassword,
:oldPassword => oldpassword
}
client.password(manifest)
display "ok".green
end
|
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
# File 'lib/cli/commands/user.rb', line 162
def runtimes
all_opts = total_opts
all_opts.each_value do |value|
err "Invalid options" if value != nil
end
client.check_login_status
runtimes_info = client.runtimes
return display JSON.pretty_generate(runtimes_info) if @options[:json]
return display "No Runtimes" if runtimes_info.empty?
rtable = table do |t|
t.headings = ['Name']
runtimes_info.each { |rt| t << [rt] }
end
display "\n"
display rtable
end
|
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/cli/commands/user.rb', line 90
def targets
all_opts = total_opts
all_opts.each_value do |value|
err "Invalid options" if value != nil
end
client.check_login_status
targets = client.targets
return display JSON.pretty_generate(targets) if @options[:json]
return display 'No Targets' if targets.empty?
targets_table = table do |t|
t.headings = 'Name', 'URL'
targets.each do |target|
t << [target[:name], target[:targetUrl]]
end
end
display "\n"
display targets_table
end
|
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/cli/commands/user.rb', line 66
def user
all_opts = total_opts
all_opts.each_value do |value|
err "Invalid options" if value != nil
end
client.check_login_status
user = client.user_info
github_info = client.github_info
if github_info.nil?
github_info = Hash.new
github_info[:name] = "null"
github_info[:email] = "null"
end
user_merge =user.merge(github_info)
return display JSON.pretty_generate(user_merge) if @options[:json]
return display 'No user info' if user.empty?
display "\nUserName: #{user[:userName]}"
display "DomainName: #{user[:domainName]}"
display "RoleName: #{user[:roleName]}"
display "State: #{user[:state]}"
display "Github Account Name: #{github_info[:name]}"
display "Github Account Email: #{github_info[:email]}"
end
|