Class: LeveretAuth::Ldap::Configuration

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

Defined Under Namespace

Classes: ConfigurationError

Constant Summary collapse

REQUIRED_CONNECTION_CONFIG_KEYS =

For build Net::LDAP::Connection

%i[host port base].freeze
OPTIONAL_CONNECTION_CONFIG_KEYS =
encryption: %i[method tls_opitons],
  auth: %i[method username password]
].freeze
REQUIRED_SEARCH_CONFIG_KEYS =

For custom search condition

[%i[uid filter]].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration = {}) ⇒ Configuration

Returns a new instance of Configuration.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/leveret_auth/ldap/configuration.rb', line 20

def initialize(configuration = {})
  validate_required_keys(configuration)

  permitted_keys = [permitted_connection_keys + permitted_search_keys].flatten
  Utils.deep_slice(configuration, permitted_keys).each do |k, v|
    instance_variable_set("@#{k}", v)
  end

  validate_encryption
  validate_auth
end

Instance Attribute Details

#filterObject (readonly)

Returns the value of attribute filter.



18
19
20
# File 'lib/leveret_auth/ldap/configuration.rb', line 18

def filter
  @filter
end

#uidObject (readonly)

Returns the value of attribute uid.



18
19
20
# File 'lib/leveret_auth/ldap/configuration.rb', line 18

def uid
  @uid
end

Instance Method Details

#connection_configObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/leveret_auth/ldap/configuration.rb', line 32

def connection_config
  permitted_connection_keys.each_with_object({}) do |key, hash|
    if key.is_a?(Hash)
      key.each_key { |sub_key| hash[sub_key] = instance_variable_get("@#{sub_key}") }
    else
      hash[key] = instance_variable_get("@#{key}")
    end
    hash
  end.compact
end