Sha256: 451dca87595b0c5c2bbc6733c4989c9c558a383c797c365a130e302c11596c27

Contents?: true

Size: 1.48 KB

Versions: 16

Compression:

Stored size: 1.48 KB

Contents

module Api
  module V2
    module Compliance
      class OvalReportsController < ::Api::V2::BaseController
        include Foreman::Controller::SmartProxyAuth
        add_smart_proxy_filters :create, :features => 'Openscap'

        skip_before_action :setup_has_many_params
        before_action :find_resources_before_create, :only => [:create]

        api :POST, "/compliance/oval_reports/:cname/:oval_policy_id/:date", N_("Upload an OVAL report - a list of CVEs for given host")
        param :cname, :identifier, :required => true
        param :oval_policy_id, :identifier, :required => true
        param :date, :identifier, :required => true

        def create
          ForemanOpenscap::Oval::Cves.new.create(@host, params.to_unsafe_h)
          if @host.errors.any?
            upload_fail @host.errors.full_messages
          else
            @host.refresh_statuses([ForemanOpenscap::OvalStatus])
            render :json => { :result => :ok }
          end
        end

        private

        def find_resources_before_create
          @host = ForemanOpenscap::Helper.find_host_by_name_or_uuid params[:cname]

          unless @host
            upload_fail(_('Could not find host identified by: %s') % params[:cname])
            return
          end
        end

        def upload_fail(msg)
          logger.error msg
          render :json => { :result => :fail, :errors => msg }, :status => :unprocessable_entity
        end

        def find_resource
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
foreman_openscap-8.0.0 app/controllers/api/v2/compliance/oval_reports_controller.rb
foreman_openscap-7.1.1 app/controllers/api/v2/compliance/oval_reports_controller.rb
foreman_openscap-7.1.0 app/controllers/api/v2/compliance/oval_reports_controller.rb
foreman_openscap-7.0.0 app/controllers/api/v2/compliance/oval_reports_controller.rb
foreman_openscap-6.0.0 app/controllers/api/v2/compliance/oval_reports_controller.rb
foreman_openscap-5.2.3 app/controllers/api/v2/compliance/oval_reports_controller.rb
foreman_openscap-5.2.2 app/controllers/api/v2/compliance/oval_reports_controller.rb
foreman_openscap-5.1.1 app/controllers/api/v2/compliance/oval_reports_controller.rb
foreman_openscap-5.2.1 app/controllers/api/v2/compliance/oval_reports_controller.rb
foreman_openscap-5.2.0 app/controllers/api/v2/compliance/oval_reports_controller.rb
foreman_openscap-5.1.0 app/controllers/api/v2/compliance/oval_reports_controller.rb
foreman_openscap-5.0.0 app/controllers/api/v2/compliance/oval_reports_controller.rb
foreman_openscap-4.3.3 app/controllers/api/v2/compliance/oval_reports_controller.rb
foreman_openscap-4.3.2 app/controllers/api/v2/compliance/oval_reports_controller.rb
foreman_openscap-4.3.1 app/controllers/api/v2/compliance/oval_reports_controller.rb
foreman_openscap-4.3.0 app/controllers/api/v2/compliance/oval_reports_controller.rb