[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[dak/master] update-db: support switching to a different role after connecting to the db



---
 dak/update_db.py        | 4 ++++
 integration-tests/setup | 1 +
 2 files changed, 5 insertions(+)

diff --git a/dak/update_db.py b/dak/update_db.py
index 332eab6..63d9a64 100755
--- a/dak/update_db.py
+++ b/dak/update_db.py
@@ -137,6 +137,10 @@ Updates dak's database schema to the lastest version. You should disable crontab
 
             self.db = psycopg2.connect(connect_str)
 
+            db_role = cnf.get("DB::Role")
+            if db_role is not None:
+                self.db.cursor().execute('SET ROLE "{}"'.format(db_role))
+
         except Exception as e:
             print "FATAL: Failed connect to database (%s)" % str(e)
             sys.exit(1)
diff --git a/integration-tests/setup b/integration-tests/setup
index f3f339c..08e8d9d 100755
--- a/integration-tests/setup
+++ b/integration-tests/setup
@@ -21,6 +21,7 @@ dak-setup() {
 
   export DAK_CONFIG="${DAKBASE}/etc/dak.conf"
   (cd ${setupdir}; ./init_minimal_conf) > ${DAK_CONFIG}
+  echo 'DB::Role "dak";' >> ${DAK_CONFIG}
 
   export PATH="${DAKBASE}/bin:${PATH}"
   ln -s ${DAK_ROOT}/dak/dak.py ${DAKBASE}/bin/dak
-- 
2.1.4


Reply to: