[Mpuls-commits] r5314 - base/trunk/mpulsweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Sep 9 19:57:10 CEST 2011


Author: bh
Date: 2011-09-09 19:57:09 +0200 (Fri, 09 Sep 2011)
New Revision: 5314

Modified:
   base/trunk/mpulsweb/lib/app_globals.py
Log:
Port meta-server settings in app_globals from WASKU to mpulsweb.

The code was taken almost unchanged from wasku-web revision
390:1334ddc05a11. The only change is that the settings are now
optional. This includes the SSL options making SSL support default to
false. This is a bit unfortunate, because the default value true was
meant to make it more likely that SSL was switched on for the
meta-server connection, by requiring a conscious decision to switch it
off. However, changing this is the easiest the way to add the options
without requiring all applications to be adapted.


Modified: base/trunk/mpulsweb/lib/app_globals.py
===================================================================
--- base/trunk/mpulsweb/lib/app_globals.py	2011-09-09 17:02:10 UTC (rev 5313)
+++ base/trunk/mpulsweb/lib/app_globals.py	2011-09-09 17:57:09 UTC (rev 5314)
@@ -40,6 +40,7 @@
 
 from mpulsweb.config.importer import import_overridable_module
 from mpulsweb.lib.config import MpulsAppConfig, MpulsDBMapping, MpulsDBList
+from mpulsweb.lib.metaclient import get_ssl_context
 from mpulsweb.model.annotations import AnnotationsProvider
 
 
@@ -55,6 +56,28 @@
 session = StackedObjectProxy()
 
 
+def ssl_option(key, default=None):
+    """Return the SSL option named by key.
+
+    The SSL option is taken from pylons config with a key formed by
+    prepending "mpuls.meta.ssl." to the key passed to this function. If
+    there's no value for that key, the value of the parameter default is
+    returned.
+    """
+    return config.get("mpuls.meta.ssl." + key, default)
+
+
+def ssl_file_option(key, default=None):
+    """Like ssl_option, but for values that are filenames.
+    The filenames are added to the paster reloader watch list, so that
+    when the application runs with 'paster serve --reload' paster
+    restarts automatically when the file changes.
+    """
+    filename = ssl_option(key, default=None)
+    watch_file(filename)
+    return filename
+
+
 class Globals(object):
 
     """Globals acts as a container for objects available throughout the
@@ -118,6 +141,19 @@
         watch_file(annotation_file)
         watch_file(tagging_file)
 
+        # meta-server settings
+        if ssl_option("enabled", "false") == "true":
+            self.ssl_context = get_ssl_context(ssl_file_option("cacerts"),
+                                               ssl_file_option("client_cert"),
+                                               ssl_file_option("client_key"))
+        else:
+            self.ssl_context = None
+
+        self.meta_converter = config.get("mpuls.meta.converter")
+        if self.meta_converter:
+            watch_file(self.meta_converter)
+
+
         # TODO: These setups should be while application intialisation, as they
         # are not related to any global vars or functions. Move to
         # config/environment.py



More information about the Mpuls-commits mailing list