Project

General

Profile

« Previous | Next » 

Revision 9a7f1b63

Added by Marc Dequènes over 14 years ago

  • ID 9a7f1b6328d8f9529a200b342bac8d6296eb643e

[evol] added default config and simplified MilkyPond shadow config (and minor other changes)

View differences:

lib/ldap_shadows/config.rb
require 'singleton'
require 'yaml'
require 'kwalify'
require 'facets/hash/recursive_merge'
require 'ldap_shadows/shadow'
module LdapShadows
......
def initialize
@global_config = nil
@schemas = {}
@default_configs = {}
@shadows = {}
end
def load_global_config(extra_private_config_list = [])
g_default_config = load_default_config('global')
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_config_partial = YAML.load_file(g_config_file) || {}
g_def_partial = YAML.load_file(g_config_file) || {}
extra_private_config_list += [
File.join(CFG_DIR, "global_private.conf")
]
extra_private_config_list.each do |file|
if File.exists?(file)
g_config_partial.merge!(YAML.load_file(file) || {})
g_def_partial.merge!(YAML.load_file(file) || {})
break
end
end
g_config = parse_and_validate('config', 'global', YAML.dump(g_config_partial))
g_def = parse('config', 'global', YAML.dump(g_def_partial))
g_config = g_default_config.recursive_merge(g_def)
ActiveLdap::Base.setup_connection(g_config[:ldap])
......
}
shadow.set_config(config)
load_config_components(shadow_config_path, 'aspects') do |c_name, c_config|
load_element_config(shadow_config_path, 'aspects') do |c_name, c_config|
shadow.add_aspect(c_name, c_config)
end
load_config_components(shadow_config_path, 'objects') do |c_name, c_config|
load_element_config(shadow_config_path, 'objects') do |c_name, c_config|
shadow.add_object(c_name, c_config)
end
......
@shadows[shadow_name]
end
def parse_and_validate(def_name, type, def_data_raw)
def parse(def_name, type, def_data_raw, validate = true)
schema = load_schema(type)
validator_klass = case type
when 'global'
GlobalValidator
when 'object'
ObjectValidator
when 'aspect'
AspectValidator
if validate
validator_klass = case type
when 'global'
GlobalValidator
when 'object'
ObjectValidator
when 'aspect'
AspectValidator
else
Kwalify::Validator
end
validator = validator_klass.new(schema)
else
Kwalify::Validator
validator = nil
end
validator = validator_klass.new(schema)
# validate config with schema
parser = Kwalify::Yaml::Parser.new(validator)
......
def_data.recursive_symbolize_keys!
end
def load_default_config(type)
default_config = @default_configs[type]
if default_config.nil?
filename = File.join(DATA_DIR, "default_config", type + ".yaml")
default_config_raw = File.read(filename)
default_config = parse(':defaults:', type, default_config_raw, false)
@default_configs[type] = default_config
end
default_config
rescue
raise PreProcessingError, _("Could not load default config for '%s': %s") % [type, $!]
end
def load_hook_content(shadow_name, type, hook_name)
s_info = get_shadow_info(shadow_name)
return nil if s_info.nil?
......
File.read(filename)
end
protected
def load_config_components(shadow_config_path, type)
def load_element_config(shadow_config_path, type)
c_config_dir = File.join(shadow_config_path, type)
c_config_pattern = File.join(c_config_dir, "**", "*.conf")
......
end
schema
rescue
raise PreProcessingError, _("Could not load schema: %s") % $!
raise PreProcessingError, _("Could not load schema for '%s': %s") % [type, $!]
end
protected
def raise_if_validation_errors(name, errors)
if errors and not errors.empty?
err_msg = []

Also available in: Unified diff