Skip to content

Commit

Permalink
Update Ping::LDAP documentation
Browse files Browse the repository at this point in the history
* removed Gemfile from the project
  • Loading branch information
tardate committed Apr 30, 2011
1 parent 84dee6b commit 01f8ac7
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 34 deletions.
9 changes: 0 additions & 9 deletions Gemfile

This file was deleted.

16 changes: 0 additions & 16 deletions Gemfile.lock

This file was deleted.

25 changes: 25 additions & 0 deletions doc/ping.txt
Expand Up @@ -43,6 +43,7 @@
* Ping::HTTP
* Ping::ICMP
* Ping::WMI
* Ping::LDAP

All Ping classes are children of the Ping parent class (which should
never be instantiated directly).
Expand Down Expand Up @@ -135,6 +136,30 @@ Ping::WMI#ping(host, options={})
Ping::WMI#ping?(host, options={})
Returns whether or not the ping succeeded.

== Ping::LDAP
Ping::LDAP.new(uri=nil, timeout=5)
Performs a 'ping' to an LDAP server in the form of either an anonymous
or an authenticated LDAP bind.
Identical to Net::Ping.new except that, instead of a host, the first
argument is a URI.
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

Ping::LDAP#encryption
Set/get the encyption method. By default is nil, but may be set to :simple_tls

Ping::LDAP#username
Ping::LDAP#password
set/get the username and password for ping using and authenticated bind.

= Common Instance Methods
Ping#exception
Returns the error string that was set if a ping call failed. If an exception
Expand Down
38 changes: 30 additions & 8 deletions lib/net/ping/ldap.rb
Expand Up @@ -9,22 +9,43 @@ module Net
# The Ping::LDAP class encapsulates methods for LDAP pings.
class Ping::LDAP < Ping

# uri contains the URI object for the request
#
attr_accessor :uri

# username and password may be set for ping using
# an authenticated LDAP bind
#
attr_accessor :username
attr_accessor :password

# set/get the encryption method. By default nil,
# but may be set to :simple_tls
#
attr_accessor :encryption
def encryption=(value)
@encryption = (value.is_a? Symbol) ? value : value.to_sym
end

# Creates and returns a new Ping::LDAP object. The default port is the
# port associated with the URI. The default timeout is 5 seconds.
# Creates and returns a new Ping::LDAP object.
# The default +timeout+ is 5 seconds.
#
def initialize(host=nil, timeout=5)
host, port = decode_uri(host)
# +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
#
def initialize(uri=nil, timeout=5)
host, port = decode_uri(uri)
super(host, port, timeout)
end

# method used to decode uri string
#
def decode_uri(value)
@uri = URI.parse(value)
if uri.scheme =~ /ldap/
Expand All @@ -38,20 +59,21 @@ def decode_uri(value)
[h, p]
end

# constructs the LDAP configuration structure
#
def config
conf = {
{
:host => uri.host,
:port => uri.port,
:encryption => encryption
}
conf.merge!(
}.merge(
(username && password) ?
{ :auth => {:method => :simple, :username => username, :password => password} } :
{ :auth => {:method => :anonymous} }
)
conf
end

# perform ping, optionally providing the ping destination uri
#
def ping(host = nil)
decode_uri(host) if host
Expand Down
2 changes: 1 addition & 1 deletion test/test_net_ping_ldap.rb
Expand Up @@ -189,4 +189,4 @@ def teardown
assert_equal({:method => :anonymous}, @ldap.config[:auth] )
end

end
end

0 comments on commit 01f8ac7

Please sign in to comment.