comparison src/memory/sqlite.py @ 1045:65fffdcb97f1

memory: auto-update configuration file with libervia's passphrase when migrating the database
author souliane <souliane@mailoo.org>
date Fri, 23 May 2014 09:59:15 +0200
parents 15f43b54d697
children 5f7f913c05ac
comparison
equal deleted inserted replaced
1044:85c110c0be86 1045:65fffdcb97f1
21 from sat.core.constants import Const as C 21 from sat.core.constants import Const as C
22 from sat.core import exceptions 22 from sat.core import exceptions
23 from sat.core.log import getLogger 23 from sat.core.log import getLogger
24 log = getLogger(__name__) 24 log = getLogger(__name__)
25 from sat.memory.crypto import BlockCipher, PasswordHasher 25 from sat.memory.crypto import BlockCipher, PasswordHasher
26 from sat.tools.config import fixConfigOption
26 from twisted.enterprise import adbapi 27 from twisted.enterprise import adbapi
27 from twisted.internet import defer 28 from twisted.internet import defer
28 from collections import OrderedDict 29 from collections import OrderedDict
29 from time import time 30 from time import time
30 import re 31 import re
796 797
797 d_list = defer.DeferredList(list_) 798 d_list = defer.DeferredList(list_)
798 d_list.addCallback(lambda dummy: ret) 799 d_list.addCallback(lambda dummy: ret)
799 return d_list 800 return d_list
800 801
802 def updateLiberviaConf(values):
803 try:
804 profile_id = values[0][0]
805 except IndexError:
806 return # no profile called "libervia"
807
808 def cb(selected):
809 try:
810 password = selected[0][0]
811 except IndexError:
812 log.error("Libervia profile exists but no password is set! Update Libervia configuration will be skipped.")
813 return
814 fixConfigOption('libervia', 'passphrase', password, False)
815 d = self.dbpool.runQuery("SELECT value FROM param_ind WHERE category=? AND name=? AND profile_id=?", xmpp_pass_path + (profile_id,))
816 d.addCallback(cb)
817
818 d = self.dbpool.runQuery("SELECT id FROM profiles WHERE name='libervia'")
819 d.addCallback(updateLiberviaConf)
820
801 d = self.dbpool.runQuery("SELECT profile_id,value FROM param_ind WHERE category=? AND name=?", xmpp_pass_path) 821 d = self.dbpool.runQuery("SELECT profile_id,value FROM param_ind WHERE category=? AND name=?", xmpp_pass_path)
802 d.addCallback(encrypt_values) 822 d.addCallback(encrypt_values)
803 return d 823 return d