Class: Spectre::SSH::Client
- Inherits:
-
Object
- Object
- Spectre::SSH::Client
- Defined in:
- lib/spectre/ssh.rb
Instance Method Summary collapse
-
#initialize(config, logger) ⇒ Client
constructor
A new instance of Client.
- #ssh(name, options = {}) ⇒ Object
Constructor Details
#initialize(config, logger) ⇒ Client
Returns a new instance of Client.
131 132 133 134 135 |
# File 'lib/spectre/ssh.rb', line 131 def initialize config, logger @config = config['ssh'] || {} @logger = logger @debug = config['debug'] end |
Instance Method Details
#ssh(name, options = {}) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/spectre/ssh.rb', line 137 def ssh(name, = {}, &) cfg = @config[name] || {} host = cfg['host'] || name username = [:username] || cfg['username'] password = [:password] || cfg['password'] opts = {} opts[:password] = password opts[:port] = [:port] || cfg['port'] || 22 ssh_key = [:key] || cfg['key'] opts[:keys] = [ssh_key] unless ssh_key.nil? opts[:passphrase] = [:passphrase] || cfg['passphrase'] opts[:auth_methods] = [] opts[:auth_methods].push('publickey') unless opts[:keys].nil? or opts[:keys].empty? opts[:auth_methods].push('password') unless opts[:password].nil? proxy_host = [:proxy_host] || cfg['proxy_host'] proxy_port = [:proxy_port] || cfg['proxy_port'] opts[:proxy] = Net::SSH::Proxy::HTTP.new(proxy_host, proxy_port) unless proxy_host.nil? if @debug opts[:verbose] = Logger::DEBUG opts[:logger] = @logger end ssh_con = SshConnection.new(host, username, opts, @logger) begin ssh_con.instance_eval(&) ensure ssh_con.close end end |