Class: PI::Cli::Command::User
- Inherits:
-
Base
show all
- Defined in:
- lib/cli/commands/user.rb
Instance Method Summary
collapse
Methods inherited from Base
#auth_token, #client, #initialize, #target_url
Instance Method Details
#frameworks ⇒ Object
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/cli/commands/user.rb', line 122
def frameworks
runtimes = client.runtimes
java_runtime = runtimes[0].downcase
ruby_runtime = runtimes[1].downcase
java_frameworks = client.frameworks(java_runtime)
ruby_frameworks = client.frameworks(ruby_runtime)
frameworks = java_frameworks << ruby_frameworks[0] << ruby_frameworks[1]
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
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/cli/commands/user.rb', line 96
def github(name=nil)
name = ask "Please input your name" unless name
email = ask "Please input your email"
password = ask "Please input your password", :echo => '*'
manifest = {
:name => "#{name}",
:password => "#{password}",
:email => "#{email}",
:passwordBase64 => "#{password}"
}
github = client.github(manifest)
display "ok".green
end
|
39
40
41
42
43
44
45
46
|
# File 'lib/cli/commands/user.rb', line 39
def info
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
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/cli/commands/user.rb', line 7
def login(url=nil)
unless url
url = ask "Attempting login to '#{target_url}'?", :default => true
if url == true
url = "#{target_url}"
else
url = ask "Please input URL"
end
end
url = "#{target_url}" if url.nil? || url.empty?
eval("PI::Cli::Command::Misc").new().send("set_target", url)
tries ||= 0
user = ask "User"
password = ask "Password", :echo => '*'
err "Need a valid user" unless user
err "Need a password" 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 or register for an account.".red
exit 1
end
|
34
35
36
37
|
# File 'lib/cli/commands/user.rb', line 34
def logout
PI::Cli::Config.remove_token_file
say "Successfully logged out of [#{target_url}]".green
end
|
#password(newpassword = nil) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/cli/commands/user.rb', line 78
def password(newpassword=nil)
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
client.password(newpassword)
display "ok".green
end
|
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/cli/commands/user.rb', line 110
def runtimes
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
|
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/cli/commands/user.rb', line 64
def targets
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
|
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/cli/commands/user.rb', line 48
def user
user = client.user_info
github_info = client.github_info
github_info[:name] = "null" if github_info[:name].empty? || github_info[:name].nil?
github_info[:email] = "null" if github_info[:email].empty? || github_info[:email].nil?
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
|