Sha256: 75aab393fbb1d330ef2e3ad4565c5818f517beb701325c321fd255e14940036e

Contents?: true

Size: 882 Bytes

Versions: 14

Compression:

Stored size: 882 Bytes

Contents

# frozen_string_literal: true

module Groundskeeper
  # Wraps ssh executable.
  class Ssh
    COMMAND = "ssh"
    DEFAULT_CONNECT_TIMEOUT_IN_S = 5
    # ssh arguments
    CONNECT_WITH_TIMEOUT = "-o ConnectTimeout=#{DEFAULT_CONNECT_TIMEOUT_IN_S}"
    REMOTE_ECHO =
      "%<options>s %<username>s@%<domain_name>s \"echo 'groundskeeper'\""

    attr_reader :domain_name, :ssh, :username

    def self.build(username, domain_name)
      new Executable.new(COMMAND), username, domain_name
    end

    def initialize(ssh, username, domain_name)
      @ssh = ssh
      @username = username
      @domain_name = domain_name
    end

    def can_connect?
      ssh.execute(format(REMOTE_ECHO,
                         options: CONNECT_WITH_TIMEOUT,
                         username: username,
                         domain_name: domain_name)).strip == "groundskeeper"
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
groundskeeper-bitcore-0.22.0 lib/groundskeeper/ssh.rb
groundskeeper-bitcore-0.21.0 lib/groundskeeper/ssh.rb
groundskeeper-bitcore-0.20.1 lib/groundskeeper/ssh.rb
groundskeeper-bitcore-0.19.0 lib/groundskeeper/ssh.rb
groundskeeper-bitcore-0.18.0 lib/groundskeeper/ssh.rb
groundskeeper-bitcore-0.17.0 lib/groundskeeper/ssh.rb
groundskeeper-bitcore-0.16.0 lib/groundskeeper/ssh.rb
groundskeeper-bitcore-0.15.0 lib/groundskeeper/ssh.rb
groundskeeper-bitcore-0.14.0 lib/groundskeeper/ssh.rb
groundskeeper-bitcore-0.13.0 lib/groundskeeper/ssh.rb
groundskeeper-bitcore-0.12.0 lib/groundskeeper/ssh.rb
groundskeeper-bitcore-0.11.0 lib/groundskeeper/ssh.rb
groundskeeper-bitcore-0.10.0 lib/groundskeeper/ssh.rb
groundskeeper-bitcore-0.9.0 lib/groundskeeper/ssh.rb