smart_proxy_dynflow 0.8.0 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8852c64e45de97691310f1c9fd17bef228a9ea87db2085377cee1cd404546752
4
- data.tar.gz: 54afa19849d245f44f8d5e03c69d82e30015ff95978b266cad0db3919eb82195
3
+ metadata.gz: 6444ef5fcad649ae35d106b149f2832ea50c4cbbf9d6a1be7575332e9585fe8b
4
+ data.tar.gz: 587ed9c21c9c0dd3e320e29c28eb3cf76904aa3222c901979fc8e29023630f16
5
5
  SHA512:
6
- metadata.gz: 4a1799f87c74aa10807ea642d217686f208fe2de5444b4a87c540a8685e419d4c88b272e03faa83a9756fa7ef4e996f3cd8195f730ae43e97800e4666fecae59
7
- data.tar.gz: ab1dd31d7555502d566803ba4e87965e2431bb6d32c67cc6e0e39f7ac1c6c5369e22b1b6c7f6e3abb8cfdcccf6b4432029ba10b277171931f6a5fa05ed792d8d
6
+ metadata.gz: 4b27f6de4ae4353b6fdb45334b920b66bea2de0dce26af6c4f52855e9e28641acd9ec917e8d313b8aafb9c70f7077fa9223417d943e9ac2a30d6c05995d66e0a
7
+ data.tar.gz: e0877874c73541ab78d2957693202959bbffce5771ff71c9f1bee0664c5f78bf180addece3668206662e70cf08481d3586ff88f82eef3fc293d9a837ccfca75d
@@ -36,7 +36,8 @@ module Proxy
36
36
 
37
37
  post "/tasks/launch/?" do
38
38
  params = MultiJson.load(request.body.read)
39
- launcher = launcher_class(params).new(world, callback_host(params, request), params.fetch('options', {}))
39
+ first_params = params['input']&.values&.first || {}
40
+ launcher = launcher_class(params).new(world, callback_host(first_params, request), params.fetch('options', {}))
40
41
  launcher.launch!(params['input'])
41
42
  launcher.results.to_json
42
43
  end
@@ -72,8 +73,13 @@ module Proxy
72
73
  private
73
74
 
74
75
  def callback_host(params, request)
75
- params.fetch('action_input', {})['proxy_url'] ||
76
- request.env.values_at('HTTP_X_FORWARDED_FOR', 'HTTP_HOST').compact.first
76
+ params.fetch('action_input', {})['proxy_url'] || callback_host_from_env(request)
77
+ end
78
+
79
+ def callback_host_from_env(request)
80
+ protocol = %w[yes on 1].include?(request.env['HTTPS'].to_s) ? 'https' : 'http'
81
+ host = request.env.values_at('HTTP_X_FORWARDED_FOR', 'HTTP_HOST').compact.first
82
+ "#{protocol}://#{host}"
77
83
  end
78
84
 
79
85
  def launcher_class(params)
@@ -28,8 +28,8 @@ module Proxy::Dynflow
28
28
 
29
29
  db_file = Settings.instance.database
30
30
  if db_file.nil? || db_file.empty?
31
- Log.instance.warn "Could not open DB for dynflow at '#{db_file}', " \
32
- "will keep data in memory. Restart will drop all dynflow data."
31
+ Log.instance.info "Using in-memory database (default behaviour). Restart will drop all dynflow data. " \
32
+ "To change this behaviour configure setting 'database'."
33
33
  else
34
34
  FileUtils.mkdir_p(File.dirname(db_file))
35
35
  db_conn_string += "/#{db_file}"
@@ -76,12 +76,12 @@ module Proxy
76
76
  out_read, out_write = IO.pipe
77
77
  err_read, err_write = IO.pipe
78
78
 
79
- @pid = spawn(*@command, :in => in_read, :out => out_write, :err => err_write)
80
- [in_read, out_write, err_write].each(&:close)
81
-
82
79
  @stdin.io = in_write
83
80
  @stdout.io = out_read
84
81
  @stderr.io = err_read
82
+
83
+ @pid = spawn(*@command, :in => in_read, :out => out_write, :err => err_write)
84
+ [in_read, out_write, err_write].each(&:close)
85
85
  rescue Errno::ENOENT => e
86
86
  [in_read, in_write, out_read, out_write, err_read, err_write].each(&:close)
87
87
  @pid = -1
@@ -158,8 +158,10 @@ module Proxy
158
158
  # @return [void]
159
159
  def finish
160
160
  close
161
- _pid, status = Process.wait2(@pid)
162
- @status = status.exitstatus
161
+ unless @pid == -1
162
+ _pid, status = Process.wait2(@pid)
163
+ @status = status.exitstatus
164
+ end
163
165
  end
164
166
  end
165
167
  end
@@ -1,5 +1,18 @@
1
1
  module Proxy::Dynflow
2
2
  module Runner
3
+ # This module expects to be included into a Runner action, where it can be
4
+ # used to simplify handling of long-running processes. However it tracks the
5
+ # running process as a group of instance variables, which has served us
6
+ # reasonably well in the past, but can be rather error prone.
7
+ #
8
+ # A better alternative to this is
9
+ # {::Proxy::Dynflow::Runner::ProcessManagerCommand}. It tracks the whole
10
+ # execution of a process under a single instance variable and uses a more
11
+ # robust {::Proxy::Dynflow::ProcessManager} under the hood. It also
12
+ # maintains the same interface and can be used as a drop-in replacement.
13
+ #
14
+ # This module is now soft-deprecated and
15
+ # {::Proxy::Dynflow::Runner::ProcessManagerCommand} should be used instead.
3
16
  module Command
4
17
  def initialize_command(*command)
5
18
  @command_out, @command_in, @command_pid = PTY.spawn(*command)
@@ -4,6 +4,7 @@ require 'smart_proxy_dynflow/runner/command'
4
4
 
5
5
  module Proxy::Dynflow
6
6
  module Runner
7
+ # This class is now soft-deprecated, see {::Proxy::Dynflow::Runner::Command}
7
8
  class CommandRunner < Base
8
9
  include Command
9
10
  end
@@ -2,13 +2,21 @@ require 'smart_proxy_dynflow/process_manager'
2
2
 
3
3
  module Proxy::Dynflow
4
4
  module Runner
5
+ # A convenience module which should be included into a Runner action. It
6
+ # leverages {::Proxy::Dynflow::ProcessManager} to reliably keep track of
7
+ # an external process and collect its output.
8
+ #
9
+ # The only expectation from the Runner action is to call
10
+ # {#initialize_command} somewhere and pass the command to be run to it.
5
11
  module ProcessManagerCommand
6
12
  def initialize_command(*command)
7
13
  @process_manager = ProcessManager.new(command)
8
14
  set_process_manager_callbacks(@process_manager)
9
15
  @process_manager.start!
10
16
  if @process_manager.done? && @process_manager.status == 255
11
- publish_exception("Error running command '#{command.join(' ')}'", @process_manager.stderr.to_s)
17
+ exception = RuntimeError.new(@process_manager.stderr.to_s)
18
+ exception.set_backtrace Thread.current.backtrace
19
+ publish_exception("Error running command '#{command.join(' ')}'", exception)
12
20
  end
13
21
  end
14
22
 
@@ -24,7 +32,7 @@ module Proxy::Dynflow
24
32
  end
25
33
 
26
34
  def refresh
27
- @process_manager.process(timeout: 0.1)
35
+ @process_manager.process(timeout: 0.1) unless @process_manager.done?
28
36
  publish_exit_status(@process_manager.status) if @process_manager.done?
29
37
  end
30
38
 
@@ -1,5 +1,5 @@
1
1
  module Proxy
2
2
  module Dynflow
3
- VERSION = '0.8.0'.freeze
3
+ VERSION = '0.8.2'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_dynflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Nečas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 1980-01-01 00:00:00.000000000 Z
11
+ date: 2022-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dynflow
@@ -208,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
208
  - !ruby/object:Gem::Version
209
209
  version: '0'
210
210
  requirements: []
211
- rubygems_version: 3.2.26
211
+ rubygems_version: 3.3.20
212
212
  signing_key:
213
213
  specification_version: 4
214
214
  summary: Dynflow runtime for Foreman smart proxy