Class: PI::Cli::Command::User

Inherits:
Base show all
Defined in:
lib/cli/commands/user.rb

Constant Summary collapse

YES_SET =
Set.new(["y", "Y", "yes", "YES"])
NO_SET =
Set.new(["n", "N", "no", "NO"])

Instance Method Summary collapse

Methods inherited from Base

#auth_token, #client, #initialize, #target_url

Constructor Details

This class inherits a constructor from PI::Cli::Command::Base

Instance Method Details

#frameworksObject



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/cli/commands/user.rb', line 147

def frameworks
  client.
  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



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/cli/commands/user.rb', line 117

def github(name=nil)
  client.
  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

#infoObject



47
48
49
50
51
52
53
54
# File 'lib/cli/commands/user.rb', line 47

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



9
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
# File 'lib/cli/commands/user.rb', line 9

def (url=nil)
  user = @options[:user]
  password = @options[:password]
  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)
  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      
  (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

#logoutObject



42
43
44
45
# File 'lib/cli/commands/user.rb', line 42

def logout
  PI::Cli::Config.remove_token_file
  say "Successfully logged out of [#{target_url}]".green
end

#password(oldpassword = nil) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/cli/commands/user.rb', line 91

def password(oldpassword=nil)   
  client.   
  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

#runtimesObject



134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/cli/commands/user.rb', line 134

def runtimes
  client.
  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

#targetsObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/cli/commands/user.rb', line 76

def targets
  client.
  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

#userObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/cli/commands/user.rb', line 56

def user
  client.
  user = client.
  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