smart_proxy_remote_execution_ssh 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTEyZjNlZjgzOGU2ODkzNmYyMGM1NTgwNWZjM2VjZmU2NDljZmEwMw==
4
+ ZmFjY2VkY2YyMTZhNmM4MTQ1ZGI5NTA3ZTRjMDIzYTZiNzFmNzU5Mg==
5
5
  data.tar.gz: !binary |-
6
- YjVmNmNiNDdiNTA5ZTU1YjNiNzNkMzcxOTkxZDY3YTgwN2QxYjBhNQ==
6
+ MWRkNzJjZDdjNWMyNTI4NTA2NDI0NDAyZWI4ZmY5MjVkM2E5Njk5Yw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NmJmOTc3Njg3MmE5Yzk0NWQ0MjI3MmMwYjM0Mjk3Mzg3NWYxZDY2ZWI0YzNi
10
- MjE1MDBkMjMwYTc0N2FlYjUyY2Q1MzgwZTQ0NzA5YzIwYmUyNTBlNzQ0NzI1
11
- OTZhOGU5MWMyZGU5MzE1YjI4MzhmMWIwYjg5YzNmNTkzNGVkMjM=
9
+ Y2IwYTA4OTgwYTcxMjEzODg4NDRjYWQwODE0NWEwM2QxN2ZlZDlkYmI0MDEz
10
+ OGZkOGM0Y2M2NjZlNjg1ODJkNmFmYmJmMjU2MWE4NjllOWNkZDVkY2U3YWZi
11
+ NWZkNTBlM2I5ZDgwNDU5YWU2YTVkMGQ0MTM0YzJlYzA5MjE2MWE=
12
12
  data.tar.gz: !binary |-
13
- NWRjNDU2YzgzNzAxM2NlMDliYTY3MTE5MDM3OTRkN2NiMzVmNmVlNTgxNTE4
14
- YTcyMjY5YTJlZmE0NTkxYTJlOGNhM2ZmODEzZDE4ZWIwOTU4NDIyN2U2ZjFj
15
- MWZhNTMzNDNkN2Y5ZDU4ZDFhNmU0ZTA4NWRlNGI1YjRhODU3NjE=
13
+ M2IzMGY4ZDI2NjA5ZGEyMTk3YWM5NGEyODNkMjFlYjk2ZWUwOTkwMzAyNTc5
14
+ YTJlODIyMmM4N2JhODIwY2M5NzE4YzA5NWI2ZWEwZjFlNDAwYTY3NzRkNDli
15
+ MGU0OTBhMzQ0ZDU4ZDA1MzcwYmI3Y2IxZjA2YzBkN2JlMDNiNTM=
@@ -17,13 +17,7 @@ module Proxy::RemoteExecution::Ssh
17
17
  when nil
18
18
  init_run
19
19
  when CommandUpdate
20
- update = event
21
- output[:result].concat(update.buffer_to_hash)
22
- if update.exit_status
23
- finish_run(update)
24
- else
25
- suspend
26
- end
20
+ process_update(event)
27
21
  when Dynflow::Action::Cancellable::Cancel
28
22
  kill_run
29
23
  when Dynflow::Action::Skip
@@ -32,9 +26,8 @@ module Proxy::RemoteExecution::Ssh
32
26
  raise "Unexpected event #{event.inspect}"
33
27
  end
34
28
  rescue => e
35
- action_logger.error e
36
- output[:result] << Connector::DebugData.new("#{e.class}: #{e.message}").to_hash
37
- output[:exit_status] = "PROXY_ERROR"
29
+ action_logger.error(e)
30
+ process_update(CommandUpdate.new(CommandUpdate.encode_exception("Proxy error", e)))
38
31
  end
39
32
 
40
33
  def finalize
@@ -72,6 +65,15 @@ module Proxy::RemoteExecution::Ssh
72
65
  output[:exit_status] = update.exit_status
73
66
  end
74
67
 
68
+ def process_update(update)
69
+ output[:result].concat(update.buffer_to_hash)
70
+ if update.exit_status
71
+ finish_run(update)
72
+ else
73
+ suspend
74
+ end
75
+ end
76
+
75
77
  def failed_run?
76
78
  output[:exit_status] != 0
77
79
  end
@@ -22,9 +22,9 @@ module Proxy::RemoteExecution::Ssh
22
22
  def async_run(command)
23
23
  started = false
24
24
  session.open_channel do |channel|
25
- channel.on_data { |ch, data| yield CommandUpdate::StdoutData.new(data) }
25
+ channel.on_data { |ch, data| yield CommandUpdate::StdoutData.new(handle_encoding(data)) }
26
26
 
27
- channel.on_extended_data { |ch, type, data| yield CommandUpdate::StderrData.new(data) }
27
+ channel.on_extended_data { |ch, type, data| yield CommandUpdate::StderrData.new(handle_encoding(data)) }
28
28
 
29
29
  # standard exit of the command
30
30
  channel.on_request("exit-status") { |ch, data| yield CommandUpdate::StatusData.new(data.read_long) }
@@ -120,6 +120,14 @@ module Proxy::RemoteExecution::Ssh
120
120
 
121
121
  private
122
122
 
123
+ def handle_encoding(data)
124
+ if data.is_a? String
125
+ data.force_encoding('UTF-8')
126
+ else
127
+ data
128
+ end
129
+ end
130
+
123
131
  def session
124
132
  @session ||= begin
125
133
  @logger.debug("opening session to #{@user}@#{@host}")
@@ -30,7 +30,14 @@ module Proxy::RemoteExecution::Ssh
30
30
  end
31
31
  output_path = File.join(File.dirname(remote_script), 'output')
32
32
 
33
- @connector.async_run("#{su_prefix}#{remote_script} | /usr/bin/tee #{output_path}") do |data|
33
+ # pipe the output to tee while capturing the exit code
34
+ script = <<-SCRIPT
35
+ exec 4>&1
36
+ exit_code=`((#{su_prefix}#{remote_script}; echo $?>&3 ) | /usr/bin/tee #{output_path} ) 3>&1 >&4`
37
+ exec 4>&-
38
+ exit $exit_code
39
+ SCRIPT
40
+ @connector.async_run(script) do |data|
34
41
  @command_buffer << data
35
42
  end
36
43
  rescue => e
@@ -1,7 +1,7 @@
1
1
  module Proxy
2
2
  module RemoteExecution
3
3
  module Ssh
4
- VERSION = '0.0.4'
4
+ VERSION = '0.0.5'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_remote_execution_ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
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: 2015-08-27 00:00:00.000000000 Z
11
+ date: 2015-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler