Project

General

Profile

« Previous | Next » 

Revision c5ae937c

Added by Marc Dequènes almost 15 years ago

  • ID c5ae937cec7230cec232bb772e3347f7e6ee333b

[evol] improve config #9 (preliminary work to check object definition against schema)

View differences:

data/ldap_shadows/schema/object.yaml
---
type: map
mapping:
"mapping":
type: map
required: yes
mapping:
=:
type: str
"presentation":
type: map
mapping:
"allowed_aspects":
type: seq
sequence:
- type: str
"hidden_attributes":
type: seq
sequence:
- type: str
"expert_attributes":
type: seq
sequence:
- type: str
lib/ldap_shadows/controller.rb
$KCODE = 'UTF8'
require 'jcode'
require 'active_ldap'
require 'kwalify'
require 'ldap_shadows/activeldap_fixes'
require 'ldap_shadows/object'
......
def initialize(mod_container = LdapShadows::Objects)
@mod_container = mod_container
@schema = {}
clear_shadow
LdapShadows::LdapObject.mapper = self
end
......
end
def load_object(obj_name, obj_def)
schema = load_schema("object")
validator = Kwalify::Validator.new(schema)
errors = validator.validate(obj_def)
obj_mapping = obj_def[:mapping]
klass_name = self.class.object_name_to_klass_name(obj_name)
......
I18n.load_path += Dir[File.join(translation_path, "**", "*.yml")]
end
rescue
raise PreProcessingError, _("Could not load shadow configiguration: %s") % $!
raise PreProcessingError, _("Could not load shadow configuration: %s") % $!
end
protected
......
yield(c_name, c_config)
end
end
def load_schema(type)
schema = @schema[type]
if schema.nil?
schema_file = File.join(Config::DATA_DIR, "schema", type + ".yaml")
schema = YAML.load(IO.read(schema_file))
@schema[type] = schema
end
schema
rescue
raise PreProcessingError, _("Could not load schema: %s") % $!
end
end
# default location for mapped objects

Also available in: Unified diff