Class: ElDap::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/el_dap/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Base

Returns a new instance of Base.

Yields:

  • (_self)

Yield Parameters:

  • _self (ElDap::Base)

    the object that the method was called on



5
6
7
8
9
# File 'lib/el_dap/base.rb', line 5

def initialize
  @server_ips = []
  @timeout = 15
  yield(self) if block_given?
end

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



3
4
5
# File 'lib/el_dap/base.rb', line 3

def password
  @password
end

#server_ipsObject

Returns the value of attribute server_ips.



3
4
5
# File 'lib/el_dap/base.rb', line 3

def server_ips
  @server_ips
end

#timeoutObject

Returns the value of attribute timeout.



3
4
5
# File 'lib/el_dap/base.rb', line 3

def timeout
  @timeout
end

#treebaseObject

Returns the value of attribute treebase.



3
4
5
# File 'lib/el_dap/base.rb', line 3

def treebase
  @treebase
end

#usernameObject

Returns the value of attribute username.



3
4
5
# File 'lib/el_dap/base.rb', line 3

def username
  @username
end

Instance Method Details

#search(search_string) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/el_dap/base.rb', line 26

def search(search_string)
  return nil if Validator.blank?(search_string)

  @server_ips.each do |ip_address|
    begin
      TimeCop.timer.timeout(self.timeout) do
        worker = Worker.new(:username => self.username, :password => self.password, :ip_address => ip_address)
        raise(InvalidCredentialsError, 'The user credentials provided are invalid') unless worker.bind
        return worker.search_directory(search_string, self.treebase)
      end
    rescue Timeout::Error
      next
    end
  end
  
  false
end

#validate(username, password) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/el_dap/base.rb', line 11

def validate(username, password)
  return false if Validator.blank?(username, password)

  @server_ips.each do |ip_address|
    begin
      TimeCop.timer.timeout(self.timeout) do
        worker = Worker.new(:username => username, :password => password, :ip_address => ip_address)
        return worker.bind
      end
    rescue Timeout::Error
      next
    end
  end
end