Revision 0df6346a
Added by Marc Dequènes over 15 years ago
- ID 0df6346aea93b5cf58ff4bc82053d57e6cafc608
lib/ldap_shadows/controller.rb | ||
---|---|---|
|
||
module LdapShadows
|
||
class Controller
|
||
attr_reader :shadow_name, :shadow_config_path
|
||
|
||
def initialize(mod_container = LdapShadows::Objects)
|
||
@mod_container = mod_container
|
||
|
||
... | ... | |
end
|
||
|
||
def clear_shadow
|
||
@shadow_name = nil
|
||
@shadow_config_path = nil
|
||
@global_config = nil
|
||
@shadow_config = nil
|
||
@object_definitions = {}
|
||
@aspects = {}
|
||
# TODO: should replace @aspects properly one day
|
||
@aspects2 = {}
|
||
@shadow_dir = nil
|
||
end
|
||
|
||
def set_global_config(global_config)
|
||
@global_config = global_config
|
||
def set_shadow_config(shadow_config)
|
||
@shadow_config = shadow_config
|
||
end
|
||
|
||
def get_global_config
|
||
@global_config
|
||
def get_shadow_config
|
||
@shadow_config
|
||
end
|
||
|
||
def set_aspect(aspect_name, aspect_def)
|
||
... | ... | |
end
|
||
EOS
|
||
rescue
|
||
STDERR.puts "Could not load Aspect plugin '#{aspect_name}'"
|
||
exit 1
|
||
raise PreProcessingError, _("Could not load Aspect plugin '%s'") % aspect_name
|
||
end
|
||
|
||
@aspects2[aspect_name] = Aspects.const_get(klass_name)
|
||
... | ... | |
obj_def[:presentation][:allowed_aspects].each do |aspect|
|
||
aspect_data = get_aspect(aspect)
|
||
if aspect_data.nil?
|
||
STDERR.puts "Aspect '%s' is missing" % aspect
|
||
exit 1
|
||
raise PreProcessingError, _("Aspect '%s' is missing") % aspect
|
||
end
|
||
obj_rel.merge!(aspect_data[:relations]) if aspect_data.has_key?(:relations) and aspect_data[:relations]
|
||
end
|
||
... | ... | |
obj_rel.each_pair do |field_name, rel|
|
||
foreign_klass = find_klass(rel[:object])
|
||
if foreign_klass.nil?
|
||
STDERR.puts "Relation '%s' for object '%s' is impossible: foreign object '%s' is missing" % [field_name, obj_name, rel[:object]]
|
||
exit 1
|
||
raise PreProcessingError, _("Relation '%s' for object '%s' is impossible: foreign object '%s' is missing") % [field_name, obj_name, rel[:object]]
|
||
end
|
||
rel[:class_name] = foreign_klass.to_s
|
||
|
||
... | ... | |
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
|
||
g_config_file = File.join(LdapShadows::Config::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(IO.read(g_config_file)) || {})
|
||
g_config.recursive_symbolize_keys!
|
||
@global_config = g_config
|
||
|
||
@shadow_name = shadow_name || @global_config[:default_shadow]
|
||
if @shadow_name.nil?
|
||
raise PreProcessingError, _("Could not determine which Shadow to travel through")
|
||
end
|
||
|
||
@shadow_config_path = File.join(LdapShadows::Config::CFG_DIR, "shadows", @shadow_name)
|
||
unless File.exists? @shadow_config_path
|
||
raise PreProcessingError, _("Configuration directory for Shadow '%s' is missing") % @shadow_name
|
||
end
|
||
|
||
config_str = IO.read(File.join(@shadow_dir, "shadow.conf"))
|
||
config = YAML.load(config_str)
|
||
config_file = File.join(@shadow_config_path, "shadow.conf")
|
||
unless File.exists? config_file
|
||
raise PreProcessingError, _("General configuration file for Shadow '%s' is missing") % @shadow_name
|
||
end
|
||
config = YAML.load(IO.read(config_file))
|
||
config_str_prv_filelist = [
|
||
File.join(ENV['HOME'], ".shadowwalker"),
|
||
File.join(@shadow_dir, "shadow_private.conf")
|
||
File.join(@shadow_config_path, "shadow_private.conf")
|
||
]
|
||
config_str_prv_filelist.each do |file|
|
||
if File.exists?(file)
|
||
... | ... | |
end
|
||
config.recursive_symbolize_keys!
|
||
|
||
$ldapctl.set_global_config(config[:presentation])
|
||
$ldapctl.set_shadow_config(config[:presentation])
|
||
|
||
load_config_components("aspects") do |c_name, c_config|
|
||
$ldapctl.set_aspect(c_name, c_config)
|
||
... | ... | |
end
|
||
|
||
$ldapctl.load_relations
|
||
|
||
translation_path = File.join($ldapctl.shadow_config_path, "translations")
|
||
if File.exists? translation_path
|
||
# load interface translation
|
||
I18n.load_path += Dir[File.join(translation_path, "**", "*.yml")]
|
||
end
|
||
rescue
|
||
raise PreProcessingError, _("Could not load shadow configiguration: %s") % $!
|
||
end
|
||
|
||
protected
|
||
|
||
def load_config_components(type)
|
||
c_config_dir = File.join(@shadow_dir, type)
|
||
c_config_dir = File.join(@shadow_config_path, type)
|
||
c_config_pattern = File.join(c_config_dir, "**", "*.conf")
|
||
|
||
Dir.glob(c_config_pattern).each do |f|
|
Also available in: Unified diff
[evol] improve config #8 (shadow selection support)