Skip to content

Commit

Permalink
Merge pull request #554 from inspec/zenspider/ssh/fix
Browse files Browse the repository at this point in the history
Refactor with_sudo_pty to BaseConnection (no-op) and SshConnection.
  • Loading branch information
tas50 committed Jan 15, 2020
2 parents 50bf636 + 8867db9 commit ab85356
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
11 changes: 1 addition & 10 deletions lib/train/extras/command_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ def initialize(backend, options)
@user = options[:user]
end

def with_sudo_pty
old_pty = backend.transport_options[:pty]
backend.transport_options[:pty] = true if @sudo

yield
ensure
backend.transport_options[:pty] = old_pty
end

# (see CommandWrapperBase::verify)
def verify
cmd = if @sudo
Expand All @@ -72,7 +63,7 @@ def verify
end

# rubocop:disable Style/BlockDelimiters
res = with_sudo_pty {
res = @backend.with_sudo_pty {
@backend.run_command(cmd)
}
return nil if res.exit_status == 0
Expand Down
4 changes: 4 additions & 0 deletions lib/train/plugins/base_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def initialize(options = nil)
end
end

def with_sudo_pty
yield
end

# Returns cached client if caching enabled. Otherwise returns whatever is
# given in the block.
#
Expand Down
9 changes: 9 additions & 0 deletions lib/train/transports/ssh_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ def obscured_options
options_to_print
end

def with_sudo_pty
old_pty = backend.transport_options[:pty]
backend.transport_options[:pty] = true if @sudo

yield
ensure
backend.transport_options[:pty] = old_pty
end

private

PING_COMMAND = "echo '[SSH] Established'".freeze
Expand Down

0 comments on commit ab85356

Please sign in to comment.