1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Use Net::SSH's KeyManager to detect ssh-agent

The presence of ENV['SSH_AUTH_SOCK'] is necessary but not sufficient for
ssh-agent support (e.g. no agent may be listening on the socket; the
listening agent may be SSH2-compatible and hence currently unsupported)
so it is better to delegate this decision to Net::SSH.
This commit is contained in:
David 2011-01-22 16:23:49 +08:00 committed by Wesley Beary
parent 99298851f7
commit 7aa7939d3b

View file

@ -2,9 +2,6 @@ module Fog
module SSH
def self.new(address, username, options = {})
unless options[:key_data] || options[:keys] || options[:password] || ENV['SSH_AUTH_SOCK']
raise ArgumentError.new(':key_data, :keys, :password or ENV[\'SSH_AUTH_SOCK\'] are required to initialize SSH')
end
if Fog.mocking?
Fog::SSH::Mock.new(address, username, options)
else
@ -40,6 +37,13 @@ module Fog
def initialize(address, username, options)
require 'net/ssh'
key_manager = Net::SSH::Authentication::KeyManager.new(nil, options)
unless options[:key_data] || options[:keys] || options[:password] || key_manager.agent
raise ArgumentError.new(':key_data, :keys, :password or a loaded ssh-agent is required to initialize SSH')
end
@address = address
@username = username
@options = { :paranoid => false }.merge(options)