Class: Wdmc::User
Instance Method Summary collapse
- #create(name) ⇒ Object
- #delete(name) ⇒ Object
-
#initialize(*args) ⇒ User
constructor
A new instance of User.
- #list ⇒ Object
- #show(name) ⇒ Object
- #update(name) ⇒ Object
Constructor Details
Instance Method Details
#create(name) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/wdmc/user.rb', line 44 def create( name ) password = Base64.strict_encode64([:password]) if [:password] user_exists = @wdmc.user_exists?( name ) abort "\nUser does not exist: ".color(:yellow) + "#{name}".color(:cyan) if user_exists.include?( name ) begin groups = ['cloudholders'] groups.push [:group_names] if [:group_names] data = { :email => [:email], :username => name, :password => password, :fullname => [:fullname], :is_admin => [:admin], :group_names => groups.join(','), :first_name => [:first_name], :last_name => [:last_name] } puts "Create user:\s".color(:whitesmoke) + "OK".color(:green) if @wdmc.add_user( data ) rescue RestClient::ExceptionWithResponse => e puts eval(e.response)[:users][:error_message].color(:orange) end end |
#delete(name) ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/wdmc/user.rb', line 95 def delete( name ) user_exists = @wdmc.user_exists?( name ) abort "\nUser does not exist: ".color(:yellow) + "#{name}".color(:cyan) unless user_exists.include?( name ) unless ['force'] puts "\nAre you sure you want to delete this user?\s".color(:orange) + "#{name}".color(:whitesmoke) return unless yes?("DELETE? (yes/no):") end puts "Delete user:\s".color(:whitesmoke) + "OK".color(:green) if @wdmc.delete_user( name ) end |
#list ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/wdmc/user.rb', line 13 def list users = @wdmc.all_users puts "Users".upcase.color(:magenta) users.each do |user| puts "\s- #{user[:username]}" end end |
#show(name) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/wdmc/user.rb', line 22 def show( name ) users = @wdmc.find_user( name ) user_exists = @wdmc.user_exists?( name ) abort "\nUser does not exist: ".color(:yellow) + "#{name}".color(:cyan) unless user_exists.include?( name ) users.each do |user| puts "Username:\s".upcase.color(:magenta) + user[:username] puts "\sUser ID\t\t: ".color(:whitesmoke) + "#{user[:user_id]}" puts "\sFullname\t\t: ".color(:whitesmoke) + "#{user[:fullname]}" unless user[:fullname].empty? puts "\sAdmin\t\t\t: ".color(:whitesmoke) + "#{user[:is_admin]}" puts "\sPassword set\t\t: ".color(:whitesmoke) + "#{user[:is_password]}".color(:green) if user[:is_password] == 'true' puts "\sPassword set\t\t: ".color(:whitesmoke) + "#{user[:is_password]}".color(:orange) if user[:is_password] == 'false' end end |
#update(name) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/wdmc/user.rb', line 74 def update( name ) password = Base64.strict_encode64([:password]) if [:password] user_exists = @wdmc.user_exists?( name ) abort "\nUser does not exist: ".color(:yellow) + "#{name}".color(:cyan) unless user_exists.include?( name ) begin data = { :username => [:new_username] || name, :password => password, :fullname => [:fullname], :is_admin => [:admin], :first_name => [:first_name], :last_name => [:last_name] } puts "Update user:\s".color(:whitesmoke) + "OK".color(:green) if @wdmc.update_user( name, data ) rescue RestClient::ExceptionWithResponse => e puts eval(e.response)[:users] #[:error_message].color(:orange) end end |