Project

General

Profile

« Previous | Next » 

Revision 7f913647

Added by Marc Dequènes over 14 years ago

  • ID 7f913647af33494ef7a79a0cd1949daa103ab3a0

[evol] improve config #14 (validate global and shadow config, and removed shadowwalker's stuff from the general classes)

View differences:

lib/ldap_shadows/config.rb
require 'ldap_shadows/config_setup'
require 'singleton'
require 'yaml'
require 'kwalify'
require 'ldap_shadows/shadow'
......
@shadows = {}
end
def load_global_config
def load_global_config(extra_private_config_list = [])
g_config_file = File.join(CFG_DIR, "global.conf")
unless File.exists? g_config_file
raise PreProcessingError, _("Global LdapShadows config file is missing")
end
g_default_config = {}
g_config = g_default_config.merge(YAML.load_file(g_config_file) || {})
g_config_str_prv_filelist = [
File.join(ENV['HOME'], ".shadowwalker"),
g_config_partial = YAML.load_file(g_config_file) || {}
extra_private_config_list += [
File.join(CFG_DIR, "global_private.conf")
]
g_config_str_prv_filelist.each do |file|
extra_private_config_list.each do |file|
if File.exists?(file)
g_config.merge!(YAML.load_file(file))
g_config_partial.merge!(YAML.load_file(file) || {})
break
end
end
g_config.recursive_symbolize_keys!
g_config = parse_and_validate('config', 'global', YAML.dump(g_config_partial))
ActiveLdap::Base.setup_connection(g_config[:ldap])
......
unless File.exists? config_file
raise PreProcessingError, _("General configuration file for Shadow '%s' is missing") % shadow_name
end
config = YAML.load_file(config_file)
config.recursive_symbolize_keys!
config = File.read(config_file)
shadow = Shadow.new(shadow_name)
shadow.set_shadow_config(config[:presentation])
shadow.set_shadow_config(config)
load_config_components(shadow_config_path, 'aspects') do |c_name, c_config|
shadow.add_aspect(c_name, c_config)
......
schema = load_schema(type)
validator_klass = case type
when 'global'
GlobalValidator
when 'object'
ObjectValidator
when 'aspect'
......
extra_params = [:type, :object]
if value['type'] == 'belongs_to'
ne_params = value.keys.collect{|k| k.to_sym } - ActiveLdap::Associations::ClassMethods::VALID_BELONGS_TO_OPTIONS - extra_params
ne_params = value.keys.collect{|k| k.to_sym } -
ActiveLdap::Associations::ClassMethods::VALID_BELONGS_TO_OPTIONS - extra_params
unless ne_params.empty?
msg_list << _("nonexisting relation mapping parameters (%s)") % ne_params.join(", ")
end
else
ne_params = value.keys.collect{|k| k.to_sym } - ActiveLdap::Associations::ClassMethods::VALID_HAS_MANY_OPTIONS - extra_params
ne_params = value.keys.collect{|k| k.to_sym } -
ActiveLdap::Associations::ClassMethods::VALID_HAS_MANY_OPTIONS - extra_params
unless ne_params.empty?
msg_list << _("nonexisting relation mapping parameters (%s)") % ne_params.join(", ")
end
......
end
end
class AspectValidator < LdapShadowsValidator
class GlobalValidator < LdapShadowsValidator
def validate_hook_in(value, rule, path, msg_list)
case rule.name
when 'RelationMapping'
validate_hook_relation(value, rule, path, msg_list)
when 'LdapMapping'
ne_params = value.keys.collect{|k| k.to_sym } -
ActiveLdap::Configuration::ClassMethods::CONNECTION_CONFIGURATION_KEYS -
ActiveLdap::Adapter::Base::VALID_ADAPTER_CONFIGURATION_KEYS
unless ne_params.empty?
msg_list << _("nonexisting LDAP mapping parameters (%s)") % ne_params.join(", ")
end
end
end
end
......
class ObjectValidator < LdapShadowsValidator
def validate_hook_in(value, rule, path, msg_list)
case rule.name
when 'Mapping'
ne_params = value.keys.collect{|k| k.to_sym } - ActiveLdap::Base::VALID_LDAP_MAPPING_OPTIONS
when 'ObjectMapping'
ne_params = value.keys.collect{|k| k.to_sym } -
ActiveLdap::Base::VALID_LDAP_MAPPING_OPTIONS
unless ne_params.empty?
msg_list << _("nonexisting mapping parameters (%s)") % ne_params.join(", ")
msg_list << _("nonexisting object mapping parameters (%s)") % ne_params.join(", ")
end
when 'RelationMapping'
......
end
end
end
class AspectValidator < LdapShadowsValidator
def validate_hook_in(value, rule, path, msg_list)
case rule.name
when 'RelationMapping'
validate_hook_relation(value, rule, path, msg_list)
end
end
end
end
end

Also available in: Unified diff