Module: ForemanAnsible::Concerns::ApiCommon

Extended by:
ActiveSupport::Concern
Included in:
Api::V2::HostgroupsControllerExtensions, Api::V2::HostsControllerExtensions
Defined in:
app/controllers/foreman_ansible/concerns/api_common.rb

Overview

Shared task methods between api controllers

Instance Method Summary collapse

Instance Method Details

#find_ansible_roleObject



16
17
18
19
20
# File 'app/controllers/foreman_ansible/concerns/api_common.rb', line 16

def find_ansible_role
  @ansible_role = AnsibleRole.authorized(:view_ansible_roles).find(params[:ansible_role_id])
rescue ActiveRecord::RecordNotFound => e
  not_found(e.message)
end

#find_ansible_rolesObject



9
10
11
12
13
14
# File 'app/controllers/foreman_ansible/concerns/api_common.rb', line 9

def find_ansible_roles
  ids = params.fetch(:ansible_role_ids, []) || []
  @ansible_roles = AnsibleRole.authorized(:view_ansible_roles).find(ids)
rescue ActiveRecord::RecordNotFound => e
  not_found(e.message)
end

#find_host_ansible_roleObject



22
23
24
25
26
27
# File 'app/controllers/foreman_ansible/concerns/api_common.rb', line 22

def find_host_ansible_role
  find_ansible_role
  @host = Host.authorized(:view_hosts).find(params[:id])
rescue ActiveRecord::RecordNotFound => e
  not_found(e.message)
end

#find_hostgroup_ansible_roleObject



29
30
31
32
33
34
# File 'app/controllers/foreman_ansible/concerns/api_common.rb', line 29

def find_hostgroup_ansible_role
  find_ansible_role
  @hostgroup = Hostgroup.authorized(:view_hostgroups).find(params[:id])
rescue ActiveRecord::RecordNotFound => e
  not_found(e.message)
end