lib/kitchen/transport/ssh.rb in test-kitchen-3.3.0 vs lib/kitchen/transport/ssh.rb in test-kitchen-3.3.1
- old
+ new
@@ -14,10 +14,11 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require_relative "../../kitchen"
+require_relative "../util"
require "fileutils" unless defined?(FileUtils)
require "net/ssh" unless defined?(Net::SSH)
require "net/ssh/gateway"
require "net/ssh/proxy/http"
@@ -100,11 +101,13 @@
end
# (see Base#cleanup!)
def cleanup!
if @connection
- logger.debug("[SSH] shutting previous connection #{@connection}")
+ string_to_mask = "[SSH] shutting previous connection #{@connection}"
+ masked_string = Util.mask_values(string_to_mask, %w{password ssh_http_proxy_password})
+ logger.debug(masked_string)
@connection.close
@connection = @connection_options = nil
end
end
@@ -123,21 +126,25 @@
# (see Base::Connection#close)
def close
return if @session.nil?
- logger.debug("[SSH] closing connection to #{self}")
+ string_to_mask = "[SSH] closing connection to #{self}"
+ masked_string = Util.mask_values(string_to_mask, %w{password ssh_http_proxy_password})
+ logger.debug(masked_string)
session.close
ensure
@session = nil
end
# (see Base::Connection#execute)
def execute(command)
return if command.nil?
- logger.debug("[SSH] #{self} (#{command})")
+ string_to_mask = "[SSH] #{self} (#{command})"
+ masked_string = Util.mask_values(string_to_mask, %w{password ssh_http_proxy_password})
+ logger.debug(masked_string)
exit_code = execute_with_exit_code(command)
if exit_code != 0
raise Transport::SshFailed.new(
"SSH exited (#{exit_code}) for command: [#{command}]",
@@ -350,11 +357,13 @@
# @return [Net::SSH::Connection::Session] the SSH connection session
# @api private
def retry_connection(opts)
log_msg = "[SSH] opening connection to #{self}"
log_msg += " via #{ssh_gateway_username}@#{ssh_gateway}:#{ssh_gateway_port}" if ssh_gateway
- logger.debug(log_msg)
+ masked_string = Util.mask_values(log_msg, %w{password ssh_http_proxy_password})
+
+ logger.debug(masked_string)
yield
rescue *RESCUE_EXCEPTIONS_ON_ESTABLISH => e
if (opts[:retries] -= 1) > 0
message = if opts[:message]
logger.debug("[SSH] connection failed (#{e.inspect})")
@@ -539,11 +548,11 @@
end
# Creates a new SSH Connection instance and save it for potential future
# reuse.
#
- # @param options [Hash] conneciton options
+ # @param options [Hash] connection options
# @return [Ssh::Connection] an SSH Connection instance
# @api private
def create_new_connection(options, &block)
cleanup!
@connection_options = options
@@ -553,10 +562,12 @@
# Return the last saved SSH connection instance.
#
# @return [Ssh::Connection] an SSH Connection instance
# @api private
def reuse_connection
- logger.debug("[SSH] reusing existing connection #{@connection}")
+ string_to_mask = "[SSH] reusing existing connection #{@connection}"
+ masked_string = Util.mask_values(string_to_mask, %w{password ssh_http_proxy_password})
+ logger.debug(masked_string)
yield @connection if block_given?
@connection
end
end
end