class HammerCLIForeman::OptionSources::UserParams

Public Class Methods

new(command) click to toggle source
# File lib/hammer_cli_foreman/option_sources/user_params.rb, line 4
def initialize(command)
  @command = command
end

Public Instance Methods

get_options(defined_options, result) click to toggle source
# File lib/hammer_cli_foreman/option_sources/user_params.rb, line 8
def get_options(defined_options, result)
  org_id = organization_id(result[option_name(:default_organization)])
  result[option_name(:default_organization_id)] ||= org_id unless org_id.nil?
  loc_id = location_id(result[option_name(:default_location)])
  result[option_name(:default_location_id)] ||= loc_id unless loc_id.nil?

  if @command.action == :update
    if result[option_name(:password)] || result[option_name(:ask_password)]
      if current_logged_user["id"].to_s == result[option_name(:id)].to_s
        unless result[option_name(:current_password)]
          result[option_name(:current_password)] = ask_password(:current)
        end
      end
    end
  end

  if result[option_name(:ask_password)]
    result[option_name(:password)] = ask_password(:new)
  end

  result
end

Private Instance Methods

ask_password(type) click to toggle source
# File lib/hammer_cli_foreman/option_sources/user_params.rb, line 37
def ask_password(type)
  if type == :current
    prompt = _("Enter user's current password:") + " "
  elsif type == :new
    prompt = _("Enter user's new password:") + " "
  end
  ask(prompt) {|q| q.echo = false}
end
current_logged_user() click to toggle source
# File lib/hammer_cli_foreman/option_sources/user_params.rb, line 54
def current_logged_user
  HammerCLIForeman.foreman_api_connection.resource(:users).call(:show, :id => HammerCLIForeman.foreman_api_connection.authenticator.user(true))
end
location_id(name) click to toggle source
# File lib/hammer_cli_foreman/option_sources/user_params.rb, line 50
def location_id(name)
  @command.resolver.location_id('option_name' => name) if name
end
option_name(opt_name) click to toggle source
# File lib/hammer_cli_foreman/option_sources/user_params.rb, line 33
def option_name(opt_name)
  HammerCLI.option_accessor_name(opt_name)
end
organization_id(name) click to toggle source
# File lib/hammer_cli_foreman/option_sources/user_params.rb, line 46
def organization_id(name)
  @command.resolver.organization_id('option_name' => name) if name
end