Project

General

Profile

« Previous | Next » 

Revision 3cdff641

Added by Marc Dequènes over 13 years ago

  • ID 3cdff641250aa4c4ed92bcc471b80acf0f692ac2

[evol] Librarian API work §2

View differences:

bin/test_client
ask "Librarian", :library, "/Records"
ask "Librarian", :persons, "/Records/persons"
ask "Librarian", :dns_domains, "/Records/dns_domains"
ask "Librarian", :gorou, "/Records/Persons/gorou"
ask "Librarian", :guihome_net, "/Records/DnsDomains/guihome.net"
#ask "MapMaker", :zones, "/Zones"
#ask "MapMaker", :wanted_failure, "/prout"
#ask "MapMaker", :dns, "/Services/DNS"
lib/cyborghood-librarian/interface/0_base.rb
node 'Records' do
node ['persons', 'dns_domains'] do
node ['Persons', 'DnsDomains'] do
object_list = Proc.new{|obj_name| bot.services.records.send(node_name.underscore, obj_name) }
on_request do |request|
request.reply.results = bot.services.records.send(node_name)
request.reply.results = object_list.call
end
node object_list do
on_request do |request|
prepare_value = Proc.new do |v|
if v.is_a? Array
v.collect!{|v2| prepare_value.call(v2) }
elsif v.is_a? ActiveLdap::DistinguishedName
v.to_s
else
v
end
end
obj_attrs = object_list.call(node_name).attributes
obj_attrs.delete('objectClass')
obj_attrs.each do |k, v|
obj_attrs[k] = prepare_value.call(v)
end
request.reply.results = obj_attrs
end
end
end
end
lib/cyborghood-librarian/records.rb
module CyborgHood
module LibrarianLand
class Records
def persons
LdapPerson.find(:all, :attributes => ['uid']).collect{|i| i.uid }
def persons(obj_name = nil)
if obj_name.nil?
LdapPerson.find(:all, :attributes => ['uid']).collect{|i| i.uid }
else
list = LdapPerson.find(:all, :attribute => 'uid', :value => obj_name)
return if list.nil? or list.empty?
return list.first if list.size == 1
raise CyberError.new(:unrecoverable, "db/ldap", "broken DB: multiple Person with the same uid")
end
end
def dns_domains
LdapDnsDomain.find(:all, :attributes => ['cn']).collect{|i| i.cn }
def dns_domains(obj_name = nil)
if obj_name.nil?
LdapDnsDomain.find(:all, :attributes => ['cn']).collect{|i| i.cn }
else
list = LdapDnsDomain.find(:all, :attribute => 'cn', :value => obj_name)
return if list.nil? or list.empty?
return list.first if list.size == 1
raise CyberError.new(:unrecoverable, "db/ldap", "broken DB: multiple DnsDomain with the same cn")
end
end
end
end # LibrarianLand

Also available in: Unified diff