Class: VMC::Cli::Command::Admin

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

Instance Attribute Summary

Attributes inherited from Base

#no_prompt, #prompt_ok

Instance Method Summary collapse

Methods inherited from Base

#auth_token, #client, #client_info, #frameworks_info, #initialize, #runtimes_info, #target_url

Constructor Details

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

Instance Method Details

#add_user(email = nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cli/commands/admin.rb', line 24

def add_user(email=nil)
  email    = @options[:email] unless email
  password = @options[:password]
  email = ask("Email: ") unless no_prompt || email
  unless no_prompt || password
    password = ask("Password: ") {|q| q.echo = '*'}
    password2 = ask("Verify Password: ") {|q| q.echo = '*'}
    err "Passwords did not match, try again" if password != password2
  end
  err "Need a valid email" unless email
  err "Need a password" unless password
  display 'Creating New User: ', false
  client.add_user(email, password)
  display 'OK'.green

  # if we are not logged in for the current target, log in as the new user
  return unless VMC::Cli::Config.auth_token.nil?
  @options[:password] = password
  cmd = User.new(@options)
  cmd.(email)
end

#delete_user(user_email) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/cli/commands/admin.rb', line 46

def delete_user(user_email)
  # Check to make sure all apps and services are deleted before deleting the user
  # implicit proxying

  client.proxy_for(user_email)
  @options[:proxy] = user_email
  apps = client.apps

  if (apps && !apps.empty?)
    unless no_prompt
      proceed = ask("\nDeployed applications and associated services will be DELETED, continue? [yN]: ")
      err "Aborted" if proceed.upcase != 'Y'
    end
    cmd = Apps.new(@options)
    apps.each { |app| cmd.delete_app(app[:name], true) }
  end

  services = client.services
  if (services && !services.empty?)
    cmd = Services.new(@options)
    services.each { |s| cmd.delete_service(s[:name])}
  end

  display 'Deleting User: ', false
  client.proxy = nil
  client.delete_user(user_email)
  display 'OK'.green
end

#list_usersObject Also known as: users



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/cli/commands/admin.rb', line 5

def list_users
  users = client.users
  users.sort! {|a, b| a[:email] <=> b[:email] }
  return display JSON.pretty_generate(users || []) if @options[:json]

  display "\n"
  return display "No Users" if users.nil? || users.empty?

  users_table = table do |t|
    t.headings = 'Email', 'Admin', 'Apps'
    users.each do |user|
      t << [user[:email], user[:admin], user[:apps].map {|x| x[:name]}.join(', ')]
    end
  end
  display users_table
end