class LearnOpen::Adapters::SshAdapter

Constants

SSH_AUTH_FAILURE_EXIT_STATUS
SSH_AUTH_SUCCESS_EXIT_STATUS

Attributes

hostname[R]
user[R]

Public Class Methods

new(user:, hostname:) click to toggle source
# File lib/learn_open/adapters/ssh_adapter.rb, line 9
def initialize(user:, hostname:)
  @user = user
  @hostname = hostname
end

Public Instance Methods

authenticated?() click to toggle source
# File lib/learn_open/adapters/ssh_adapter.rb, line 22
def authenticated?
  _stdout, stderr, status = LearnOpen.system_adapter.run_command_with_capture("ssh -T #{user}@#{hostname}")

  case status.exitstatus
  when SSH_AUTH_SUCCESS_EXIT_STATUS
    true
  when SSH_AUTH_FAILURE_EXIT_STATUS
    case stderr
    when /permission denied/i
      false
    else
      raise LearnOpen::Adapters::SshAdapter::UnknownError
    end
  else
    raise LearnOpen::Adapters::SshAdapter::UnknownError
  end
end
public_key() click to toggle source
# File lib/learn_open/adapters/ssh_adapter.rb, line 14
def public_key
  File.read("#{ENV['HOME']}/.ssh/id_rsa.pub").chomp
end
unauthenticated?() click to toggle source
# File lib/learn_open/adapters/ssh_adapter.rb, line 18
def unauthenticated?
  !authenticated?
end