The Ping::LDAP class encapsulates methods for LDAP pings.
Creates and returns a new Ping::LDAP object. The default timeout is 5 seconds.
uri string is expected to be a full URI with scheme (ldap/ldaps) and optionally the port (else default port is assumed) e.g.
ldap://my.ldap.host.com ldap://my.ldap.host.com:1389 ldaps://my.ldap.host.com ldaps://my.ldap.host.com:6636
If a plain hostname is provided as the uri, a default port of 389 is assumed
# File lib/net/ping/ldap.rb, line 42 def initialize(uri=nil, timeout=5) host, port = decode_uri(uri) super(host, port, timeout) end
constructs the LDAP configuration structure
# File lib/net/ping/ldap.rb, line 64 def config { :host => uri.host, :port => uri.port, :encryption => encryption }.merge( (username && password) ? { :auth => {:method => :simple, :username => username, :password => password} } : { :auth => {:method => :anonymous} } ) end
method used to decode uri string
# File lib/net/ping/ldap.rb, line 49 def decode_uri(value) @uri = URI.parse(value) if uri.scheme =~ /ldap/ p = @port = uri.port h = @host = uri.host @encryption = uri.scheme=='ldaps' ? :simple_tls : nil else h = value p = 389 end [h, p] end
# File lib/net/ping/ldap.rb, line 26 def encryption=(value) @encryption = (value.is_a? Symbol) ? value : value.to_sym end
perform ping, optionally providing the ping destination uri
# File lib/net/ping/ldap.rb, line 78 def ping(host = nil) decode_uri(host) if host super(@host) bool = false start_time = Time.now begin Timeout.timeout(@timeout) do Net::LDAP.new( config ).bind end rescue Net::LDAP::LdapError => e @exception = e.message rescue Exception => e @exception = e.message else bool = true end # There is no duration if the ping failed @duration = Time.now - start_time if bool bool end
Generated with the Darkfish Rdoc Generator 2.