Sha256: 60b08d398d845671147e0ff7e9e3130abfc7ecaa66107b625b5712fdc7a9f9d9
Contents?: true
Size: 1.19 KB
Versions: 5
Compression:
Stored size: 1.19 KB
Contents
class Kuroko2::Api::JobInstancesController < Kuroko2::Api::ApplicationController include Garage::RestfulActions validates :create do hash :env, description: 'Env variables to launch an instance' do |env| env.to_h.all? { |_, v| v.is_a?(String) } end end private def require_resources protect_resource_as Kuroko2::Api::JobInstanceResource end def create_resource definition = Kuroko2::JobDefinition.find(params[:job_definition_id]) unless definition.api_allowed? raise HTTP::Forbidden.new("#{definition.name} is not allowed to be executed via API") end instance = definition.create_instance( script: definition.script.prepend(env_script), launched_by: "instances API (#{basic_user_name})" ) Kuroko2::Api::JobInstanceResource.new(instance) end def require_resource instance = Kuroko2::JobInstance.find(params[:id]) @resource = Kuroko2::Api::JobInstanceResource.new(instance) end def env_script return '' unless params[:env] params[:env].permit!.to_h.map { |key, value| "env: #{key}='#{value.gsub("'", "\\\\'")}'" }.join("\n").concat("\n") end # Don't set location header def location nil end end
Version data entries
5 entries across 5 versions & 1 rubygems