class LdapFluff::Config
Constants
- ATTRIBUTES
- DEFAULT_CONFIG
Public Class Methods
new(config)
click to toggle source
# File lib/ldap_fluff/config.rb, line 19 def initialize(config) raise ArgumentError unless config.respond_to?(:to_hash) config = validate(convert(config)) ATTRIBUTES.each do |attr| instance_variable_set(:"@#{attr}", config[attr]) end end
Private Instance Methods
all_required_keys?(config)
click to toggle source
# File lib/ldap_fluff/config.rb, line 49 def all_required_keys?(config) %w[host port base_dn group_base server_type].all? do |key| raise ConfigError, "config key #{key} has to be set, it was nil" if config[key].nil? end %w[service_user service_pass].all? do |key| if !config['anon_queries'] && config[key].nil? raise ConfigError, "config key #{key} has to be set, it was nil" end end end
anon_queries_set?(config)
click to toggle source
# File lib/ldap_fluff/config.rb, line 61 def anon_queries_set?(config) unless [false, true].include?(config['anon_queries']) raise ConfigError, "config key anon_queries has to be true or false but was #{config['anon_queries']}" end end
convert(config)
click to toggle source
@param [#to_hash] config
# File lib/ldap_fluff/config.rb, line 31 def convert(config) config.to_hash.with_indifferent_access.tap do |conf| %w[encryption server_type method].each do |key| conf[key] = conf[key].is_a?(Hash) ? convert(conf[key]) : conf[key].to_sym if conf[key] end end end
correct_server_type?(config)
click to toggle source
# File lib/ldap_fluff/config.rb, line 67 def correct_server_type?(config) unless %i[posix active_directory free_ipa netiq].include?(config['server_type']) raise ConfigError, 'config key server_type has to be :active_directory, :posix, :free_ipa, :netiq ' + "but was #{config['server_type']}" end end
missing_keys?(config)
click to toggle source
# File lib/ldap_fluff/config.rb, line 39 def missing_keys?(config) missing_keys = ATTRIBUTES - config.keys raise ConfigError, "missing configuration for keys: #{missing_keys.join(',')}" unless missing_keys.empty? end
unknown_keys?(config)
click to toggle source
# File lib/ldap_fluff/config.rb, line 44 def unknown_keys?(config) unknown_keys = config.keys - ATTRIBUTES raise ConfigError, "unknown configuration keys: #{unknown_keys.join(',')}" unless unknown_keys.empty? end
validate(config)
click to toggle source
# File lib/ldap_fluff/config.rb, line 74 def validate(config) config = DEFAULT_CONFIG.merge(config) correct_server_type?(config) missing_keys?(config) unknown_keys?(config) all_required_keys?(config) anon_queries_set?(config) config end