Project

General

Profile

« Previous | Next » 

Revision 74f1db3a

Added by Marc Dequènes about 15 years ago

  • ID 74f1db3a130a3149a98d54f2eeb625276f47a4ad

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

View differences:

TODO
each type in a separate subdirectory (only global config on top)
* handle relations globally to allow sharing them among objects
* validate each file with a schema (using kwalify)
* create global config and support loading a selected Shadow (a default
Shadow can be given in the global config)
- select parent at creation with :parent ? this could be integrated in
common code to be able to relocate an item
- find a way to restrict parent locations for new objects (regex for
bin/shadowwalker
set_locale(locale)
config_str = IO.read(File.join(LdapShadows::Config::CFG_DIR, "shadow.conf"))
config = YAML.load(config_str)
config_str_prv_filelist = [
File.join(ENV['HOME'], ".shadowwalker"),
File.join(LdapShadows::Config::CFG_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!
$program_options = {}
......
cmdparser.add_command(CmdParse::VersionCommand.new)
def load_config_components(type)
c_config_dir = File.join(LdapShadows::Config::CFG_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
$ldapctl = Controller.new
$ldapctl.set_global_config(config[:presentation])
load_config_components("aspects") do |c_name, c_config|
$ldapctl.set_aspect(c_name, c_config)
end
begin
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
$ldapctl.load_shadow()
rescue ActiveLdap::Error => e
STDERR.puts _("LDAP connection error: %s") % e.to_s
exit 2
rescue
STDERR.puts _("Cannot load shadow configuration")
exit 2
end
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