Class: Api::V2::CveScansController

Inherits:
V2::BaseController
  • Object
show all
Defined in:
app/controllers/api/v2/cve_scans_controller.rb

Overview

API controller for CVE scans per host.

Instance Method Summary collapse

Instance Method Details

#compareObject



77
78
79
80
81
82
83
84
85
86
87
# File 'app/controllers/api/v2/cve_scans_controller.rb', line 77

def compare
  return compare_params_missing unless params[:first_id].present? && params[:second_id].present?

  first_scan = find_scan_for_host(params[:first_id])
  return unless first_scan

  second_scan = find_scan_for_host(params[:second_id])
  return unless second_scan

  render json: ::ForemanCveScanner::ScanComparison.compare(first_scan, second_scan)
end

#destroyObject



93
94
95
96
# File 'app/controllers/api/v2/cve_scans_controller.rb', line 93

def destroy
  @cve_scan = resource_class.for_host(@host.id).find(params[:id])
  process_response @cve_scan.destroy
end

#exportObject



102
103
104
105
106
107
108
109
110
111
# File 'app/controllers/api/v2/cve_scans_controller.rb', line 102

def export
  @cve_scan = resource_class.for_host(@host.id).find(params[:id])

  send_data(
    findings_csv(@cve_scan),
    filename: export_filename(@cve_scan),
    type: 'text/csv; charset=utf-8',
    disposition: 'attachment'
  )
end

#importObject



59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/api/v2/cve_scans_controller.rb', line 59

def import
  @cve_scan = resource_class.new(build_import_attributes)

  if @cve_scan.save
    render 'api/v2/cve_scans/show', status: :created
  else
    render(
      json: { error: { message: @cve_scan.errors.full_messages.to_sentence } },
      status: :unprocessable_entity
    )
  end
end

#indexObject



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

def index
  @cve_scans = cve_scans_index_scope.paginate(paginate_options)
end

#latestObject



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

def latest
  @cve_scan = cve_scans_index_scope.first
  head :no_content if @cve_scan.nil?
end

#resource_classObject



11
12
13
# File 'app/controllers/api/v2/cve_scans_controller.rb', line 11

def resource_class
  ::ForemanCveScanner::CveScan
end

#showObject



36
37
38
# File 'app/controllers/api/v2/cve_scans_controller.rb', line 36

def show
  @cve_scan = resource_class.for_host(@host.id).find(params[:id])
end