Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update Ping::LDAP documentation

* removed Gemfile from the project
  • Loading branch information...
commit 01f8ac7fe688b0582676e4113d5fc1ff5453b70e 1 parent 84dee6b
@tardate tardate authored
View
9 Gemfile
@@ -1,9 +0,0 @@
-source 'http://rubygems.org'
-
-gem 'net-ldap', '~> 0.2.2'
-
-group :test do
- gem 'test-unit', '>= 2.1.2'
- gem 'fakeweb', '>= 1.3.0'
- gem 'fakeldap', '~> 0.0.1'
-end
View
16 Gemfile.lock
@@ -1,16 +0,0 @@
-GEM
- remote: http://rubygems.org/
- specs:
- fakeldap (0.0.1)
- fakeweb (1.3.0)
- net-ldap (0.2.2)
- test-unit (2.3.0)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- fakeldap (~> 0.0.1)
- fakeweb (>= 1.3.0)
- net-ldap (~> 0.2.2)
- test-unit (>= 2.1.2)
View
25 doc/ping.txt
@@ -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).
@@ -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
View
38 lib/net/ping/ldap.rb
@@ -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/
@@ -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
View
2  test/test_net_ping_ldap.rb
@@ -189,4 +189,4 @@ def teardown
assert_equal({:method => :anonymous}, @ldap.config[:auth] )
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.