Class: ForemanMco::CommandStatusesController

Inherits:
Api::V2::BaseController
  • Object
show all
Includes:
Foreman::Controller::SmartProxyAuth
Defined in:
app/controllers/foreman_mco/command_statuses_controller.rb

Instance Method Summary collapse

Instance Method Details

#find_statusObject



14
15
16
17
# File 'app/controllers/foreman_mco/command_statuses_controller.rb', line 14

def find_status
  @command_status = ForemanMco::CommandStatus.find_by_jid(params[:id])
  render_error 'not_found', :status => :not_found and return false unless @command_status
end

#parse_resultsObject



19
20
21
22
# File 'app/controllers/foreman_mco/command_statuses_controller.rb', line 19

def parse_results
  return if params[:command_status][:result].nil?
  @host_statuses = params[:command_status][:result].each {|host_status| @command_status.host_command_statuses.build(to_foreman_schema(host_status))}
end

#require_mco_proxy_or_loginObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/foreman_mco/command_statuses_controller.rb', line 35

def 
  if auth_smart_proxy(SmartProxy.mcollective_proxies, false)
    set_admin_user
    return true
  end

  
  unless User.current
    render_error 'access_denied', :status => :forbidden unless performed? and api_request?
    return false
  end
  authorize
end

#to_foreman_schema(a_hash) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/foreman_mco/command_statuses_controller.rb', line 24

def to_foreman_schema(a_hash)
  to_ret = {}
  our_schema = { "sender" => "host", "statuscode" => "status_code", "statusmsg" => "status_message", "data" => "result" }

  a_hash.each_pair do |k,v|
    our_schema.has_key?(k) ? to_ret[our_schema[k]] = v : to_ret[k] = v
  end

  to_ret
end

#updateObject



10
11
12
# File 'app/controllers/foreman_mco/command_statuses_controller.rb', line 10

def update
  process_response @command_status.update_attributes!(params[:command_status])
end