# Copyright (C) 2011 Laurentian University
# Dan Scott <dscott@laurentian.ca>
#
-#
+#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
"""
-Synchronize Evergreen user accounts with an LDAP directory via OpenSRF
+Synchronize Evergreen user accounts with an LDAP directory via OpenSRF
LDAP and OpenSRF authentication information is stored in a separate Python
file (credentials.py) and imported to avoid storing credentials in the VCS.
2. For each new LDAP record, check to see if the record exists in Evergreen
(matching on ident_value, usrname, email).
-
+
If not, create a new account with barcode.
3. Push the new barcode back into the LDAP directory.
server. One could a HEAD request to do some smarter caching,
perhaps.
"""
-
+
parser = oils.utils.idl.IDLParser()
idlfile = tempfile.TemporaryFile()
# Get the fm_IDL.xml file from the server
try:
- idl = urllib2.urlopen('%s://%s/%s' %
+ idl = urllib2.urlopen('%s://%s/%s' %
(credentials.OSRF_HTTP, ARGS.eg_host, credentials.IDL_URL)
)
idlfile.write(idl.read())
try:
seed = osrf_request(
- 'open-ils.auth',
+ 'open-ils.auth',
'open-ils.auth.authenticate.init', username).send()
except Exception, exc:
print exc
result = osrf_request(
'open-ils.auth',
- 'open-ils.auth.authenticate.complete',
- { 'workstation' : workstation,
+ 'open-ils.auth.authenticate.complete', {
+ 'workstation' : workstation,
'username' : username,
'password' : password,
- 'type' : 'staff'
+ 'type' : 'staff'
}).send()
evt = oils.event.Event.parse_event(result)
evt = oils.event.Event.parse_event(user)
if evt and not evt.success:
raise AuthException(evt.text_code)
-
+
if not user:
return None
search_depth = 1
include_inactive = True
- print("Trying to find user: %s %s %s" %
+ print("Trying to find user: %s %s %s" %
(user.ident_value, user.email, user.usrname)
)
).send()
if by_email and len(by_email):
- return by_email[0]
+ return by_email[0]
by_usrname = osrf_request(
'open-ils.actor', search_method,
# Generate a barcode for the user
try:
barcode = osrf_request(
- 'open-ils.actor', 'open-ils.actor.generate_patron_barcode',
+ 'open-ils.actor', 'open-ils.actor.generate_patron_barcode',
auth, usr.id(), '000070'
).send()
except Exception, exc:
print >> sys.stderr, "Create barcode failed for %s: %s" % (
AuthException(evt.text_code), user.usrname)
return None
-
+
user.barcode = barcode['evergreen.actor_update_barcode']
create_stat_cats(egau, user)
print("Created: %s with barcode %s" % (egau.usrname(), user.barcode))
-
+
return egau.usrname(), user.barcode
def update_ldap_barcode(con, user):
'lulModifyTimestamp'
]
- if (ARGS.query_date):
+ if ARGS.query_date:
ldap_filter = '(&%s(lulPrimaryAffiliation=*)(createTimestamp>=%s))' % (
'(objectclass=lulEduPerson)', ARGS.query_date
)
- elif (ARGS.query_cn):
+ elif ARGS.query_cn:
ldap_filter = '(&%s(cn=%s))' % (
'', ARGS.query_cn
)
- elif (ARGS.query_sn):
+ elif ARGS.query_sn:
ldap_filter = '(&%s(sn=%s))' % (
'(objectclass=lulEduPerson)', ARGS.query_sn
)
- elif (ARGS.query_id):
+ elif ARGS.query_id:
ldap_filter = '(&%s(lulColleagueId=%s))' % (
'(objectclass=lulEduPerson)', ARGS.query_id
)
if not ldap_filter:
- return
+ return
return find_ldap_users(con, ldap_filter, attributes, auth)
def parse_args():