class ROM::LDAP::Directory::ENV
Parse uri and options received by the gateway configuration.
@example
scheme:// binddn : passwd @ host : port / base ldap://uid=admin,ou=system:secret@localhost:1389/ou=users,dc=rom,dc=ldap
@see ldapwiki.com/wiki/LDAP%20URL @see docs.oracle.com/cd/E19957-01/816-6402-10/url.htm
@api private
Public Instance Methods
Username and password.
@return [Hash, NilClass]
# File lib/rom/ldap/directory/env.rb, line 65 def auth { username: bind_dn, password: bind_pw } if bind_dn end
Global search base. The value is derived in this order:
1. Gateway Options 2. ENVs 3. URI (unless this is a socket) defaults "" 4. an empty string
@example
'ldap://localhost/ou=users,dc=rom,dc=ldap' => ou=users,dc=rom,dc=ldap
@return [String]
# File lib/rom/ldap/directory/env.rb, line 55 def base config.fetch(:base) do ::ENV['LDAPBASE'] || (path ? EMPTY_STRING : uri.dn.to_s) end end
@return [String]
# File lib/rom/ldap/directory/env.rb, line 83 def inspect "<#{self.class.name} #{connection} />" end
@return [Hash, NilClass]
# File lib/rom/ldap/directory/env.rb, line 71 def ssl config[:ssl] if uri.scheme.eql?('ldaps') end
@return [Hash]
# File lib/rom/ldap/directory/env.rb, line 77 def to_h { host: host, port: port, path: path, ssl: ssl, auth: auth } end
Build LDAP
URL with encoded spaces.
@return [URI::LDAP, URI::LDAPS]
@raise URI::InvalidURIError
# File lib/rom/ldap/directory/env.rb, line 40 def uri URI(connection.gsub(SPACE, PERCENT_SPACE)) end
Private Instance Methods
Override LDAPURI user with options or LDAPBINDDN. Percent decode the URI's user value.
@return [String, NilClass]
# File lib/rom/ldap/directory/env.rb, line 112 def bind_dn dn = config.fetch(:username, ::ENV['LDAPBINDDN']) || uri.user dn.gsub(PERCENT_SPACE, SPACE) if dn end
Override LDAPURI password with options or LDAPBINDPW
@return [String, NilClass]
# File lib/rom/ldap/directory/env.rb, line 121 def bind_pw config.fetch(:password, ::ENV['LDAPBINDPW']) || uri.password end
Fallback connection scheme is “ldap://”
@return [String]
# File lib/rom/ldap/directory/env.rb, line 145 def default_connection "ldap://#{default_host}:#{default_port}" end
LDAPHOST or localhost
@return [String]
# File lib/rom/ldap/directory/env.rb, line 129 def default_host ::ENV.fetch('LDAPHOST', 'localhost') end
LDAPPORT or 389
@return [Integer]
# File lib/rom/ldap/directory/env.rb, line 137 def default_port ::ENV.fetch('LDAPPORT', 389) end
@return [String, NilClass]
# File lib/rom/ldap/directory/env.rb, line 97 def host uri.host unless path end
@return [String, NilClass]
# File lib/rom/ldap/directory/env.rb, line 91 def path uri.path unless uri.host end
@return [Integer, NilClass]
# File lib/rom/ldap/directory/env.rb, line 103 def port uri.port unless path end