Revision 23fe62d2
Added by Marc Dequènes over 15 years ago
- ID 23fe62d2faed62289ab6e449f4181cd37283d462
TODO | ||
---|---|---|
- display sort order
|
||
- aspects additional relations
|
||
- binary fields: display presence and (later) allow download/upload to/from file
|
config/test.conf | ||
---|---|---|
classes: ['bot']
|
||
sort_by: uid
|
||
presentation:
|
||
desc_attribute: cn
|
||
optional_classes: []
|
||
allowed_aspects: ['primary', 'mail', 'fs', 'shell', 'ftp', 'web', 'jabber']
|
||
hidden_attributes: ['objectClass', 'uid']
|
||
... | ... | |
classes: ['individual']
|
||
sort_by: uid
|
||
presentation:
|
||
desc_attribute: cn
|
||
optional_classes: []
|
||
allowed_aspects: ['primary', 'mail', 'fs', 'shell', 'ftp', 'web', 'jabber']
|
||
hidden_attributes: ['objectClass', 'uid']
|
||
... | ... | |
classes: ['posixGroup', 'groupOfMembers']
|
||
sort_by: cn
|
||
presentation:
|
||
desc_attribute: description
|
||
optional_classes: []
|
||
allowed_aspects: []
|
||
hidden_attributes: ['objectClass', 'uniqueMember']
|
||
... | ... | |
excluded_classes: ['dcObject']
|
||
sort_by: o
|
||
presentation:
|
||
desc_attribute: o
|
||
name_attribute: o
|
||
hidden_attributes: ['objectClass', 'founder']
|
||
associated_relations: ['foundersIndividuals', 'foundersEntities']
|
||
relations:
|
test.rb | ||
---|---|---|
opt.separator "Global options:"
|
||
opt.on("--debug", "Output debug info without being formated") {|t| $debug_opt = true }
|
||
opt.on("--expert", "Output extra info for expert users") {|t| $expert_opt = true }
|
||
opt.on("--handles", "Output with handles (objects/field/... keys used for manipulations)") {|t| $handles_opt = true }
|
||
end
|
||
|
||
cmdparser.add_command(CmdParse::HelpCommand.new)
|
||
... | ... | |
class_inheritable_accessor :presentation, :mapper
|
||
|
||
def name
|
||
self[dn_attribute].is_a?(Array) ? self[dn_attribute][0] : self[dn_attribute]
|
||
name = self[dn_attribute].is_a?(Array) ? self[dn_attribute][0] : self[dn_attribute]
|
||
name.strip
|
||
end
|
||
|
||
def human_name
|
||
[self.class.presentation[:name_attribute], 'displayName', 'cn'].each do |attr|
|
||
if self.has_attribute?(attr) and self.attribute_present?(attr)
|
||
name = self[attr].is_a?(Array) ? self[attr][0] : self[attr]
|
||
return name.strip
|
||
end
|
||
end
|
||
return ""
|
||
end
|
||
|
||
def description
|
||
[self.class.presentation[:desc_attribute], 'displayName', 'cn', 'description'].each do |attr|
|
||
[self.class.presentation[:desc_attribute], 'description'].each do |attr|
|
||
if self.has_attribute?(attr) and self.attribute_present?(attr)
|
||
return self[attr].is_a?(Array) ? self[attr][0] : self[attr]
|
||
end
|
||
... | ... | |
exit 1
|
||
end
|
||
|
||
obj_name = args[0]
|
||
obj_klass = ldapctl.find_klass(obj_name)
|
||
obj_hdl = args[0]
|
||
obj_klass = ldapctl.find_klass(obj_hdl)
|
||
if obj_klass.nil?
|
||
STDERR.puts "No such object '#{obj_name}'."
|
||
STDERR.puts "No such object '#{obj_hdl}'."
|
||
exit 2
|
||
end
|
||
|
||
obj_human_name = I18n.t(obj_hdl, :scope => 'objects', :default => "Object '#{obj_hdl}'")
|
||
puts "=== List of #{obj_human_name.pluralize} ==="
|
||
obj_klass.find(:all).each do |obj|
|
||
puts "#{obj.name}: #{obj.description}"
|
||
str = obj.human_name
|
||
str += " [#{obj.name}]" if $handles_opt
|
||
str += ": #{obj.description}" unless obj.description.empty?
|
||
puts str
|
||
end
|
||
end
|
||
cmdparser.add_command(cmd)
|
||
|
||
def objectclasses_attr_list(objectclass_list)
|
||
objectclass_list = [objectclass_list] unless objectclass_list.is_a? Array
|
||
list = []
|
||
objectclass_list.each do |objectclass|
|
||
objectclass_obj = ActiveLdap::Base.schema.object_class(objectclass)
|
||
attr_list = objectclass_obj.must + objectclass_obj.may
|
||
list += attr_list.collect{|attr| attr.human_attribute_name }
|
||
end
|
||
list
|
||
end
|
||
|
||
def self.translate_data_key(name)
|
||
def translate_data_key(name)
|
||
if name.index(":")
|
||
type, key = name.split(":")
|
||
case type
|
||
... | ... | |
def display_data(attr_data)
|
||
attr_data.each_pair do |key, val|
|
||
field_name = translate_data_key(key)
|
||
field_name += " [#{key}]" if $handles_opt
|
||
puts field_name + ": " + (val.is_a?(Array) ? val.sort.collect{|v| v.to_s }.join(", ") : val.to_s)
|
||
end
|
||
end
|
||
... | ... | |
exit 1
|
||
end
|
||
|
||
obj_name = args[0]
|
||
obj_klass = ldapctl.find_klass(obj_name)
|
||
obj_hdl = args[0]
|
||
obj_klass = ldapctl.find_klass(obj_hdl)
|
||
if obj_klass.nil?
|
||
STDERR.puts "No such object '#{obj_name}'."
|
||
STDERR.puts "No such object '#{obj_hdl}'."
|
||
exit 2
|
||
end
|
||
|
||
item_identifier = args[1]
|
||
item_hdl = args[1]
|
||
begin
|
||
item = obj_klass.find(item_identifier)
|
||
item = obj_klass.find(item_hdl)
|
||
rescue ActiveLdap::EntryNotFound
|
||
STDERR.puts "No such item '#{obj_name}/#{item_identifier}'"
|
||
STDERR.puts "No such item '#{obj_hdl}/#{item_hdl}'"
|
||
exit 2
|
||
end
|
||
|
||
obj_human_name = I18n.t(obj_name, :scope => 'objects', :default => "Object '#{obj_name}'")
|
||
puts "=== #{obj_human_name}: #{item.name} ==="
|
||
obj_human_name = I18n.t(obj_hdl, :scope => 'objects', :default => "Object '#{obj_hdl}'")
|
||
name = item.human_name
|
||
name += " [#{item.name}]" if $handles_opt
|
||
puts "=== #{obj_human_name}: #{name} ==="
|
||
|
||
if $debug_opt
|
||
puts item.to_s
|
Also available in: Unified diff
[evol] properly display names and handles