Project

General

Profile

« Previous | Next » 

Revision 5174b503

Added by Marc Dequènes over 13 years ago

  • ID 5174b503ce8e352baae3100d518158bf23758b87

[evol] added support for multiple worlds (closes #144)

View differences:

lib/ldap_shadows/config.rb
def initialize
@global_config = nil
@world_config = nil
@schemas = {}
@default_configs = {}
@shadows = {}
end
def load_global_config(extra_private_config_list = [])
def load_global_config
g_default_config = load_default_config('global')
g_config_file = File.join(CFG_DIR, "global.conf")
......
end
g_def_partial = YAML.load_file(g_config_file) || {}
g_def = parse('config', 'global', YAML.dump(g_def_partial))
g_config = g_default_config.recursive_merge(g_def)
@global_config = g_config
end
def load_world_config(world_name = nil, extra_private_config_list = [])
world_name = self.global_config[:default_world] if world_name.nil?
w_default_config = load_default_config('world')
w_config_path = File.join(CFG_DIR, "worlds", world_name)
w_config_file = File.join(w_config_path, "world.conf")
unless File.exists? w_config_file
raise PreProcessingError, _("General configuration file for World '%s' is missing") % world_name
end
w_def_partial = YAML.load_file(w_config_file) || {}
extra_private_config_list += [
File.join(CFG_DIR, "global_private.conf")
File.join(w_config_path, "world_private.conf")
]
extra_private_config_list.each do |file|
if File.exists?(file)
g_def_partial.merge!(YAML.load_file(file) || {})
w_def_partial.merge!(YAML.load_file(file) || {})
break
end
end
g_def = parse('config', 'global', YAML.dump(g_def_partial))
g_config = g_default_config.recursive_merge(g_def)
w_def = parse('config', 'world', YAML.dump(w_def_partial))
w_config = w_default_config.recursive_merge(w_def)
ActiveLdap::Base.setup_connection(g_config[:ldap])
ActiveLdap::Base.setup_connection(w_config[:ldap])
@global_config = g_config
@world_config = w_config
@world_config_path = w_config_path
end
def global_config
......
@global_config
end
def world_config
load_world_config() if @world_config.nil?
@world_config
end
# needs 'ldap_shadows/shadow' for this feature to work
def load_shadow(shadow_name = nil)
shadow_name = self.global_config[:default_shadow] if shadow_name.nil?
shadow_name = self.world_config[:default_shadow] if shadow_name.nil?
if shadow_name.nil?
raise PreProcessingError, _("Could not determine which Shadow to travel through")
end
shadow_config_path = File.join(CFG_DIR, "shadows", shadow_name)
shadow_config_path = File.join(@world_config_path, "shadows", shadow_name)
unless File.exists? shadow_config_path
raise PreProcessingError, _("Configuration directory for Shadow '%s' is missing") % shadow_name
end
......
if validate
validator_klass = case type
when 'global'
GlobalValidator
when 'world'
WorldValidator
when 'object'
ObjectValidator
when 'aspect'
......
end
end
class GlobalValidator < LdapShadowsValidator
class WorldValidator < LdapShadowsValidator
def validate_hook_in(value, rule, path, msg_list)
case rule.name
when 'LdapMapping'

Also available in: Unified diff