memory: auto-update configuration file with libervia's passphrase when migrating the database

This commit is contained in:
souliane 2014-05-23 09:59:15 +02:00
commit c68b147398

View file

@ -23,6 +23,7 @@ from sat.core import exceptions
from sat.core.log import getLogger
log = getLogger(__name__)
from sat.memory.crypto import BlockCipher, PasswordHasher
from sat.tools.config import fixConfigOption
from twisted.enterprise import adbapi
from twisted.internet import defer
from collections import OrderedDict
@ -798,6 +799,25 @@ class Updater(object):
d_list.addCallback(lambda dummy: ret)
return d_list
def updateLiberviaConf(values):
try:
profile_id = values[0][0]
except IndexError:
return # no profile called "libervia"
def cb(selected):
try:
password = selected[0][0]
except IndexError:
log.error("Libervia profile exists but no password is set! Update Libervia configuration will be skipped.")
return
fixConfigOption('libervia', 'passphrase', password, False)
d = self.dbpool.runQuery("SELECT value FROM param_ind WHERE category=? AND name=? AND profile_id=?", xmpp_pass_path + (profile_id,))
d.addCallback(cb)
d = self.dbpool.runQuery("SELECT id FROM profiles WHERE name='libervia'")
d.addCallback(updateLiberviaConf)
d = self.dbpool.runQuery("SELECT profile_id,value FROM param_ind WHERE category=? AND name=?", xmpp_pass_path)
d.addCallback(encrypt_values)
return d