class Rack::Auth::Config

class Config provide Yaml config mapping for Rack::Auth::Module the class map ldap configurations values @note this class is not provide to be used standalone

Public Class Methods

new(options = { :file => './ldap.yml'}) click to toggle source

initializer for Config class @param [Hash<Symbol>] options initialisation options @option options [Symbol] :file The YAML filename (default to ./ldap.yml, the config.ru path) @return [Config] object himself

# File lib/rack/auth/ldap.rb, line 27
def initialize(options = { :file => './ldap.yml'})
  @values = defaults
  options.merge!(:file => './ldap.yml') { |key,oldval,newval| oldval }
  target  = (ENV['RACK_ENV'])? ENV['RACK_ENV'] : 'test'
  config_values = load_yaml(::File.expand_path(options[:file], Dir.pwd))[target]
  debug = ::File.open("/tmp/test.txt",'a+')
  debug.puts ENV['RACK_ENV']
  debug.close
  config_values.keys.each do |key|
    config_values[key.to_sym] = config_values.delete(key)
  end
  @values.merge! config_values
  @values.keys.each do |meth|
    bloc = Proc.new  {@values[meth] }
      self.class.send :define_method, meth, &bloc
  end
end

Private Instance Methods

defaults() click to toggle source

private method with default configuration values for LDAP @return [Hash<Symbol>] the default values of LDAP configuration

# File lib/rack/auth/ldap.rb, line 61
def defaults
  return {
    :hostname => 'localhost',
    :basedn => 'dc=domain,dc=tld',
    :rootdn => '',
    :passdn => '',
    :auth => false,
    :port => 389,
    :scope => :subtree,
    :username_ldap_attribute => 'uid',
    :ldaps => false,
    :starttls => false,
    :tls_options => nil,
    :debug => false
  }
end
load_yaml(file) click to toggle source
# File lib/rack/auth/ldap.rb, line 47
def load_yaml(file)
  if ::File.exist?(file)
    ::YAML.load ::ERB.new(IO.read(file)).result
  else
    raise "Could not load ldap configuration. No such file - #{file}"
  end
rescue ::Psych::SyntaxError => e
  raise "YAML syntax error occurred while parsing #{file}. " \
        "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
        "Error: #{e.message}"
end