Class: Api::V2::Compliance::ScapContentsController

Inherits:
BaseController
  • Object
show all
Includes:
Foreman::Controller::Parameters::ScapContent, ForemanOpenscap::Api::V2::ScapApiControllerExtensions, ForemanOpenscap::BodyLogExtensions
Defined in:
app/controllers/api/v2/compliance/scap_contents_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ForemanOpenscap::BodyLogExtensions

#log_response_body, #logger_msg, #skip_body_log

Class Method Details

.bulk_upload_typesObject



10
11
12
# File 'app/controllers/api/v2/compliance/scap_contents_controller.rb', line 10

def self.bulk_upload_types
  ['files', 'directory', 'default']
end

Instance Method Details

#bulk_uploadObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/api/v2/compliance/scap_contents_controller.rb', line 75

def bulk_upload
  case params[:type]
  when 'files'
    @result = ForemanOpenscap::BulkUpload.new.upload_from_files(params[:files])
  when 'directory'
    @result = ForemanOpenscap::BulkUpload.new.upload_from_directory(params[:directory])
  when 'default'
    @result = ForemanOpenscap::BulkUpload.new.upload_from_scap_guide
  else
    return render :json => {
      :errors => [
        _("Please specify import type, received: %{received}, expected one of: %{expected}") %
          { :expected => self.class.bulk_upload_types.join(', '), :received => params[:type] }
      ]
    }, :status => :unprocessable_entity
  end
end

#createObject



50
51
52
53
# File 'app/controllers/api/v2/compliance/scap_contents_controller.rb', line 50

def create
  @scap_content = ForemanOpenscap::ScapContent.new(scap_content_params)
  process_response @scap_content.save
end

#destroyObject



66
67
68
# File 'app/controllers/api/v2/compliance/scap_contents_controller.rb', line 66

def destroy
  process_response @scap_content.destroy
end

#indexObject



20
21
22
# File 'app/controllers/api/v2/compliance/scap_contents_controller.rb', line 20

def index
  @scap_contents = resource_scope_for_index(:permission => :view_scap_contents)
end

#showObject



35
36
# File 'app/controllers/api/v2/compliance/scap_contents_controller.rb', line 35

def show
end

#updateObject



59
60
61
# File 'app/controllers/api/v2/compliance/scap_contents_controller.rb', line 59

def update
  process_response @scap_content.update(scap_content_params)
end

#xmlObject



27
28
29
30
31
# File 'app/controllers/api/v2/compliance/scap_contents_controller.rb', line 27

def xml
  send_data @scap_content.scap_file,
            :type     => 'application/xml',
            :filename => @scap_content.original_filename || "#{@scap_content.title}.xml"
end