misc/scripts/ldap_change_base_dn.py
changeset 11057 0b59724cb3f2
parent 11052 058bb3dc685f
child 11058 23eb30449fe5
equal deleted inserted replaced
11052:058bb3dc685f 11057:0b59724cb3f2
     1 from __future__ import print_function
       
     2 
       
     3 from base64 import b64decode, b64encode
       
     4 try:
       
     5     uri, newdn = __args__
       
     6 except ValueError:
       
     7     print('USAGE: cubicweb-ctl shell <instance> ldap_change_base_dn.py -- <ldap source uri> <new dn>')
       
     8     print()
       
     9     print('you should not have updated your sources file yet')
       
    10 
       
    11 olddn = repo.sources_by_uri[uri].config['user-base-dn']
       
    12 
       
    13 assert olddn != newdn
       
    14 
       
    15 raw_input("Ensure you've stopped the instance, type enter when done.")
       
    16 
       
    17 for eid, extid in sql("SELECT eid, extid FROM entities WHERE source='%s'" % uri):
       
    18     olduserdn = b64decode(extid)
       
    19     newuserdn = olduserdn.replace(olddn, newdn)
       
    20     if newuserdn != olduserdn:
       
    21         print(olduserdn, '->', newuserdn)
       
    22         sql("UPDATE entities SET extid='%s' WHERE eid=%s" % (b64encode(newuserdn), eid))
       
    23 
       
    24 commit()
       
    25 
       
    26 print('you can now update the sources file to the new dn and restart the instance')