From 20995d3b2eeaf3e22e6748629341a8efc32fb607 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Fri, 16 May 2008 14:12:01 -0700 Subject: [PATCH] Added support for database hostname and ssl mode in configuration file. --- NEWS | 3 +++ config/Common.py | 2 ++ controller/Database.py | 8 ++++++-- luminotes.py | 6 +++++- 4 files changed, 16 insertions(+), 3 deletions(-) mode change 100644 => 100755 luminotes.py diff --git a/NEWS b/NEWS index 68e12e4..20d5d90 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +1.3.29: May 16, 2008 + * Added support for database hostname and ssl mode in configuration file. + 1.3.28: May 14, 2008 * Updated the pricing page with more info about each feature. diff --git a/config/Common.py b/config/Common.py index a82d1c3..7a0556e 100644 --- a/config/Common.py +++ b/config/Common.py @@ -22,6 +22,8 @@ settings = { "luminotes.https_url": "", "luminotes.http_proxy_ip": "127.0.0.1", "luminotes.https_proxy_ip": "127.0.0.2", + "luminotes.db_host": "localhost", + "luminotes.db_ssl_mode": "allow", # "disallow", "allow", "prefer", or "require" "luminotes.support_email": "", "luminotes.payment_email": "", "luminotes.rate_plans": [ diff --git a/controller/Database.py b/controller/Database.py index 855e6a6..be958f1 100644 --- a/controller/Database.py +++ b/controller/Database.py @@ -21,7 +21,7 @@ class Database( object ): ID_BITS = 128 # number of bits within an id ID_DIGITS = "0123456789abcdefghijklmnopqrstuvwxyz" - def __init__( self, connection = None, cache = None ): + def __init__( self, connection = None, cache = None, host = None, ssl_mode = None ): """ Create a new database and return it. @@ -53,7 +53,11 @@ class Database( object ): self.__pool = PersistentConnectionPool( 1, # minimum connections 50, # maximum connections - "dbname=luminotes user=luminotes password=%s" % os.getenv( "PGPASSWORD", "dev" ), + "host=%s sslmode=%s dbname=luminotes user=luminotes password=%s" % ( + host or "localhost", + ssl_mode or "allow", + os.getenv( "PGPASSWORD", "dev" ) + ), ) self.__cache = cache diff --git a/luminotes.py b/luminotes.py old mode 100644 new mode 100755 index 2dd1402..97df63b --- a/luminotes.py +++ b/luminotes.py @@ -12,7 +12,6 @@ SOCKET_TIMEOUT_SECONDS = 60 def main( args ): socket.setdefaulttimeout( SOCKET_TIMEOUT_SECONDS ) - database = Database() cherrypy.config.update( Common.settings ) @@ -25,6 +24,11 @@ def main( args ): cherrypy.config.update( settings ) + database = Database( + host = cherrypy.config.configMap[ u"global" ].get( u"luminotes.db_host" ), + ssl_mode = cherrypy.config.configMap[ u"global" ].get( u"luminotes.db_ssl_mode" ), + ) + cherrypy.lowercase_api = True root = Root( database, cherrypy.config.configMap ) cherrypy.root = root