Project

General

Profile

« Previous | Next » 

Revision f43a4cb1

Added by Marc Dequènes over 14 years ago

  • ID f43a4cb1f55d9e168f0e458c1af4229e96675767

[evol] recognize 'root' and understand it as value (but not yet as argument), clarify the full handle format, and recognize the MP root

View differences:

bin/shadowwalker
raise SyntaxError, _("no %s given") % name if args.empty?
full_handle = args.shift
raise SyntaxError, _("bad %s") % name unless full_handle =~ /^([a-zA-Z]+)\/(.+)$/
obj_hdl = $1.downcase
item_hdl = $2
m = LdapShadows::Elements::LdapObject.looks_like_full_handle?(full_handle)
raise SyntaxError, _("bad %s") % name unless m
obj_hdl = m[1].downcase
item_hdl = m[2]
split_args = [obj_hdl, item_hdl]
obj_klass = params_shift_object_handle(split_args)
......
unless result_is_binary or $program_options[:debug]
result = LdapShadows::Manipulation.interpret_field_value($shadow, attr_info.syntax.to_param, result)
if result.nil?
raise PreProcessingError, _("Field '%s' in object '%s' has a weird value") % [field_name, obj_klass.handle]
end
end
end
conf/ldap_shadows/shadows/MilkyPond/objects/top_entity.conf
---
mapping:
dn_attribute: dc
prefix: ''
classes: ['entity', 'dcObject']
sort_by: o
presentation:
name_attribute: o
lib/ldap_shadows/elements/object.rb
class LdapObject < ActiveLdap::Base
include LdapElement
FULL_HANDLE_PATTERN = /^([a-zA-Z_]+)\/(.+)$/
attr_reader :parent_changed
@relations_info = {}
......
"#{self.class.handle}/#{self.handle}"
end
def self.looks_like_full_handle?(full_handle)
full_handle =~ FULL_HANDLE_PATTERN
$~
end
def self.cast
super
......
raise PreProcessingError, _("The file for the binary field '%s' cannot be read: ") % [field, $!]
end
elsif attr_info.syntax.to_param == "1.3.6.1.4.1.1466.115.121.1.12"
if val =~ /([a-zA-Z]+)\/([a-zA-Z]+)/
if val =~ FULL_HANDLE_PATTERN
obj_hdl = $1.downcase
item_hdl = $2
......
end
def self.find_by_full_handle(full_handle)
raise PreProcessingError, _("Bad handle '%s'") % name unless full_handle =~ /^([a-zA-Z]+)\/(.+)$/
if full_handle == "root" and LdapShadows.const_defined?('Manipulation')
raw_item_dn = ActiveLdap::Base.base.to_s
raw_item = ActiveLdap::Base.find(:first, :base => raw_item_dn, :scope => :base)
info = LdapShadows::Manipulation.raw_item_info(self.shadow, raw_item, raw_item_dn)
if info.nil?
raise PreProcessingError, _("No such item 'root'")
elsif info[:object].nil?
raise PreProcessingError, _("Root item found, but no corresponding object defined")
else
full_handle = info[:full_handle]
end
end
raise SyntaxError, _("Bad handle '%s'") % full_handle unless full_handle =~ FULL_HANDLE_PATTERN
obj_hdl = $1.downcase.singularize
item_hdl = $2
lib/ldap_shadows/manipulation_helper.rb
shadow.objects.each do |obj_hdl|
obj_klass = shadow.get_object(obj_hdl)
ldap_classes = obj_klass.required_classes
return obj_hdl if (raw_item.classes & ldap_classes == ldap_classes) and (obj_klass.excluded_classes & raw_item.classes).empty?
ldap_classes = obj_klass.required_classes.sort
item_classes = (raw_item.classes - ['top']).sort
return obj_hdl if (item_classes & ldap_classes == ldap_classes) and (obj_klass.excluded_classes & item_classes).empty?
end
nil
end
def self.raw_item_info(shadow, raw_item, dn = nil)
is_root = false
if raw_item
is_root = true if raw_item.dn == ActiveLdap::Base.base
obj_hdl = self.find_raw_item_object(shadow, raw_item)
if obj_hdl
obj_klass = shadow.get_object(obj_hdl)
item = obj_klass.new(raw_item.dn)
return {:name => item.full_handle, :item => item, :object => obj_klass}
name = item.full_handle
name = "root|" + name if is_root
return {:full_handle => item.full_handle, :name => name, :item => item, :object => obj_klass, :is_root => is_root}
end
item_fake_hdl = raw_item.dn
......
item_fake_hdl = dn || "???"
end
{:name => "unknown/#{item_fake_hdl}"}
{:full_handle => nil, :name => "unknown/#{item_fake_hdl}", :is_root => is_root}
end
def self.interpret_field_value(shadow, syntax, val)
case syntax
when "1.3.6.1.4.1.1466.115.121.1.12"
raw_item = ActiveLdap::Base.find(:first, :base => val.to_s, :scope => :base)
LdapShadows::Manipulation.raw_item_info($shadow, raw_item, val.to_s)[:name]
LdapShadows::Manipulation.raw_item_info($shadow, raw_item, val.to_s)[:full_handle]
else
val
end

Also available in: Unified diff