Class: Bosh::Cli::Command::User

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

Constant Summary

Constants inherited from Base

Base::DEFAULT_DIRECTOR_PORT

Instance Attribute Summary

Attributes inherited from Base

#args, #exit_code, #options, #out, #runner, #work_dir

Instance Method Summary collapse

Methods inherited from Base

#add_option, #blob_manager, #blobstore, #config, #confirmed?, #deployment, #director, #initialize, #interactive?, #logged_in?, #non_interactive?, #password, #redirect, #release, #remove_option, #target, #target_name, #username, #verbose?

Methods included from Bosh::Cli::CommandDiscovery

#desc, #method_added, #option, #register_command, #usage

Methods included from DeploymentHelper

#cancel_deployment, #deployment_changed?, #inspect_deployment_changes, #job_exists_in_deployment?, #job_must_exist_in_deployment, #job_unique_in_deployment?, #jobs_and_indexes, #latest_release_versions, #prepare_deployment_manifest, #prompt_for_job_and_index, #resolve_release_aliases, #warn_about_stemcell_changes

Constructor Details

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

Instance Method Details

#create(username = nil, password = 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
# File 'lib/cli/commands/user.rb', line 9

def create(username = nil, password = nil)
  auth_required

  if interactive?
    username = ask("Enter new username: ") if username.blank?
    if password.blank?
      password = ask("Enter new password: ") { |q| q.echo = "*" }
      password_confirmation = ask("Verify new password: ") { |q| q.echo = "*" }

      err("Passwords do not match") if password != password_confirmation
    end
  end

  if username.blank? || password.blank?
    err("Please enter username and password")
  end

  if director.create_user(username, password)
    say("User `#{username}' has been created".make_green)
  else
    err("Error creating user")
  end
end

#delete(username = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cli/commands/user.rb', line 35

def delete(username = nil)
  auth_required

  if interactive?
    username ||= ask("Username to delete: ")
  end

  if username.blank?
    err("Please provide a username to delete")
  end

  if confirmed?("Are you sure you would like to delete the user `#{username}'?")
    if director.delete_user(username)
      say("User `#{username}' has been deleted".make_green)
    else
      err("Unable to delete user")
    end
  end
end