Class: HammerCLIForeman::OptionSources::UserParams

Inherits:
HammerCLI::Options::Sources::Base
  • Object
show all
Defined in:
lib/hammer_cli_foreman/option_sources/user_params.rb

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ UserParams

Returns a new instance of UserParams.



4
5
6
# File 'lib/hammer_cli_foreman/option_sources/user_params.rb', line 4

def initialize(command)
  @command = command
end

Instance Method Details

#get_options(defined_options, result) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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
        curr_passwd = HammerCLIForeman.foreman_api_connection.authenticator.password(true)
        result[option_name(:current_password)] = curr_passwd unless curr_passwd.nil?
        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