pais_legacy 2.6.16 → 2.6.17

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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b14cd12b4599a01e634b5402905338ea560ed612fb3e741353996f803681edf
4
- data.tar.gz: 7b09991342fb3d5a32f44038813ecc1ac6d10be4b268f39dcbfaa8ebe8ab6d01
3
+ metadata.gz: 4bc027926acd33cf21596f062b32a7df8e255025e55ee0d91430efc731b24eaf
4
+ data.tar.gz: 6cdb3bad8eff90e4e092f5ee5b8ac7bfa5157c80e9902ae8eaecf33e96fcfb2b
5
5
  SHA512:
6
- metadata.gz: 717c645f192c85c726a43cfbc5e3407044fe17dc2555c49b71bed9517ecfce4917787cc1a4440259c9e35126c19f1631d4a1dd198934a26f175d8428bbf7c4f2
7
- data.tar.gz: 37ef988bcc0f47a31dcc47f612dd9f0af0c3429984b71b1ce4bd4ed788dd15507f22df5884e35243354ed4ea344c072746063ec2a851b67df43ce0b99a38ac35
6
+ metadata.gz: 69c8e7b80e89a51907efeeae410cb387453b46884bc573ba00ea8a488c054f05f954b5801bc19cfc8b9a0aa3c782a6781df1ec23b3ad5e1ed091e55c8c6be849
7
+ data.tar.gz: 1a86989dbb53199054fed3d54bc795595a8c41c4a941c68ca9f41d0bda64c70656302c1afe5ff91ea193d54b999aeb3ef423edb31cd5354379e4190f9ea675dc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pais_legacy (2.6.15)
4
+ pais_legacy (2.6.17)
5
5
  net-ssh
6
6
  pastel (~> 0.8)
7
7
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PaisLegacy
4
- VERSION = "2.6.16"
4
+ VERSION = "2.6.17"
5
5
  end
data/lib/pais_legacy.rb CHANGED
@@ -31,36 +31,50 @@ module PaisLegacy
31
31
  end
32
32
 
33
33
  def self.execute_ssh_command(command)
34
- output = ''
34
+ stdout = ''
35
+ stderr = ''
36
+ exit_status = nil
35
37
  retries = 0
36
38
 
37
39
  begin
38
-
39
- # Start an SSH session
40
+ stdout = ''
41
+ stderr = ''
42
+ exit_status = nil
43
+
44
+ # Start an SSH session.
45
+ #
46
+ # No pty is requested, deliberately. A pty merges the remote stderr
47
+ # into stdout, so any notice from the remote side (a `docker compose`
48
+ # "variable is not set" WARN, an ANSI colour code, a 4GL error) lands
49
+ # in the middle of the JSON we are about to parse. A pty also sets
50
+ # SSH_TTY, which makes the remote `fglgo` wrapper take its interactive
51
+ # branch: it names the 4GL container after the tty number and stops
52
+ # whatever already holds that name, so two callers landing on the same
53
+ # recycled tty number collide with each other.
40
54
  Net::SSH.start(SERVER,USER,keys: [KEY]) do |ssh|
41
55
  # Open a new SSH channel
42
56
  ssh.open_channel do |channel|
43
- # Request a pseudo-tty
44
- channel.request_pty do |ch, success|
45
- raise 'Could not obtain pty' unless success
46
-
47
- # Execute the command
48
- ch.exec(command) do |ch, success|
49
- raise 'Could not execute command' unless success
50
-
51
- # Collect the data received from the command's standard output
52
- ch.on_data do |c, data|
53
- output += data
54
- end
55
-
56
- # Collect the data received from the command's standard error
57
- ch.on_extended_data do |c, type, data|
58
- output += "stderr: #{data}"
59
- end
60
-
61
- ch.on_close do
62
- puts 'Command execution finished' if ENV['DEBUG'] == 'true'
63
- end
57
+ # Execute the command
58
+ channel.exec(command) do |ch, success|
59
+ raise 'Could not execute command' unless success
60
+
61
+ # Collect the data received from the command's standard output
62
+ ch.on_data do |c, data|
63
+ stdout += data
64
+ end
65
+
66
+ # Collect the data received from the command's standard error,
67
+ # kept apart from stdout so it cannot corrupt the payload
68
+ ch.on_extended_data do |c, type, data|
69
+ stderr += data
70
+ end
71
+
72
+ ch.on_request('exit-status') do |c, data|
73
+ exit_status = data.read_long
74
+ end
75
+
76
+ ch.on_close do
77
+ puts 'Command execution finished' if ENV['DEBUG'] == 'true'
64
78
  end
65
79
  end
66
80
  end
@@ -69,31 +83,27 @@ module PaisLegacy
69
83
  ssh.loop
70
84
  end
71
85
 
72
- rescue Net::SSH::ConnectionTimeout => e
86
+ rescue Net::SSH::ConnectionTimeout, Errno::ECONNRESET => e
73
87
  retries += 1
74
88
  if retries <= MAX_RETRIES
75
- puts "Connection timed out, retrying (#{retries}/#{MAX_RETRIES})..." if ENV['DEBUG'] == 'true'
89
+ puts "#{e.class}, retrying (#{retries}/#{MAX_RETRIES})..." if ENV['DEBUG'] == 'true'
76
90
  sleep RETRY_DELAY
77
91
  retry
78
- else
79
- puts 'Max retries reached. Could not connect.' if ENV['DEBUG'] == 'true'
80
92
  end
93
+ raise Error, "#{command}: #{e.class} after #{MAX_RETRIES} retries"
94
+ end
81
95
 
82
- rescue Errno::ECONNRESET => e
83
- retries += 1
84
- if retries <= MAX_RETRIES
85
- puts "Connection reset by peer, retrying (#{retries}/#{MAX_RETRIES})..." if ENV['DEBUG'] == 'true'
86
- sleep RETRY_DELAY
87
- retry
88
- else
89
- puts 'Max retries reached. Could not connect.' if ENV['DEBUG'] == 'true'
90
- end
96
+ # Fail loudly rather than handing back a partial or empty payload for
97
+ # the caller to trip over in JSON.parse.
98
+ unless exit_status.nil? || exit_status.zero?
99
+ raise Error, "#{command} exited #{exit_status}: #{stderr.strip}"
100
+ end
91
101
 
92
- rescue StandardError => e
93
- puts "An error occurred: #{e.message}" if ENV['DEBUG'] == 'true'
102
+ if stdout.empty? && !stderr.empty?
103
+ raise Error, "#{command} produced no output: #{stderr.strip}"
94
104
  end
95
105
 
96
- output
106
+ stdout
97
107
  end
98
108
 
99
109
  # delegate :execute_ssh_command, to: :class
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pais_legacy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.16
4
+ version: 2.6.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Pope
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
10
+ date: 2026-09-15 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: pastel
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  requirements: []
77
- rubygems_version: 3.6.9
77
+ rubygems_version: 3.6.2
78
78
  specification_version: 4
79
79
  summary: PAIS Legacy API Wrapper
80
80
  test_files: []