Project

General

Profile

« Previous | Next » 

Revision c30d4613

Added by Marc Dequènes over 14 years ago

  • ID c30d46135dc6b02049f912f586cfd6b07701bb39

[evol] improved code for objects recognition, created display helper for raw items, and added family items display support

View differences:

TODO
common code to be able to relocate an item
- find a way to restrict parent locations for new objects (regex for <obj>/<item> string ? regex for DN ? OR/AND with both ? ???)
- handle fields containing a DN (allowing either giving a DN string or something like <object>:<item>)
- display familly information (preliminary work done for debug mode done, but object type should be recognized and displayed properly)
- handle subtypes
bin/shadowwalker
def execute (args)
raise SyntaxError, _("no search arguments") if args.empty?
res = LdapObject.items_search_from_strings(args)
res = LdapObject.items_find_from_strings(args)
unless res.empty?
display_lines = []
Hash[res].each_pair do |item_dn, item_data|
obj_hdl = LdapObject.find_raw_item_object(item_data)
if obj_hdl
obj_klass = $ldapctl.find_klass(obj_hdl)
item = obj_klass.new(item_dn)
display_lines << "#{obj_hdl}/#{item.name}"
else
display_lines << "unknown/#{item_dn}"
end
res.each do |raw_item|
display_lines << LdapObject.raw_item_info(raw_item)[:name]
end
puts display_lines.join("\n")
end
lib/ldap_shadows/display_utils.rb
puts "--- Detected Info ---"
puts "aspects: " + item.aspects.sort.join(", ")
puts "--- Family ---"
puts "parent: " + item.family_parent_dn.to_s
puts "siblings: " + item.family_siblings_dn.join(", ")
puts "children: " + item.family_children_dn.join(", ")
puts "--- Relations ---"
item.relations.each do |rel|
rel_data = item.send(rel)
......
end
puts "#{rel}: " + rel_value
end
puts "--- Family ---"
puts "parent: " + item.family_parent_dn.to_s
puts "siblings: " + item.family_siblings_dn.join(", ")
puts "children: " + item.family_children_dn.join(", ")
else
obj_info, obj_aspects = item.organized_data
......
puts "--- #{Translator.translate_aspect_name(aspect_name)} ---"
display_fields(aspect_data, options)
end
puts "--- Family ---"
puts "parent: " + LdapObject.raw_item_info(item.family_parent)[:name]
puts "siblings: " + item.family_siblings.collect{|raw_item| LdapObject.raw_item_info(raw_item)[:name] }.join(", ")
puts "children: " + item.family_children.collect{|raw_item| LdapObject.raw_item_info(raw_item)[:name] }.join(", ")
end
end
lib/ldap_shadows/object.rb
true
end
def self.items_search_from_strings(str_list)
def self.items_find_from_strings(str_list)
ldap_search_objects = "(objectClass=*)"
ldap_search_aspects = ""
ldap_search_fields = []
......
end
ldap_search_string = "(&" + ldap_search_objects + ldap_search_aspects + ldap_search_fields.join + ")"
search(:scope => :sub, :filter => ldap_search_string, :attributes => "objectClass")
LdapObject.find(:all, :scope => :sub, :filter => ldap_search_string, :attributes => ["objectClass"])
end
def self.ldap_search_string_field(field, op, val)
......
self.mapper.objects.each do |obj_hdl|
obj_klass = $ldapctl.find_klass(obj_hdl)
ldap_classes = obj_klass.required_classes
return obj_hdl if raw_item['objectClass'] & ldap_classes == ldap_classes
return obj_hdl if raw_item.classes & ldap_classes == ldap_classes
end
nil
end
def self.raw_item_info(raw_item)
obj_hdl = self.find_raw_item_object(raw_item)
if obj_hdl
obj_klass = $ldapctl.find_klass(obj_hdl)
item = obj_klass.new(raw_item.dn)
{:name => "#{obj_hdl}/#{item.name}", :item => item, :object => obj_klass}
else
{:name => "unknown/#{item_dn}"}
end
end
def family_parent_dn
pdn = self.dn_obj.dup
pdn.shift
pdn
end
def family_parent
# nothing found when using LdapObject, that's weird, so using ActiveLdap::Base
# until further investigation
#LdapObject.find(:first, :base => self.family_parent_dn.to_s, :scope => :base)
ActiveLdap::Base.find(:first, :base => self.family_parent_dn.to_s, :scope => :base)
end
def family_children
LdapObject.find(:all, :base => self.dn, :scope => :one)
end

Also available in: Unified diff