Add the possibility to filter the returned entry

This commit is contained in:
Josué Tille 2019-05-26 00:45:44 +02:00
parent eeadb2ce17
commit a951b6f9a2
No known key found for this signature in database
GPG key ID: D5E068C6DFA8681D

View file

@ -77,7 +77,7 @@ def read_yaml(file_path):
return loaded_yaml
def read_ldif(file_path):
def read_ldif(file_path, filtred_entries=[]):
"""
Safely read a LDIF file and create struct in the same style than
what return the auth objet with the seach method
@ -86,13 +86,21 @@ def read_ldif(file_path):
Keyword argument:
file_path -- Path to the ldif file
filtred_entries -- The entries to don't include in the result
"""
from ldif import LDIFRecordList
class LDIFPar(LDIFRecordList):
def handle(self,dn,entry):
for e in filtred_entries:
if e in entry:
entry.pop(e)
self.all_records.append((dn,entry))
# Open file and read content
try:
with open(file_path, "r") as f:
parser = LDIFRecordList(f)
parser = LDIFPar(f)
parser.parse()
except IOError as e:
raise MoulinetteError('cannot_open_file', file=file_path, error=str(e))