Sha256: 8b19ca5315981286655617f4d8517158867898d720cda8a4a30d8cd30a586fbd

Contents?: true

Size: 1.53 KB

Versions: 4

Compression:

Stored size: 1.53 KB

Contents

module VagrantPlugins
  module Unison
    class SshCommand
      def initialize(machine, options)
        @machine = machine
        @options = options
      end

      def ssh
        %W[ssh #{ssh_auth} #{ssh_args}].compact.join(' ')
      end

      def ssh_args
        %W[
        #{ssh_port}
        #{proxy_command}
        #{ssh_log_options}
        #{ssh_options}
        #{identity}
        ].compact.join(' ')
      end

      def uri(unison_paths)
        username = @machine.config.unison.ssh_user
        host     = @machine.config.unison.ssh_host

        "ssh://#{username}@#{host}/#{unison_paths.guest}"
      end

      private

      def ssh_auth
        "#{@machine.config.unison.ssh_user}@#{@machine.config.unison.ssh_host}"
      end

      def ssh_port
        "-p #{@machine.config.unison.ssh_port}"
      end

      def ssh_log_options
        log_line = ''
        log_line = '-o LogLevel=quiet' unless @options[:verbose]
        log_line
      end

      def ssh_options
        ' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
      end

      def proxy_command
        command = @machine.ssh_info[:proxy_command]
        return nil unless command
        "-o ProxyCommand='#{command}'"
      end

      def identity
        if @machine.config.unison.ssh_use_agent
          ''
        else
          (%w[-o IdentitiesOnly=yes] << key_paths).join(' ')
        end
      end

      def key_paths
        @machine.ssh_info[:private_key_path].map { |p|
          "-i #{p.shellescape}"
        }.join(' ')
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vagrant-vaimo-unison-2.2.0 lib/vagrant-vaimo-unison/ssh_command.rb
vagrant-vaimo-unison-2.0.2 lib/vagrant-vaimo-unison/ssh_command.rb
vagrant-vaimo-unison-2.0.1 lib/vagrant-vaimo-unison/ssh_command.rb
vagrant-vaimo-unison-2.0.0 lib/vagrant-vaimo-unison/ssh_command.rb