Class: LdapQuery::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ldap_query/config.rb

Overview

Used to validate and filter credentials for establishing an LDAP connection

Constant Summary collapse

DEFAULT_CONFIG =

Usually 389 && 636

{ port: 389,       # Usually 389 && 636
encryption: nil,
base: nil,       # 'dc=company,dc=tld'
username: nil,
password: nil,
method: :simple }.freeze
ALLOWED_KEYS =
%i[base encryption host method port username password].freeze
REQUIRED_KEYS =

Required to be assigned and not have nil valuess

%i[base username password host port].freeze
VALS_REQUIRED_TO_BE_SYMBOLS =

Attributes whos values are required to by symbols for the LDAP gem

%i[encryption method].freeze

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Hash

Build and validate the configuration hash supplied for creating an LDAP connection

Parameters:

  • config (Hash) (defaults to: {})

Raises:

  • (ArgumentError)


27
28
29
30
31
# File 'lib/ldap_query/config.rb', line 27

def initialize(config = {})
  raise(ArgumentError, "the following attributes are required for an ldap connection #{REQUIRED_KEYS}") unless config.is_a?(Hash) && !config.blank?

  map_variables(validate_keys(cleanup_hash(defaults(config))))
end

Instance Method Details

#auth_hashHash

Build a hash of required config for authenticating a user against ldap

Returns:

  • (Hash)


43
44
45
# File 'lib/ldap_query/config.rb', line 43

def auth_hash
  @auth_hash ||= { host: @host, port: @port, encryption: @encryption }.freeze
end

#hashHash

Build a hash out of the provided config to establish an LDAP connection

Returns:

  • (Hash)


36
37
38
# File 'lib/ldap_query/config.rb', line 36

def hash
  @hash ||= { host: @host, port: @port, base: @base, encryption: @encryption }.merge(credentials_hash).freeze
end