Skip to content
Snippets Groups Projects
Commit 0695d073 authored by Jan David Mol's avatar Jan David Mol
Browse files

Task #8899: Propagate username, password, port to pg.connect. Also, return...

Task #8899: Propagate username, password, port to pg.connect. Also, return dbcreds["port"] as an int
parent f7551b8b
No related branches found
No related tags found
No related merge requests found
......@@ -48,9 +48,9 @@ class DBCredentials:
# Flavour of database (postgres, mysql, oracle, sqlite)
"type": "postgres",
# Connection information
# Connection information (port 0 = use default)
"host": "localhost",
"port": "",
"port": 0,
# Authentication
"user": "{USER}".format(**environ),
......@@ -81,7 +81,12 @@ class DBCredentials:
Return credentials for a given database.
"""
try:
return dict(self.config.items(self._section(database)))
d = dict(self.config.items(self._section(database)))
# fix types
d["port"] = int(d["port"] or 0)
return d
except NoSectionError:
return self.config.defaults()
......
......@@ -224,7 +224,7 @@ class PostgressMessageHandlerInterface(MessageHandlerInterface):
self.connected = (self.connection and self.connection.status == 1)
while not self.connected:
try:
self.connection = pg.connect(user=self.dbcreds["user"], host=self.dbcreds["host"], dbname=self.dbcreds["database"])
self.connection = pg.connect(user=self.dbcreds["user"], passwd=self.dbcreds["password"], host=self.dbcreds["host"], port=self.dbcreds["port"] or -1, dbname=self.dbcreds["database"])
self.connected = True
logger.info("Connected to database %s on host %s" % (self.dbcreds["database"], self.dbcreds["host"]))
except (TypeError, SyntaxError, pg.InternalError), e:
......
......@@ -106,7 +106,7 @@ if __name__ == "__main__":
while alive and not connected:
# Connect to the database
try:
otdb_connection = pg.connect(user="postgres", host=dbcreds["host"], dbname=dbcreds["database"])
otdb_connection = pg.connect(user=dbcreds["user"], passwd=dbcreds["password"], host=dbcreds["host"], port=dbcreds["port"] or -1, dbname=dbcreds["database"])
connected = True
# Get list of allowed tree states
allowed_states = {}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment