Project

General

Profile

« Previous | Next » 

Revision 9a7f1b63

Added by Marc Dequènes about 15 years ago

  • ID 9a7f1b6328d8f9529a200b342bac8d6296eb643e

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

View differences:

conf/ldap_shadows/shadows/MilkyPond/aspects/ftp.conf
mapping:
classes: ['ftpUser']
depend_aspects: ['primary', 'fs']
presentation:
relations:
conf/ldap_shadows/shadows/MilkyPond/aspects/jabber.conf
mapping:
classes: ['jabberUser']
presentation:
relations:
conf/ldap_shadows/shadows/MilkyPond/aspects/mail.conf
mapping:
classes: ['emailUser']
presentation:
relations:
conf/ldap_shadows/shadows/MilkyPond/aspects/primary.conf
classes: ['primaryAccount']
presentation:
associated_attributes: ['uid']
relations:
conf/ldap_shadows/shadows/MilkyPond/aspects/shell.conf
depend_aspects: ['primary', 'fs']
presentation:
associated_attributes: ['loginShell']
relations:
conf/ldap_shadows/shadows/MilkyPond/aspects/web.conf
mapping:
classes: ['webUser']
depend_aspects: ['primary']
presentation:
relations:
conf/ldap_shadows/shadows/MilkyPond/objects/domain.conf
prefix: ''
classes: ['genericDomain']
sort_by: cn
presentation:
allowed_aspects: []
conf/ldap_shadows/shadows/MilkyPond/objects/group.conf
classes: ['posixGroup', 'groupOfMembers']
sort_by: cn
presentation:
allowed_aspects: []
hidden_attributes: ['uniqueMember']
expert_attributes: ['gidNumber']
associated_relations: ['individualsPrimaryMembers', 'botsPrimaryMembers', 'individualsSecondaryMembers', 'botsSecondaryMembers']
data/ldap_shadows/default_config/aspect.yaml
---
mapping:
classes: []
depend_aspects: []
presentation:
associated_attributes: []
associate_unclaimed_attributes: false
associated_relations: []
relations: {}
plugin: {}
data/ldap_shadows/default_config/global.yaml
---
default_shadow:
password_hash:
ldap: {}
data/ldap_shadows/default_config/object.yaml
---
mapping: {}
presentation:
name_attribute:
allowed_aspects: []
hidden_attributes: []
expert_attributes: []
associated_relations: []
relations: {}
plugin: {}
data/ldap_shadows/default_config/shadow.yaml
---
presentation:
hidden_attributes: []
tree_objects: []
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 = []
lib/ldap_shadows/shadow.rb
end
def set_config(shadow_def_raw)
@shadow_config = @config.parse_and_validate(@name, 'shadow', shadow_def_raw)
shadow_default_config = @config.load_default_config('shadow')
shadow_def = @config.parse(@name, 'shadow', shadow_def_raw)
@shadow_config = shadow_default_config.recursive_merge(shadow_def)
end
def get_config
......
raise PreProcessingError, _("Element '%s' for model '%s' as already been defined") % [e_name, e_type]
end
e_def = @config.parse_and_validate(e_name, e_type, e_def_raw)
e_def = @config.parse(e_name, e_type, e_def_raw)
e_default_parameters = @config.load_default_config(e_type)
e_config = e_default_parameters.recursive_merge(e_def)
klass = @container.module_eval(<<-EOS)
class #{klass_name} < #{superklass_location}::#{superklass_name}; self; end
......
klass.instance_variable_set(:@handle, e_name)
klass.instance_variable_set(:@shadow, self)
klass.instance_variable_set(:@config, @config)
klass.instance_variable_set(:@parameters, e_def)
klass.instance_variable_set(:@parameters, e_config)
klass.meta_eval do
attr_reader :handle, :shadow, :config, :parameters
end

Also available in: Unified diff