Module: Proxy::Dynflow::Helpers
- Defined in:
- lib/smart_proxy_dynflow/helpers.rb
Instance Method Summary collapse
- #authorize_with_token(task_id:, clear: true) ⇒ Object
- #cancel_task(task_id) ⇒ Object
- #dispatch_external_event(task_id, params) ⇒ Object
- #task_status(task_id) ⇒ Object
- #tasks_count(state) ⇒ Object
- #trigger_task(*args) ⇒ Object
- #world ⇒ Object
Instance Method Details
#authorize_with_token(task_id:, clear: true) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/smart_proxy_dynflow/helpers.rb', line 8 def (task_id:, clear: true) if request.env.key? 'HTTP_AUTHORIZATION' if defined?(::Proxy::Dynflow) auth = request.env['HTTP_AUTHORIZATION'] basic_prefix = /\ABasic / if !auth.to_s.empty? && auth =~ basic_prefix && Proxy::Dynflow::OtpManager.authenticate(auth.gsub(basic_prefix, ''), expected_user: task_id, clear: clear) Log.instance.debug('authorized with token') return true end end halt 403, MultiJson.dump(:error => 'Invalid username or password supplied') end false end |
#cancel_task(task_id) ⇒ Object
30 31 32 33 34 |
# File 'lib/smart_proxy_dynflow/helpers.rb', line 30 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 |
#dispatch_external_event(task_id, params) ⇒ Object
51 52 53 54 55 |
# File 'lib/smart_proxy_dynflow/helpers.rb', line 51 def dispatch_external_event(task_id, params) world.event(task_id, params['step_id'].to_i, ::Proxy::Dynflow::Runner::ExternalEvent.new(params)) end |
#task_status(task_id) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/smart_proxy_dynflow/helpers.rb', line 36 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
44 45 46 47 48 49 |
# File 'lib/smart_proxy_dynflow/helpers.rb', line 44 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
25 26 27 28 |
# File 'lib/smart_proxy_dynflow/helpers.rb', line 25 def trigger_task(*args) triggered = world.trigger(*args) { :task_id => triggered.id } end |