21
21
UCB_LDAP = 'ldap.berkeley.edu'
22
22
UCB_LDAP_URL = 'ldaps://' + UCB_LDAP
23
23
UCB_LDAP_PEOPLE = 'ou=People,dc=Berkeley,dc=EDU'
24
- UCB_LDAP_DN = 'uid=ocf,ou=applications,dc=berkeley,dc=edu'
25
- UCB_LDAP_PASSWORD_PATH = '/etc/ucbldap.passwd'
26
24
27
25
28
26
@contextmanager
29
- def ldap_connection (host , dn = None , password = None ):
30
- """Context manager that provides an ldap3 Connection. Also supports optional credentials for a privileged bind.
27
+ def ldap_connection (host ):
28
+ """Context manager that provides an ldap3 Connection.
31
29
32
30
Example usage:
33
31
@@ -39,47 +37,31 @@ def ldap_connection(host, dn=None, password=None):
39
37
40
38
:param host: server hostname
41
39
"""
42
-
43
40
server = ldap3 .Server (host , use_ssl = True )
44
- with ldap3 .Connection (server , dn , password ) as connection :
41
+ with ldap3 .Connection (server ) as connection :
45
42
yield connection
46
43
47
44
48
- def ldap_ocf (dn = None , password = None ):
49
- """Context manager that provides an ldap3 Connection to OCF's LDAP server. Accepts optional DN and password.
45
+ def ldap_ocf ():
46
+ """Context manager that provides an ldap3 Connection to OCF's LDAP server.
50
47
51
48
Example usage:
52
49
53
50
with ldap_ocf() as c:
54
51
c.search(OCF_LDAP_PEOPLE, '(uid=ckuehl)', attributes=['uidNumber'])
55
52
"""
56
- return ldap_connection (OCF_LDAP , dn , password )
53
+ return ldap_connection (OCF_LDAP )
57
54
58
55
59
- def ldap_ucb (dn = None , password = None ):
60
- """Context manager that provides an ldap3 Connection to the campus LDAP. Accepts optional DN and password.
56
+ def ldap_ucb ():
57
+ """Context manager that provides an ldap3 Connection to the campus LDAP.
61
58
62
59
Example usage:
63
60
64
61
with ldap_ucb() as c:
65
62
c.search(UCB_LDAP_PEOPLE, '(uid=ckuehl)', attributes=['uidNumber'])
66
63
"""
67
- return ldap_connection (UCB_LDAP , dn , password )
68
-
69
-
70
- def ldap_ucb_privileged (dn = None , password = None ):
71
- """Context manager that provides a privileged ldap3 Connection to the campus LDAP.
72
-
73
- Note that this method will ignore all dn and password arguments,
74
- which are being kept for compatibility with user_attrs().
75
-
76
- Example usage:
77
-
78
- with ldap_ucb_privileged() as c:
79
- c.search(UCB_LDAP_PEOPLE, '(uid=ckuehl)', attributes=['uidNumber'])
80
- """
81
- password = _read_ucb_password ()
82
- return ldap_ucb (UCB_LDAP_DN , password )
64
+ return ldap_connection (UCB_LDAP )
83
65
84
66
85
67
def _format_attr (key , values ):
@@ -244,14 +226,3 @@ def format_timestamp(timestamp):
244
226
if timestamp .tzinfo is None or timestamp .tzinfo .utcoffset (timestamp ) is None :
245
227
raise ValueError ('Timestamp has no timezone info' )
246
228
return timestamp .strftime ('%Y%m%d%H%M%S%z' )
247
-
248
-
249
- def _read_ucb_password ():
250
- """Returns a string of the current campus LDAP privileged bind password
251
- found in UCB_LDAP_PASSWORD_PATH
252
-
253
- :return: A string of the campus LDAP bind password
254
- """
255
-
256
- with open (UCB_LDAP_PASSWORD_PATH , 'r' ) as passwordFile :
257
- return passwordFile .read ()
0 commit comments