[db-api/configuration] simplify db-api and configuration so that all the connection information is in the repository url, closes #2521848
eg no more specific option of pyro ns host, group, etc. This also fixes broken ZMQ
sources.
Changes:
* dropped pyro-ns-host, pyro-instance-id, pyro-ns-group from client side config, in
favor of repository-uri. No migration done, supposing there is **no web-only config**
in the wild. Also stop discovering the connection method through the repo_method class
attribute of the configuration, varying according to the configuration class. This is
a first step on the way to a simpler configuration handling. Notice those pyro options
are still available for repository only / all-in-one configurations as they are needed
to configure the pyro server.
* stop telling connection method using ConnectionProperties, this is so boring. Also,
drop _cnxtype from Connection and cnxtype from Session. The former is replaced by a
is_repo_in_memory property and the later is totaly useless.
* deprecate in_memory_cnx which becomes useless, use _repo_connect instead
import base64
from cubicweb.server.utils import crypt_password
dbdriver = config.sources()['system']['db-driver']
from logilab.database import get_db_helper
dbhelper = get_db_helper(driver)
insert = ('INSERT INTO cw_cwuser (cw_creation_date,'
' cw_eid,'
' cw_modification_date,'
' cw_login,'
' cw_firstname,'
' cw_surname,'
' cw_last_login_time,'
' cw_upassword,'
' cw_cwuri) '
"VALUES (%(mtime)s, %(eid)s, %(mtime)s, %(login)s, "
" %(firstname)s, %(surname)s, %(mtime)s, %(pwd)s, 'foo');")
update = "UPDATE entities SET source='system' WHERE eid=%(eid)s;"
rset = sql("SELECT eid,type,source,extid,mtime FROM entities WHERE source!='system'", ask_confirm=False)
for eid, type, source, extid, mtime in rset:
if type != 'CWUser':
print "don't know what to do with entity type", type
continue
if not source.lower().startswith('ldap'):
print "don't know what to do with source type", source
continue
extid = base64.decodestring(extid)
ldapinfos = [x.strip().split('=') for x in extid.split(',')]
login = ldapinfos[0][1]
firstname = login.capitalize()
surname = login.capitalize()
args = dict(eid=eid, type=type, source=source, login=login,
firstname=firstname, surname=surname, mtime=mtime,
pwd=dbhelper.binary_value(crypt_password('toto')))
print args
sql(insert, args)
sql(update, args)
commit()