Parent

Methods

Files

Class/Module Index [+]

Quicksearch

Chef::Knife::UserCreate

Public Instance Methods

run() click to toggle source
# File lib/chef/knife/user_create.rb, line 53
def run
  @user_name = @name_args[0]

  if @user_name.nil?
    show_usage
    ui.fatal("You must specify a user name")
    exit 1
  end

  if config[:user_password].length == 0
    show_usage
    ui.fatal("You must specify a non-blank password")
    exit 1
  end

  user = Chef::User.new
  user.name(@user_name)
  user.admin(config[:admin])
  user.password config[:user_password]

  if config[:user_key]
    user.public_key File.read(File.expand_path(config[:user_key]))
  end

  output = edit_data(user)
  user = Chef::User.from_hash(output).create

  ui.info("Created #{user}")
  if user.private_key
    if config[:file]
      File.open(config[:file], "w") do |f|
        f.print(user.private_key)
      end
    else
      ui.msg user.private_key
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.