mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Add the possibility to filter the returned entry
This commit is contained in:
parent
eeadb2ce17
commit
a951b6f9a2
1 changed files with 11 additions and 3 deletions
|
@ -77,7 +77,7 @@ def read_yaml(file_path):
|
||||||
return loaded_yaml
|
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
|
Safely read a LDIF file and create struct in the same style than
|
||||||
what return the auth objet with the seach method
|
what return the auth objet with the seach method
|
||||||
|
@ -85,14 +85,22 @@ def read_ldif(file_path):
|
||||||
with the "dn" and the LDAP entry.
|
with the "dn" and the LDAP entry.
|
||||||
|
|
||||||
Keyword argument:
|
Keyword argument:
|
||||||
file_path -- Path to the ldif file
|
file_path -- Path to the ldif file
|
||||||
|
filtred_entries -- The entries to don't include in the result
|
||||||
"""
|
"""
|
||||||
from ldif import LDIFRecordList
|
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
|
# Open file and read content
|
||||||
try:
|
try:
|
||||||
with open(file_path, "r") as f:
|
with open(file_path, "r") as f:
|
||||||
parser = LDIFRecordList(f)
|
parser = LDIFPar(f)
|
||||||
parser.parse()
|
parser.parse()
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
raise MoulinetteError('cannot_open_file', file=file_path, error=str(e))
|
raise MoulinetteError('cannot_open_file', file=file_path, error=str(e))
|
||||||
|
|
Loading…
Add table
Reference in a new issue