module HammerCLIForeman::User::CommonUpdateOptions

Public Class Methods

ask_password(type) click to toggle source
# File lib/hammer_cli_foreman/user.rb, line 62
def self.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
included(base) click to toggle source
# File lib/hammer_cli_foreman/user.rb, line 55
def self.included(base)
  base.option '--default-organization', 'DEFAULT_ORGANIZATION_NAME', _("Default organization name")
  base.option '--default-location', 'DEFAULT_LOCATION_NAME', _("Default location name")
  base.option "--ask-password", "ASK_PW", " ",
              :format => HammerCLI::Options::Normalizers::Bool.new
end

Public Instance Methods

current_logged_user() click to toggle source
# File lib/hammer_cli_foreman/user.rb, line 71
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/user.rb, line 93
def location_id(name)
  resolver.location_id('option_name' => name) if name
end
organization_id(name) click to toggle source
# File lib/hammer_cli_foreman/user.rb, line 89
def organization_id(name)
  resolver.organization_id('option_name' => name) if name
end
request_params() click to toggle source
Calls superclass method
# File lib/hammer_cli_foreman/user.rb, line 75
def request_params
  params = super
  org_id = organization_id(option_default_organization)
  params['user']['default_organization_id'] ||= org_id unless org_id.nil?
  loc_id = location_id(option_default_location)
  params['user']['default_location_id'] ||= loc_id unless loc_id.nil?
  params['user']['password'] = option_password unless option_password.nil?

  if option_ask_password
    params['user']['password'] = HammerCLIForeman::User::CommonUpdateOptions::ask_password(:new)
  end
  params
end