Module: SmartProxyDynflowCore::Helpers
- Defined in:
- lib/smart_proxy_dynflow_core/helpers.rb
Instance Method Summary collapse
- #authorize_with_ssl_client ⇒ Object
- #authorize_with_token ⇒ Object
- #cancel_task(task_id) ⇒ Object
- #complete_task(task_id, params) ⇒ Object
- #task_status(task_id) ⇒ Object
- #tasks_count(state) ⇒ Object
- #trigger_task(*args) ⇒ Object
- #world ⇒ Object
Instance Method Details
#authorize_with_ssl_client ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/smart_proxy_dynflow_core/helpers.rb', line 23 def if %w[yes on 1].include? request.env['HTTPS'].to_s if request.env['SSL_CLIENT_CERT'].to_s.empty? Log.instance.error "No client SSL certificate supplied" halt 403, MultiJson.dump(:error => "No client SSL certificate supplied") else client_cert = OpenSSL::X509::Certificate.new(request.env['SSL_CLIENT_CERT']) unless SmartProxyDynflowCore::Core.instance.accepted_cert_serial == client_cert.serial Log.instance.error "SSL certificate with unexpected serial supplied" halt 403, MultiJson.dump(:error => "SSL certificate with unexpected serial supplied") end end else Log.instance.debug 'require_ssl_client_verification: skipping, non-HTTPS request' end end |
#authorize_with_token ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/smart_proxy_dynflow_core/helpers.rb', line 7 def if request.env.key? 'HTTP_AUTHORIZATION' if defined?(::ForemanTasksCore) auth = request.env['HTTP_AUTHORIZATION'] basic_prefix = /\ABasic / if !auth.to_s.empty? && auth =~ basic_prefix && ForemanTasksCore::OtpManager.authenticate(auth.gsub(basic_prefix, '')) 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
45 46 47 48 49 |
# File 'lib/smart_proxy_dynflow_core/helpers.rb', line 45 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 |
#complete_task(task_id, params) ⇒ Object
66 67 68 69 70 |
# File 'lib/smart_proxy_dynflow_core/helpers.rb', line 66 def complete_task(task_id, params) world.event(task_id, params['step_id'].to_i, ::ForemanTasksCore::Runner::ExternalEvent.new(params)) end |
#task_status(task_id) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/smart_proxy_dynflow_core/helpers.rb', line 51 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
59 60 61 62 63 64 |
# File 'lib/smart_proxy_dynflow_core/helpers.rb', line 59 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
40 41 42 43 |
# File 'lib/smart_proxy_dynflow_core/helpers.rb', line 40 def trigger_task(*args) triggered = world.trigger(*args) { :task_id => triggered.id } end |
#world ⇒ Object
3 4 5 |
# File 'lib/smart_proxy_dynflow_core/helpers.rb', line 3 def world SmartProxyDynflowCore::Core.world end |