ldap.rb
977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class SdAdmin::Database::Ldap
attr_writer :base_dn, :mapper
def initialize(args = {})
@con = {:host => 'host.one.virtual', :port => 389}
@con[:host] = args[:host] if args[:host]
@con[:port] = args[:port] if args[:port]
@base_dn = args[:base_dn] if args[:base_dn]
@ldap = Net::LDAP.new(@con)
filter = args[:filter] if args[:filter]
end
def filter=(filter)
@filter = Net::LDAP::Filter::construct(filter)
end
def each
_load.each{|key,entry| puts "DEBUG: #{key}"; yield key,entry}
end
def [](id)
_load[id]
end
def []=(id, data)
end
def insert(data)
end
def delete(id)
end
private
def _load!
@data = Hash.new
@ldap.search(:base => @base_dn, :filter => @filter) do |entry|
attributes = Hash.new
entry.each{|attr,value| attributes.merge!({attr => value})}
@data.merge!({attributes[:dn][0] => attributes})
end
end
def _load
_load! if ! @data
@data
end
end