-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLdapEntry.py
More file actions
51 lines (42 loc) · 1.51 KB
/
LdapEntry.py
File metadata and controls
51 lines (42 loc) · 1.51 KB
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
Entries from an LDAP user database are represented in Python as a
dictionary of key-value pairs, where each key is a case-insensitive
string object and each value is a list of bytes objects. For example:
ldapdict = {
'objectclass': [b'inetOrgPerson', b'person'],
'cn': [b'George Orwell'],
'givenName': [b'George'],
'sn': [b'Orwell'],
'uidNumber': [b'1984'],
'gidNumber': [b'1984'],
'mail': [
b'george.orwell@example.com',
b'big.brother@example.com',
],
}
Create an LdapEntry class with attributes for each of the keys listed
above that can be used as follows:
e = LdapEntry(ldapdict)
assert(e.cn == 'George Orwell')
assert(e.uidNumber == 1984)
assert('big.brother@example.com' in e.mail)
assert(len(e.mail) == 2)
class LdapEntry(entry):
"""Single entry class for LDAP"""
def __init__(self, entry){
"""Single entry class for LDAP
Parameters:
entry: a dict containing LDAP data, with keys:
Returns:
instance
"""
self.objectClass = entry['objectclass']
if not isinstance(self.objectClass, (list, tuple))
self.objectClass = [self.objectClass]
self.cn = entry['cn']
self.givenName = entry['givenName']
self.sn = entry['sn']
self.uidNumber = entry['uidNumber']
self.gidNumber = entry['gidNumber']
self.mail = entry['mail']
if not isinstance(self.mail, (list, tuple))
self.mail = [self.mail]