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

auth() click to toggle source

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
base() click to toggle source

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
inspect() click to toggle source

@return [String]

# File lib/rom/ldap/directory/env.rb, line 83
def inspect
  "<#{self.class.name} #{connection} />"
end
ssl() click to toggle source

@return [Hash, NilClass]

# File lib/rom/ldap/directory/env.rb, line 71
def ssl
  config[:ssl] if uri.scheme.eql?('ldaps')
end
to_h() click to toggle source

@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
uri() click to toggle source

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

bind_dn() click to toggle source

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
bind_pw() click to toggle source

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
default_connection() click to toggle source

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
default_host() click to toggle source

LDAPHOST or localhost

@return [String]

# File lib/rom/ldap/directory/env.rb, line 129
def default_host
  ::ENV.fetch('LDAPHOST', 'localhost')
end
default_port() click to toggle source

LDAPPORT or 389

@return [Integer]

# File lib/rom/ldap/directory/env.rb, line 137
def default_port
  ::ENV.fetch('LDAPPORT', 389)
end
host() click to toggle source

@return [String, NilClass]

# File lib/rom/ldap/directory/env.rb, line 97
def host
  uri.host unless path
end
path() click to toggle source

@return [String, NilClass]

# File lib/rom/ldap/directory/env.rb, line 91
def path
  uri.path unless uri.host
end
port() click to toggle source

@return [Integer, NilClass]

# File lib/rom/ldap/directory/env.rb, line 103
def port
  uri.port unless path
end