Module: SmartProxyDynflowCore::Helpers

Defined in:
lib/smart_proxy_dynflow_core/helpers.rb

Instance Method Summary collapse

Instance Method Details

#authorize_with_ssl_clientObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/smart_proxy_dynflow_core/helpers.rb', line 7

def authorize_with_ssl_client
  if %w(yes on 1).include? request.env['HTTPS'].to_s
    if request.env['SSL_CLIENT_CERT'].to_s.empty?
      status 403
      # TODO: Use a logger
      STDERR.puts "No client SSL certificate supplied"
      halt MultiJson.dump(:error => "No client SSL certificate supplied")
    end
  else
    # TODO: Use a logger
    # logger.debug('require_ssl_client_verification: skipping, non-HTTPS request')
    puts 'require_ssl_client_verification: skipping, non-HTTPS request'
  end
end

#cancel_task(task_id) ⇒ Object



27
28
29
30
31
# File 'lib/smart_proxy_dynflow_core/helpers.rb', line 27

def cancel_task(task_id)
  execution_plan = world.persistence.load_execution_plan(task_id)
  cancel_events = execution_plan.cancel
  { :task_id => task_id, :canceled_steps_count => cancel_events.size }
end

#task_status(task_id) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/smart_proxy_dynflow_core/helpers.rb', line 33

def task_status(task_id)
  ep = world.persistence.load_execution_plan(task_id)
  ep.to_hash.merge(:actions => ep.actions.map(&:to_hash))
rescue KeyError => _e
  status 404
  {}
end

#tasks_count(state) ⇒ Object



41
42
43
44
45
46
# File 'lib/smart_proxy_dynflow_core/helpers.rb', line 41

def tasks_count(state)
  state ||= 'all'
  filter = state != 'all' ? { :filters => { :state => [state] } } : {}
  tasks = world.persistence.find_execution_plans(filter)
  { :count => tasks.count, :state => state }
end

#trigger_task(*args) ⇒ Object



22
23
24
25
# File 'lib/smart_proxy_dynflow_core/helpers.rb', line 22

def trigger_task(*args)
  triggered = world.trigger(*args)
  { :task_id => triggered.id }
end

#worldObject



3
4
5
# File 'lib/smart_proxy_dynflow_core/helpers.rb', line 3

def world
  SmartProxyDynflowCore::Core.world
end