Class: Cyclid::Cli::AdminUser

Inherits:
Thor
  • Object
show all
Defined in:
lib/cyclid/cli/admin/user.rb

Overview

‘admin user’ sub-commands

Instance Method Summary collapse

Instance Method Details

#create(username, email) ⇒ Object



67
68
69
70
71
# File 'lib/cyclid/cli/admin/user.rb', line 67

def create(username, email)
  client.user_add(username, email, options[:name], options[:password], options[:secret])
rescue StandardError => ex
  abort "Failed to create new user: #{ex}"
end

#delete(username) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/cyclid/cli/admin/user.rb', line 125

def delete(username)
  if options[:force]
    delete = true
  else
    print "Delete user #{username}: are you sure? (Y/n): ".colorize(:red)
    delete = STDIN.getc.chr.casecmp('y') == 0
  end
  abort unless delete

  begin
    client.user_delete(username)
  rescue StandardError => ex
    abort "Failed to delete user: #{ex}"
  end
end

#listObject



20
21
22
23
24
25
26
27
# File 'lib/cyclid/cli/admin/user.rb', line 20

def list
  users = client.user_list
  users.each do |user|
    puts user
  end
rescue StandardError => ex
  abort "Failed to retrieve list of users: #{ex}"
end

#modify(username) ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'lib/cyclid/cli/admin/user.rb', line 90

def modify(username)
  client.user_modify(username,
                     name: options[:name],
                     email: options[:email],
                     password: options[:password],
                     secret: options[:secret])
rescue StandardError => ex
  abort "Failed to modify user: #{ex}"
end

#passwd(username) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/cyclid/cli/admin/user.rb', line 101

def passwd(username)
  # Get the new password
  print 'Password: '
  password = STDIN.noecho(&:gets).chomp
  print "\nConfirm password: "
  confirm = STDIN.noecho(&:gets).chomp
  print "\n"
  abort 'Passwords do not match' unless password == confirm

  # Modify the user with the new password
  begin
    client.user_modify(username, password: password)
  rescue StandardError => ex
    abort "Failed to modify user: #{ex}"
  end
end

#show(username) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cyclid/cli/admin/user.rb', line 30

def show(username)
  user = client.user_get(username)

  # Pretty print the user details
  puts 'Username: '.colorize(:cyan) + user['username']
  puts 'Name: '.colorize(:cyan) + (user['name'] || '')
  puts 'Email: '.colorize(:cyan) + user['email']
  puts 'Organizations:'.colorize(:cyan)
  if user['organizations'].any?
    user['organizations'].each do |org|
      puts "\t#{org}"
    end
  else
    puts "\tNone"
  end
rescue StandardError => ex
  abort "Failed to get user: #{ex}"
end