Sha256: 7286f175d9473cc2a784d8ced09480ae886bbd2afaad4022cc1b36524771da42

Contents?: true

Size: 1.88 KB

Versions: 6

Compression:

Stored size: 1.88 KB

Contents

# frozen_string_literal: true

module ForemanAcd
  # Class to run remote execution jobs
  class RemoteExecutionController < JobInvocationsController
    def new
      set_app_instance
      result, job = init_configuration

      if result.success == true
        @composer = job
      else
        redirect_to(app_instances_path, :error => _("Could not create remote execution job to configure the app '%{app_instance}': %{msg}") % {
          :app_instance => @app_instance, :msg => result.error
        })
      end
    end

    def create
      customize_first = params[:customize] || false
      begin
        set_app_instance
        result, job = init_configuration

        unless result.success == true
          return redirect_to(app_instances_path, :error => _("Could not create remote execution job to configure the app '%{app_instance}': %{msg}") % {
            :app_instance => @app_instance, :msg => result.error
          })
        end

        @composer = job
        if customize_first == false
          @composer.trigger!
          redirect_to job_invocation_path(@composer.job_invocation)
        else
          # redirect to the job itself if we want to customize the job
          render :action => 'new'
        end
      rescue StandardError => e
        redirect_to app_instances_path, :error => _("#{job}, #{e}")
      end
    end

    # to overcome the isolated namespace engine difficulties with paths
    helper Rails.application.routes.url_helpers
    def _routes
      Rails.application.routes
    end

    private

    def set_app_instance
      @app_instance = ForemanAcd::AppInstance.find_by(:id => params[:id])
    end

    def init_configuration
      logger.debug("Creating job to configure the app #{@app_instance}. Customize first: #{params[:customize]}")
      app_configurator = ForemanAcd::AppConfigurator.new(@app_instance)
      app_configurator.configure
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
foreman_acd-0.11.0 app/controllers/foreman_acd/remote_execution_controller.rb
foreman_acd-0.10.0 app/controllers/foreman_acd/remote_execution_controller.rb
foreman_acd-0.9.7 app/controllers/foreman_acd/remote_execution_controller.rb
foreman_acd-0.9.5 app/controllers/foreman_acd/remote_execution_controller.rb
foreman_acd-0.9.4 app/controllers/foreman_acd/remote_execution_controller.rb
foreman_acd-0.9.3 app/controllers/foreman_acd/remote_execution_controller.rb