Class: PsuDir::Ldap

Inherits:
Object
  • Object
show all
Defined in:
lib/psu_dir/ldap.rb

Direct Known Subclasses

Disambiguate::User, LdapUser

Class Method Summary collapse

Class Method Details

.get_users(filter, fields = []) ⇒ Object



6
7
8
# File 'lib/psu_dir/ldap.rb', line 6

def get_users(filter, fields = [])
  retry_if { Hydra::LDAP.get_user(filter, fields) } || []
end

.ldap_error_message(e) ⇒ Object



34
35
36
# File 'lib/psu_dir/ldap.rb', line 34

def ldap_error_message(e)
  "#{Hydra::LDAP.connection.get_operation_result.message}\nException: #{e.exception}\n#{e.backtrace.join("\n")}"
end

.retry_ifObject

Retries the LDAP command up to .tries times, or catches any other kind of LDAP error without retrying. return [block or nil]



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/psu_dir/ldap.rb', line 12

def retry_if
  tries.times.each do
    result = yield
    return result unless unwilling?
    sleep(PsuDir.ldap_unwilling_sleep)
  end
  PsuDir.logger.warn 'LDAP is unwilling to perform this operation, try upping the number of tries'
  nil
rescue Net::LDAP::Error => e
  PsuDir.logger.warn "Error getting LDAP response: #{ldap_error_message(e)}"
  nil
end

.triesObject



25
26
27
# File 'lib/psu_dir/ldap.rb', line 25

def tries
  7
end

.unwilling?Boolean

Numeric code returned by LDAP if it is feeling “unwilling”

Returns:

  • (Boolean)


30
31
32
# File 'lib/psu_dir/ldap.rb', line 30

def unwilling?
  Hydra::LDAP.connection.get_operation_result.code == 53
end