Project

General

Profile

« Previous | Next » 

Revision 74f1db3a

Added by Marc Dequènes over 14 years ago

  • ID 74f1db3a130a3149a98d54f2eeb625276f47a4ad

[evol] improve config #7 (move shadow loading in the Controller)

View differences:

lib/ldap_shadows/controller.rb
class Controller
def initialize(mod_container = LdapShadows::Objects)
@mod_container = mod_container
clear_shadow
LdapShadows::LdapObject.mapper = self
end
def clear_shadow
@object_definitions = {}
@aspects = {}
# should replace @aspects properly one day
# TODO: should replace @aspects properly one day
@aspects2 = {}
LdapShadows::LdapObject.mapper = self
@shadow_dir = nil
end
def set_global_config(global_config)
......
def objects
@object_definitions.keys.collect{|key| key.to_s }.sort
end
def load_shadow(shadow_name = nil)
clear_shadow
# TODO: local global config and use shadow name to load corresponding Shadow (or defautl Shadow if nil)
@shadow_dir = LdapShadows::Config::CFG_DIR
config_str = IO.read(File.join(@shadow_dir, "shadow.conf"))
config = YAML.load(config_str)
config_str_prv_filelist = [
File.join(ENV['HOME'], ".shadowwalker"),
File.join(@shadow_dir, "shadow_private.conf")
]
config_str_prv_filelist.each do |file|
if File.exists?(file)
config_str_prv = IO.read(file)
config.merge!(YAML.load(config_str_prv))
break
end
end
config.recursive_symbolize_keys!
$ldapctl.set_global_config(config[:presentation])
load_config_components("aspects") do |c_name, c_config|
$ldapctl.set_aspect(c_name, c_config)
end
ActiveLdap::Base.setup_connection(config[:ldap])
load_config_components("objects") do |c_name, c_config|
$ldapctl.load_object(c_name, c_config)
end
$ldapctl.load_relations
end
protected
def load_config_components(type)
c_config_dir = File.join(@shadow_dir, type)
c_config_pattern = File.join(c_config_dir, "**", "*.conf")
Dir.glob(c_config_pattern).each do |f|
next if f[0..0] == "."
c_name = File.basename(f).sub(".conf", "").to_sym
c_config = YAML.load(IO.read(f))
c_config.recursive_symbolize_keys!
yield(c_name, c_config)
end
end
end
# default location for mapped objects

Also available in: Unified diff