diff 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
line wrap: on
line diff
--- a/src/memory/sqlite.py	Wed May 21 23:17:51 2014 +0200
+++ b/src/memory/sqlite.py	Fri May 23 09:59:15 2014 +0200
@@ -23,6 +23,7 @@
 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 @@
             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