Sha256: 0e9e2db3e0edc9c380559aeee8139b79a2ccdfab3e049586c3afdbf8c2ee4f33

Contents?: true

Size: 1.54 KB

Versions: 18

Compression:

Stored size: 1.54 KB

Contents

require 'uri'

module ForemanSalt
  module Api
    module V2
      class JobsController < ::ForemanSalt::Api::V2::BaseController
        include ::Foreman::Controller::SmartProxyAuth
        add_smart_proxy_filters :upload, :features => 'Salt'

        def_param_group :job do
          param :job, Hash, :required => true, :action_aware => true do
            param :job_id, Integer, :required => true, :desc => N_('JID')
            param :function, String, :required => true, :desc => N_('Function')
            param :result, Hash, :required => true, :desc => N_('Result')
          end
        end

        api :POST, '/upload', N_('Upload a Job')
        param_group :job, :as => :upload

        def upload
          Rails.logger.info("Processing job #{params[:job][:job_id]} from Salt.")
          case params[:job][:function]
          when 'state.highstate'
            task = ForemanTasks.async_task(::Actions::ForemanSalt::ReportImport, params[:job], detected_proxy.try(:id))
            render :json => { :task_id => task.id }
          else
            render :json => { :message => 'Unsupported function' }, :status => :unprocessable_entity
          end
        rescue ::Foreman::Exception => e
          render :json => { :message => e.to_s }, :status => :unprocessable_entity
        end

        def resource_class
          ::Report
        end

        private

        def action_permission
          case params[:action]
          when 'upload'
            :create
          else
            super
          end
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
foreman_salt-8.0.4 app/controllers/foreman_salt/api/v2/jobs_controller.rb
foreman_salt-9.0.1 app/controllers/foreman_salt/api/v2/jobs_controller.rb
foreman_salt-10.0.0 app/controllers/foreman_salt/api/v2/jobs_controller.rb
foreman_salt-9.0.0 app/controllers/foreman_salt/api/v2/jobs_controller.rb
foreman_salt-8.0.3 app/controllers/foreman_salt/api/v2/jobs_controller.rb
foreman_salt-8.0.2 app/controllers/foreman_salt/api/v2/jobs_controller.rb
foreman_salt-8.0.1 app/controllers/foreman_salt/api/v2/jobs_controller.rb
foreman_salt-7.0.3 app/controllers/foreman_salt/api/v2/jobs_controller.rb
foreman_salt-8.0.0 app/controllers/foreman_salt/api/v2/jobs_controller.rb
foreman_salt-7.0.2 app/controllers/foreman_salt/api/v2/jobs_controller.rb
foreman_salt-6.0.1 app/controllers/foreman_salt/api/v2/jobs_controller.rb
foreman_salt-7.0.1 app/controllers/foreman_salt/api/v2/jobs_controller.rb
foreman_salt-7.0.0 app/controllers/foreman_salt/api/v2/jobs_controller.rb
foreman_salt-6.0.0 app/controllers/foreman_salt/api/v2/jobs_controller.rb
foreman_salt-5.0.1 app/controllers/foreman_salt/api/v2/jobs_controller.rb
foreman_salt-5.0.0 app/controllers/foreman_salt/api/v2/jobs_controller.rb
foreman_salt-4.0.1 app/controllers/foreman_salt/api/v2/jobs_controller.rb
foreman_salt-4.0.0 app/controllers/foreman_salt/api/v2/jobs_controller.rb