Module: HammerCLIForeman::User::CommonUpdateOptions

Included in:
CreateCommand, UpdateCommand
Defined in:
lib/hammer_cli_foreman/user.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ask_password(type) ⇒ Object



62
63
64
65
66
67
68
69
# 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) ⇒ Object



55
56
57
58
59
60
# 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

Instance Method Details

#current_logged_userObject



71
72
73
# 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) ⇒ Object



93
94
95
# 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) ⇒ Object



89
90
91
# File 'lib/hammer_cli_foreman/user.rb', line 89

def organization_id(name)
  resolver.organization_id('option_name' => name) if name
end

#request_paramsObject



75
76
77
78
79
80
81
82
83
84
85
86
87
# 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