-
Notifications
You must be signed in to change notification settings - Fork 65
/
tailoring_files_controller.rb
84 lines (68 loc) · 2.69 KB
/
tailoring_files_controller.rb
1
2
3
4
5
6
7
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
module Api::V2
module Compliance
class TailoringFilesController < ::Api::V2::BaseController
include Foreman::Controller::Parameters::TailoringFile
before_filter :find_resource, :except => %w(index create)
def resource_name
'::ForemanOpenscap::TailoringFile'
end
def get_resource
instance_variable_get :"@tailoring_file" or fail 'no resource loaded'
end
api :GET, '/compliance/tailoring_files', N_('List Tailoring files')
param_group :search_and_pagination, ::Api::V2::BaseController
def index
@tailoring_files = resource_scope_for_index(:permission => :view_tailoring_files)
end
api :GET, '/compliance/tailoring_files/:id/xml', N_('Show a Tailoring file as XML')
param :id, :identifier, :required => true
def xml
send_data @tailoring_file.scap_file,
:type => 'application/xml',
:filename => @tailoring_file.original_filename
end
api :GET, '/compliance/tailoring_files/:id', N_('Show a Tailoring file')
param :id, :identifier, :required => true
def show
end
def_param_group :tailoring_file do
param :tailoring_file, Hash, :required => true, :action_aware => true do
param :name, String, :required => true, :desc => N_('Tailoring file name')
param :scap_file, String, :required => true, :desc => N_('XML containing tailoring file')
param :original_filename, String, :desc => N_('Original file name of the XML file')
param_group :taxonomies, ::Api::V2::BaseController
end
end
api :POST, '/compliance/tailoring_files', N_('Create a Tailoring file')
param_group :tailoring_file, :as => :create
def create
@tailoring_file = ForemanOpenscap::TailoringFile.new(tailoring_file_params)
process_response @tailoring_file.save
end
api :PUT, '/compliance/tailoring_files/:id', N_('Update a Tailoring file')
param :id, :identifier, :required => true
param_group :tailoring_file
def update
process_response @tailoring_file.update_attributes(tailoring_file_params)
end
api :DELETE, '/compliance/tailoring_files/:id', N_('Deletes a Tailoring file')
param :id, :identifier, :required => true
def destroy
process_response @tailoring_file.destroy
end
private
def find_resource
not_found and return if params[:id].blank?
instance_variable_set("@tailoring_file", resource_scope.find(params[:id]))
end
def action_permission
case params[:action]
when 'xml'
:view
else
super
end
end
end
end
end