Sha256: 88d66c66759a1cb89b309577bdcc29333e9bf3b2800429197af03d86ed882a99

Contents?: true

Size: 1.38 KB

Versions: 10

Compression:

Stored size: 1.38 KB

Contents

require 'picsolve_docker_builder/helpers/ssh_forward'
require 'picsolve_docker_builder/base'
require 'net/ssh'

module PicsolveDockerBuilder
  module Helpers
    # Ruby class that can forward a remote port over SSH
    class SshConnection
      include PicsolveDockerBuilder::Base
      attr_reader :options
      def initialize(opts)
        @options = opts
      end

      def connection
        @connection ||= Net::SSH.start(
          ssh_host,
          ssh_user,
          port: ssh_port
        )
      end

      def forward(*args)
        SshForward.forward(connection, *args)
      end

      def start
        log.debug "Connecting via ssh to host '#{ssh_user}@#{ssh_host}'"
        # start thread with ssh
        @thread = Thread.new do
          connection.loop { true }
        end
      end

      def stop
        return if @thread.nil?
        @thread.kill
        @thread.join
        log.debug \
          "Disconnected ssh connection to host '#{ssh_user}@#{ssh_host}'"
      end

      def ssh_user
        options[:ssh_user] = 'core'
      end

      def ssh_host
        options[:ssh_host]
      end

      def ssh_port
        options[:ssh_port] || 22
      end

      def remote_host
        options[:remote_host]
      end

      def remote_port
        options[:remote_port]
      end

      def local_port
        options[:local_port] || remote_port
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
picsolve_docker_builder-0.5.5 lib/picsolve_docker_builder/helpers/ssh_connection.rb
picsolve_docker_builder-0.5.4 lib/picsolve_docker_builder/helpers/ssh_connection.rb
picsolve_docker_builder-0.5.3 lib/picsolve_docker_builder/helpers/ssh_connection.rb
picsolve_docker_builder-0.5.2 lib/picsolve_docker_builder/helpers/ssh_connection.rb
picsolve_docker_builder-0.5.1 lib/picsolve_docker_builder/helpers/ssh_connection.rb
picsolve_docker_builder-0.5.0 lib/picsolve_docker_builder/helpers/ssh_connection.rb
picsolve_docker_builder-0.4.0 lib/picsolve_docker_builder/helpers/ssh_connection.rb
picsolve_docker_builder-0.3.2 lib/picsolve_docker_builder/helpers/ssh_connection.rb
picsolve_docker_builder-0.3.1 lib/picsolve_docker_builder/helpers/ssh_connection.rb
picsolve_docker_builder-0.3.0 lib/picsolve_docker_builder/helpers/ssh_connection.rb