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



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

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



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

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

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

#listObject



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

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



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

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



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

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



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

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

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