-
Notifications
You must be signed in to change notification settings - Fork 253
Open
Description
I see in the documentation how to read from LDIF files with Net::LDAP::Dataset.read_ldif(File.open(file_path))
and how to save entries to LDIF files with File.write file_path, entry.to_ldif
.
However, I do not see a clear way of processing adds, deletes, and modifications from LDIF files. Reading from an LDIF file shows :changetype=>["add"]
set as if it were an attribute.
Right now I have thrown together something like this.
ldif_mods = Net::LDAP::Dataset.read_ldif(File.open(file_path))
Net::LDAP.open(CONFIG) do |ldap|
ldif_mods.each do |dn, attrs|
case attrs[:changetype].first
when 'add'
ldap.add dn: dn, attributes: attrs.reject{ |k,_v| k == :changetype }
when 'delete'
ldap.delete dn
when 'modify'
# More logic to process attribute modifications
end
result = ldap.get_operation_result
puts result unless result.code.zero?
end
end
I feel like there should be a better way, similar to how LDIFReader
provides #processChange
on LDIFChangeRecord
.
# JRuby
java_import 'com.unboundid.ldif.LDIFReader'
ldif_reader = LDIFReader.new(file_path)
loop do
change_record = ldif_reader.readChangeRecord
change_record.nil? ? break : change_record.processChange(CONN)
end
ldif_reader.close
dolzenko
Metadata
Metadata
Assignees
Labels
No labels