Class: Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/direct_ssh/validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeValidator

Returns a new instance of Validator.



11
12
13
# File 'lib/direct_ssh/validator.rb', line 11

def initialize
    @direct = true
end

Instance Attribute Details

#directObject (readonly)

Returns the value of attribute direct.



9
10
11
# File 'lib/direct_ssh/validator.rb', line 9

def direct
  @direct
end

Instance Method Details

#start(host, user, options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/direct_ssh/validator.rb', line 15

def start(host, user, options={})
    options[:auth_methods] = ["publickey"]
    return Net::SSH.start(host, user, options)
rescue Net::SSH::AuthenticationFailed
    @direct = false

    3.times {
        options[:password] = ask("#{user}@#{host}'s password: ") { |q| q.echo = false }

        begin
            options[:auth_methods] = ["password"]
            return Net::SSH.start(host, user, options)
        rescue Net::SSH::AuthenticationFailed
        end
    }

    raise Net::SSH::AuthenticationFailed, 'Permission denied, please try again.'
end