foreman_remote_execution_core 1.3.1 → 1.4.0

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: e1576329ece4e20e9506b989b77557686d030c329c71f70386c7415e93a73e24
4
- data.tar.gz: 4021d34ddbaa469bb1f4152c0a3c404c976a97910422a6fd60868661992ab774
3
+ metadata.gz: dffd5715e2f9f015bb0797db3ac51bbbd8398032459ba8108bb7b7b015edefaa
4
+ data.tar.gz: 5c6092674e23f651612964b94b3ba33e07f3be381d634767e94cfaa204f6bebb
5
5
  SHA512:
6
- metadata.gz: b0ce710cc252baca86acb51cfe294b76f8de319b5516bc8f303252fff52a8ef1e074c34ea00f7bd179b2811dc85daf292035a2736cb421046aa46e2a37137d73
7
- data.tar.gz: 65092102cb80436b6de9ce165905e8d87c387bf70256b244224d780cd2335f43b0323a06afed5c72e78fa8297566dcbe01f0624dee89b25645d8e2bf292d91a4
6
+ metadata.gz: c8bb7142e790e7724fd2e81bc80c95c3d542552003055c9ef4f1c71149ed9c8c64efa9fb701f47eccd62a7f54c31290f984ad50cf1eb2e5612c32ba14a2e08b7
7
+ data.tar.gz: c4ee503e2ca8fdced721e5b802a4b0e7fad7824dbeb12bbedbc959704701e3716cd195048e764745012f68fbf429f1c4e55ee4725d705fb830ea302f40f6b60f
@@ -8,9 +8,7 @@ rescue LoadError; end
8
8
  # rubocop:enable Lint/SuppressedException:
9
9
 
10
10
  module ForemanRemoteExecutionCore
11
- class SudoUserMethod
12
- LOGIN_PROMPT = 'rex login: '.freeze
13
-
11
+ class EffectiveUserMethod
14
12
  attr_reader :effective_user, :ssh_user, :effective_user_password, :password_sent
15
13
 
16
14
  def initialize(effective_user, ssh_user, effective_user_password)
@@ -27,10 +25,6 @@ module ForemanRemoteExecutionCore
27
25
  end
28
26
  end
29
27
 
30
- def login_prompt
31
- LOGIN_PROMPT
32
- end
33
-
34
28
  def filter_password?(received_data)
35
29
  !@effective_user_password.empty? && @password_sent && received_data.match(Regexp.escape(@effective_user_password))
36
30
  end
@@ -39,52 +33,51 @@ module ForemanRemoteExecutionCore
39
33
  effective_user_password.empty? || password_sent
40
34
  end
41
35
 
36
+ def reset
37
+ @password_sent = false
38
+ end
39
+
42
40
  def cli_command_prefix
43
- "sudo -p '#{LOGIN_PROMPT}' -u #{effective_user} "
44
41
  end
45
42
 
46
- def reset
47
- @password_sent = false
43
+ def login_prompt
48
44
  end
49
45
  end
50
46
 
51
- class DzdoUserMethod < SudoUserMethod
52
- LOGIN_PROMPT = /password/i.freeze
47
+ class SudoUserMethod < EffectiveUserMethod
48
+ LOGIN_PROMPT = 'rex login: '.freeze
53
49
 
54
50
  def login_prompt
55
51
  LOGIN_PROMPT
56
52
  end
57
53
 
58
54
  def cli_command_prefix
59
- "dzdo -u #{effective_user} "
55
+ "sudo -p '#{LOGIN_PROMPT}' -u #{effective_user} "
60
56
  end
61
57
  end
62
58
 
63
- class SuUserMethod
64
- attr_accessor :effective_user, :ssh_user
59
+ class DzdoUserMethod < EffectiveUserMethod
60
+ LOGIN_PROMPT = /password/i.freeze
65
61
 
66
- def initialize(effective_user, ssh_user)
67
- @effective_user = effective_user
68
- @ssh_user = ssh_user
62
+ def login_prompt
63
+ LOGIN_PROMPT
69
64
  end
70
65
 
71
- def on_data(_, _)
66
+ def cli_command_prefix
67
+ "dzdo -u #{effective_user} "
72
68
  end
69
+ end
73
70
 
74
- def filter_password?(received_data)
75
- false
76
- end
71
+ class SuUserMethod < EffectiveUserMethod
72
+ LOGIN_PROMPT = /Password: /i.freeze
77
73
 
78
- def sent_all_data?
79
- true
74
+ def login_prompt
75
+ LOGIN_PROMPT
80
76
  end
81
77
 
82
78
  def cli_command_prefix
83
79
  "su - #{effective_user} -c "
84
80
  end
85
-
86
- def reset
87
- end
88
81
  end
89
82
 
90
83
  class NoopUserMethod
@@ -141,12 +134,13 @@ module ForemanRemoteExecutionCore
141
134
  NoopUserMethod.new
142
135
  elsif effective_user_method == 'sudo'
143
136
  SudoUserMethod.new(effective_user, ssh_user,
144
- options.fetch(:secrets, {}).fetch(:sudo_password, nil))
137
+ options.fetch(:secrets, {}).fetch(:effective_user_password, nil))
145
138
  elsif effective_user_method == 'dzdo'
146
139
  DzdoUserMethod.new(effective_user, ssh_user,
147
- options.fetch(:secrets, {}).fetch(:sudo_password, nil))
140
+ options.fetch(:secrets, {}).fetch(:effective_user_password, nil))
148
141
  elsif effective_user_method == 'su'
149
- SuUserMethod.new(effective_user, ssh_user)
142
+ SuUserMethod.new(effective_user, ssh_user,
143
+ options.fetch(:secrets, {}).fetch(:effective_user_password, nil))
150
144
  else
151
145
  raise "effective_user_method '#{effective_user_method}' not supported"
152
146
  end
@@ -176,12 +170,11 @@ module ForemanRemoteExecutionCore
176
170
 
177
171
  # the script that initiates the execution
178
172
  def initialization_script
173
+ su_method = @user_method.instance_of?(ForemanRemoteExecutionCore::SuUserMethod)
179
174
  # pipe the output to tee while capturing the exit code in a file
180
175
  <<-SCRIPT.gsub(/^\s+\| /, '')
181
- | sh <<WRAPPER
182
- | (#{@user_method.cli_command_prefix}#{@remote_script} < /dev/null; echo \\$?>#{@exit_code_path}) | /usr/bin/tee #{@output_path}
183
- | exit \\$(cat #{@exit_code_path})
184
- | WRAPPER
176
+ | sh -c "(#{@user_method.cli_command_prefix}#{su_method ? "'#{@remote_script} < /dev/null '" : "#{@remote_script} < /dev/null"}; echo \\$?>#{@exit_code_path}) | /usr/bin/tee #{@output_path}
177
+ | exit \\$(cat #{@exit_code_path})"
185
178
  SCRIPT
186
179
  end
187
180
 
@@ -1,3 +1,3 @@
1
1
  module ForemanRemoteExecutionCore
2
- VERSION = '1.3.1'.freeze
2
+ VERSION = '1.4.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_remote_execution_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Nečas
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-14 00:00:00.000000000 Z
11
+ date: 1980-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: foreman-tasks-core
@@ -60,7 +60,7 @@ homepage: https://github.com/theforeman/foreman_remote_execution
60
60
  licenses:
61
61
  - GPL-3.0
62
62
  metadata: {}
63
- post_install_message:
63
+ post_install_message:
64
64
  rdoc_options: []
65
65
  require_paths:
66
66
  - lib
@@ -75,8 +75,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  requirements: []
78
- rubygems_version: 3.0.3
79
- signing_key:
78
+ rubygems_version: 3.1.2
79
+ signing_key:
80
80
  specification_version: 4
81
81
  summary: Foreman remote execution - core bits
82
82
  test_files: []